0
私は文書のためのtf idf行列を持っています。私はTFIDFマトリックスで二重にしたいという重みを持つ用語をいくつか持っています。私は行列weightTermsを持っていると私は、コードTF IDFマトリックス用語の重みを増やす
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())
for term in count_vectorizer.get_feature_names():
# [k for k in count_vectorizer.get_feature_names() if '#' in k]:
# if '#' in term:
print term.encode('utf-8')# print np.matrix(tf_idf_matrix.todense())
# np.savetxt("foo.csv", (np.matrix(tf_idf_matrix.todense())), delimiter=",")
# np.savetxt("foo.csv", tf_idf_matrix.toarray(),fmt="%.4e")