【发布时间】:2018-03-23 11:30:39
【问题描述】:
我有一个大小为 208 的列表(208 个句子数组),看起来像:
all_words = [["this is a sentence ... "] , [" another one hello bob this is alice ... "] , ["..."] ...]
我想得到具有最高 tf-idf 值的单词。 我创建了一个 tf-idf 矩阵:
from sklearn.feature_extraction.text import TfidfVectorizer
tokenize = lambda doc: doc.split(" ")
sklearn_tfidf = TfidfVectorizer(norm='l2', tokenizer=tokenize, ngram_range=(1,2))
tfidf_matrix = sklearn_tfidf.fit_transform(all_words)
sentences = sklearn_tfidf.get_feature_names()
dense_tfidf = tfidf_matrix.todense()
现在我不知道如何获取具有最高 tf-idf 值的单词。
dense_tfidf 的每一列代表一个单词/2 个单词。 (矩阵为208x5481)
当我对每一列求和时,它并没有真正帮助 - 得到一个简单的热门词的相同结果(我猜是因为它与简单的字数相同)。
如何获取 tf-idf 值最高的单词?或者我怎样才能明智地将它标准化?
【问题讨论】:
标签: python feature-extraction tf-idf sklearn-pandas