Skip to main content
 首页 » 编程设计

python CountVectorizer() vocabulary_get 方法返回 None

2025年05月04日31telwanggs

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

谢谢,

请您参考如下方法:

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

也许你应该试试'algorithm'。