我想用 scikit 进行矢量化学习一个有列表的列表。我转到有训练文本的路径,我阅读了它们,然后我得到如下内容:
corpus = [["this is spam, 'SPAM'"],["this is ham, 'HAM'"],["this is nothing, 'NOTHING'"]]
from sklearn.feature_extraction.text import CountVectorizer
vect = CountVectorizer(analyzer='word')
vect_representation= vect.fit_transform(corpus)
print vect_representation.toarray()
我得到以下信息:
return lambda x: strip_accents(x.lower())
AttributeError: 'list' object has no attribute 'lower'
另外,问题是每个文档末尾的标签,我应该如何处理它们才能进行正确的分类?
对于未来的每个人来说,这解决了我的问题:
corpus = [["this is spam, 'SPAM'"],["this is ham, 'HAM'"],["this is nothing, 'NOTHING'"]]
from sklearn.feature_extraction.text import CountVectorizer
bag_of_words = CountVectorizer(tokenizer=lambda doc: doc, lowercase=False).fit_transform(splited_labels_from_corpus)
这是当我使用时的输出.toarray()
功能:
[[0 0 1]
[1 0 0]
[0 1 0]]
多谢你们
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)