首先,我将它放在短信语料库中:
from sklearn.feature_extraction.text import CountVectorizer
clf = CountVectorizer()
X_desc = clf.fit_transform(X).toarray()
似乎工作正常:
X.shape = (5574,)
X_desc.shape = (5574, 8713)
但是后来我对文本行应用了变换方法,我们知道,结果应该是 (, 8713) 形状,但是我们看到的是:
str2 = 'Have you visited the last lecture on physics?'
print len(str2), clf.transform(str2).toarray().shape
52 (52, 8713)
这里发生了什么?还有一件事——所有的数字都是零