这就是我调用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
这个错误在这里意味着什么?
答案 0 :(得分:6)
在变换任意文本之前,您需要首先拟合模型(例如,根据数据构建词汇表):
vectorizer.fit(data_to_vectorize)
X = vectorizer.transform(data_to_vectorize)
或
X = vectorizer.fit_transform(data_to_vectorize)