我正在阅读一本关于Scikit learn的教程,其中一节有以下代码块:
from sklearn.feature_extraction.text import CountVectorizer
corpus = ['The dog ate a sandwich, the wizard transfigured a sandwich, and I ate a sandwich']
vectorizer = CountVectorizer(stop_words='english')
print vectorizer.fit_transform(corpus).todense()
当我运行它时,我得到:
[[2 1 3 1 1]]
当我应该同时获得这两项时:
[[2 1 3 1 1]]
{u'sandwich': 2, u'wizard': 4, u'dog': 1, u'transfigured': 3, u'ate': 0}
如何更改代码以获取实际单词&;被向量化的每个单词的数量,而不仅仅是向量本身
安装模型后,您将访问
.vocabulary_
属性:相关问题 更多 >
编程相关推荐