【问题标题】:python CountVectorizer() vocabulary_ get method returns Nonepython CountVectorizer() words_get 方法返回 None
【发布时间】:2016-05-18 19:21:28
【问题描述】:

根据文档,我有这段代码 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 个文本文档

谢谢,

【问题讨论】:

    标签: python scikit-learn nltk


    【解决方案1】:

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

    也许你应该试试'algorithm'

    【讨论】:

    • 谢谢..现在我很尴尬....但即使在改变了这个故事之后,故事仍然存在 -:( print (count_vect.vocabulary_.get(u'algorithm'))
    • 尝试打印词汇表本身并查看其中包含哪些单词。尝试在词汇表中找到一些单词。 @NareshMG
    猜你喜欢
    • 2021-02-27
    • 2022-12-12
    • 2021-10-24
    • 1970-01-01
    • 2018-08-14
    • 1970-01-01
    • 1970-01-01
    • 2017-07-26
    • 2013-04-07
    相关资源
    最近更新 更多