1
我通過對Scikit學習指南書的工作,以及部分之一具有的代碼塊:如何顯示被量化的每個單詞的實際數量
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}
如何更改我的代碼以獲取每個單詞的實際字數&,而不僅僅是矢量本身?
酷,這工作,謝謝。 – Rich