【问题标题】:How do I double up the weights of CountVectoriser from SCIKIT for TFIDF matrix如何将 SCIKIT 中 CountVectoriser 的权重加倍以获得 TFIDF 矩阵
【发布时间】:2017-07-25 23:59:48
【问题描述】:

我有从我拥有的文本文件生成的 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


    【解决方案1】:

    您可以将 TFIDF 或计数加倍,这是等效的。

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

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

    【讨论】:

      猜你喜欢
      • 2020-05-11
      • 2017-05-11
      • 2015-06-21
      • 1970-01-01
      • 1970-01-01
      • 2011-07-25
      • 2017-02-27
      • 2014-01-28
      • 1970-01-01
      相关资源
      最近更新 更多