如果您有一个字符串向量或其他对象的向量,并且想要为其提供分类标签,则可以使用
Factor该类(在
pandas名称空间中可用):
In [1]: s = Series(['single', 'touching', 'nuclei', 'dusts', 'touching', 'single', 'nuclei'])In [2]: sOut[2]: 0 single1 touching2 nuclei3 dusts4 touching5 single6 nucleiName: None, Length: 7In [4]: Factor(s)Out[4]: Factor:array([single, touching, nuclei, dusts, touching, single, nuclei], dtype=object)Levels (4): [dusts nuclei single touching]
该因素有属性
labels和
levels:
In [7]: f = Factor(s)In [8]: f.labelsOut[8]: array([2, 3, 1, 0, 3, 2, 1], dtype=int32)In [9]: f.levelsOut[9]: Index([dusts, nuclei, single, touching], dtype=object)
这是针对一维矢量的,因此不确定是否可以立即将其应用于您的问题,但请看一下。
顺便说一句,我建议您在statsmodels和/或scikit-learn邮件列表上问这些问题,因为我们大多数人都不是SO用户。



