【发布时间】:2016-10-27 05:35:54
【问题描述】:
我在以 sklearn 可以接受的形式呈现我的数据时遇到问题
我的原始数据是几百个字符串,它们被分为 5 个类别之一,我有一个我想分类的字符串列表,以及它们各自类别的平行列表。我正在使用GaussianNB()
示例数据:
For such a large, successful business, I really feel like they need to be
either choosier in their employee selection or teach their employees to
better serve their customers.|||Class:4
代表一个给定的“特征”和一个分类
在分类器中使用之前,字符串本身必须转换为向量,我尝试使用DictVector 来执行此任务
dictionaryTraining = convertListToSentence(data)
vec = DictVectorizer()
print(dictionaryTraining)
vec.fit_transform(dictionaryTraining)
但是为了做到这一点,我必须将数据的实际分类附加到字典中,否则我会收到错误 'str' object has no attribute 'items' 我理解这是因为 .fit_transform 需要特征和索引,但我不完全了解索引的目的
fit_transform(X[, y]) Learn a list of feature name -> indices mappings and transform X.
我的问题是,我如何获取字符串列表和表示其分类的数字列表,并将它们提供给gaussianNB() 分类器,以便我将来可以使用类似的字符串呈现它,它会估计字符串类?
【问题讨论】:
-
你能分享
dictionaryTraining变量中数据的格式吗? -
除非我将格式设置为字符串 -> 分类,否则该格式不起作用,但显然这不是分类器所需要的
标签: python string scipy scikit-learn gaussian