2017-03-06 31 views
3

我有tf-idf矩阵是从我拥有的文本文件生成的。我想更重视一些词汇术语。 我已经写下了下面的代码。我怎样才能加倍特定词汇术语的权重。我需要通过2加倍计或者只是多了TFIDF的权重,我想增加从d的一些术语的重要性我如何从TFTPF矩阵加倍从SCIKIT CountVectoriser的权重

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()) 

回答

0

您可以双击任一TFIDF或计数,相当于。

在你的情况,我会做类似

position = count_vectorizer.vocabulary_['the_important_word'] 
tf_idf_matrix[:, position] *= 2.0