我有从我拥有的文本文件生成的 tf-idf 矩阵。我想更加重视一些词汇术语。 我写了下面的代码。我怎样才能将特定词汇术语的权重加倍。我需要将计数加倍还是仅将 TFIDF 的权重乘以 2。我想增加 d 中某些术语的重要性
from sklearn.feature_extraction.text import CountVectorizer
count_vectorizer = CountVectorizer(min_df=1,stop_words="english")
term_freq_matrix = count_vectorizer.fit_transform(vectoriser.mydoclist)
# print "Vocabulary:", count_vectorizer.vocabulary_
from sklearn.feature_extraction.text import TfidfTransformer
tfidf = TfidfTransformer(norm="l2")
tfidf.fit(term_freq_matrix)
tf_idf_matrix = tfidf.transform(term_freq_matrix)
print len(count_vectorizer.get_feature_names())
最佳答案
您可以将 TFIDF 或计数加倍,它们是等价的。
在你的情况下,我会做类似的事情
position = count_vectorizer.vocabulary_['the_important_word']
tf_idf_matrix[:, position] *= 2.0
关于python - 如何将 SCIKIT 中 CountVectoriser 的权重加倍以用于 TFIDF 矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42620153/