【发布时间】:2015-10-16 11:02:41
【问题描述】:
from sklearn.feature_extraction.text import CountVectorizer
vectorizer = CountVectorizer()
vectorizer = vectorizer.fit(word_data)
freq_term_mat = vectorizer.transform(word_data)
from sklearn.feature_extraction.text import TfidfTransformer
tfidf = TfidfTransformer(norm="l2")
tfidf = tfidf.fit(freq_term_mat)
Ttf_idf_matrix = tfidf.transform(freq_term_mat)
voc_words = Ttf_idf_matrix.getfeature_names()
print "The num of words = ",len(voc_words)
当我运行包含这段代码的程序时,出现以下错误:
Traceback(最近一次调用最后一次): 文件“vectorize_text.py”,第 87 行,在
voc_words = Ttf_idf_matrix.getfeature_names()
getattr
中的文件“/home/farheen/anaconda/lib/python2.7/site->packages/scipy/sparse/base.py”,第 499 行 raise AttributeError(attr + " not found")
AttributeError: get_feature_names not found
请给我一个解决方案。
【问题讨论】:
标签: python scikit-learn tf-idf