2017-11-21 9 views
0

私はgensimを使用してLDAモデルを訓練しました。私はLdaがデータを2つのより低いレベルの行列(ref:https://www.analyticsvidhya.com/blog/2016/08/beginners-guide-to-topic-modeling-in-python/)に減らしているという印象を受けていますが、用語トピックマトリックスにアクセスする方法を理解できないようです。 gensimのドキュメンテーションにある唯一の参考資料は、.get_topics()属性のためのものですが、それが提供するフォーマットは私には意味がありません。アクセス用語トピックGensim LDAによって生成される行列

そうと同じように、ドキュメント・トピックの行列を取得するための変換を適用するのは簡単です:

doc_topic_matrix = lda_model[doc_term_matrix] 

ので、私は、トピック用語行列を生成するために、同様の機能方法があることを期待しています。理想的には

、出力は次のようになります。これが可能であるか否かの

  word1 word2 word3 word4 word5 
topic_a .12 .38 .07 .24 .19 
topic_b .41 .11 .04 .14 .30 

任意の考え?

答えて

0

それは簡単です、あなたはこのようにそれを得ることができます:

#get raw topic > word estimates 
topics_terms = model.state.get_lambda() 

#convert estimates to probability (sum equals to 1 per topic) 
topics_terms_proba = np.apply_along_axis(lambda x: x/x.sum(),1,topics_terms) 

# find the right word based on column index 
words = [model.id2word[i] for i in range(topics_terms_proba.shape[1])] 

#put everything together 
pd.DataFrame(topics_terms_proba,columns=words) 
関連する問題