如何将SCIKIT中CountVectoriser的权重加倍为TFIDF矩阵

问题描述 投票:3回答:1

我有从我拥有的文本文件生成的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())
python scikit-learn tf-idf weight
1个回答
0
投票

你可以加倍TFIDF或计数,它是等价的。

在你的情况下,我会做类似的事情

position = count_vectorizer.vocabulary_['the_important_word']
tf_idf_matrix[:, position] *= 2.0
© www.soinside.com 2019 - 2024. All rights reserved.