python CountVectorizer()vocabulary_ get方法返回None

时间:2016-02-08 23:34:05

标签: python scikit-learn nltk

我根据文档提供了这段代码 http://scikit-learn.org/stable/tutorial/text_analytics/working_with_text_data.html

from sklearn.datasets import load_files
from sklearn.feature_extraction.text import CountVectorizer

count_vect = CountVectorizer()

my_bunch = load_files("c:\\temp\\billing_test\\")

my_data = my_bunch['data']
print (my_bunch.keys())
print('target_names',my_bunch['target_names'])
print('length of data' , len(my_bunch['data']))


X_train_counts = count_vect.fit_transform(my_data)
print(X_train_counts.shape)

print ( count_vect.vocabulary_.get(u'algorithm'))

输出如下

dict_keys(['target', 'filenames', 'target_names', 'data', 'DESCR'])
target_names ['false', 'true']
length of data 920
(920, 8773)
None

不知道为什么“无”在(920,8773)之后的底部

我在每个文件夹“true”和“false”

中有大约460个文本文档

感谢,

1 个答案:

答案 0 :(得分:5)

因为单词'algoritham'从未出现在您的文档中。

也许您应该尝试'algorithm'