2017-03-02 4 views
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") 

答えて

0

を以下しているあなたは、必ずしもそれを行うことはできません、あなたが/それを行うにはハック方法を見つけても、お勧めしませんと言います。 1つのハックは複数のモデルをアンサンブルし、モデルごとに1つの機能で重み付けされます。これはテストされたアプローチではありませんので、慎重に進めてください。

あなたの精度+精度+リコールにどのような影響があるかを確認するために、再帰的特徴消去(RFE)を行います。また、ランダムなフォレストのベンチマークを使用して機能をランク付けして、どの機能がモデルに分散を与えているかを確認できます。

関連する問題