我现在使用下面的代码。我已经存储了所有文档的tfidf矩阵,现在我需要一个特定文档的前n个单词?我不知道怎么弄到它?
这是我一直使用到现在的代码。我现在需要从每个tfidf最高的文档中找到单词
import glob
import pandas as pd
import math
filenames=[]
corpus = []
df=pd.DataFrame(columns=['article','similar','score'])
for file in glob.glob("*.txt"):
with open(file, "r") as paper:
corpus.append((file, paper.read()))
filenames.append(file)
from sklearn.feature_extraction.text import TfidfVectorizer
tf = TfidfVectorizer(analyzer='word', ngram_range=(1,1), min_df = 0, stop_words = 'english')
tfidf_matrix = tf.fit_transform([content for file, content in corpus])https://stackoverflow.com/questions/44450510
复制相似问题