我正在使用sklearn处理大量文本数据。首先,我需要将文本内容(单词计数)转换为向量,并执行TfidfTransformer。以下是我的代码,似乎无法将CountVectorizer的输出传递给TfidfTransformer的输入。
TEXT = [data[i].values()[3] for i in range(len(data))]
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
vectorizer = CountVectorizer(min_df=0.01,max_df = 2.5, lowercase = False, stop_words = 'english')
X = vectorizer(TEXT)
transformer = TfidfTransformer(X)
X = transformer.fit_transform()
当我运行这段代码时,我遇到了以下错误:
Traceback (most recent call last):
File "nlpQ2.py", line 27, in <module>
X = vectorizer(TEXT)
TypeError: 'CountVectorizer' object is not callable
我原以为已将文本向量化,但现在它变成了一个矩阵——我是否错过了某个转换步骤?谢谢!