这就是我调用TFIDFVectorizer的方式:
vectorizer = TfidfVectorizer(
vocabulary=selected_vocabulary,
stop_words='english',
use_idf=True,
norm=norm,
tokenizer=self.tokenize,
lowercase=True,
smooth_idf=True)
当我打电话时收到此错误
vectorizer.transform(data_to_vectorize)
错误:
File "/root/anaconda/lib/python2.7/site-packages/sklearn/feature_extraction/text.py", line 1305, in transform
return self._tfidf.transform(X, copy=False)
File "/root/anaconda/lib/python2.7/site-packages/sklearn/feature_extraction/text.py", line 1024, in transform
raise ValueError("idf vector not fitted")
ValueError: idf vector not fitted
这个错误在这里意味着什么?
最佳答案
您需要先拟合模型(例如,根据数据构建词汇表),然后才能转换任意文本:
vectorizer.fit(data_to_vectorize)
X = vectorizer.transform(data_to_vectorize)
或者
X = vectorizer.fit_transform(data_to_vectorize)
关于python - 这个错误是什么意思 "idf vector not fitted",我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28239915/