2017-07-17 45 views
1

我想在一組文檔上應用LDA。假設計算文檔屬於某個主題的概率。我做了以下內容:如何使用scikit學習獲取特定文檔的主題概率?

tfidf_vectorizer = TfidfVectorizer(min_df=12, analyzer="word") 
tfidf = tfidf_vectorizer.fit_transform(data_samples) 
lda = LatentDirichletAllocation(n_topics=5, max_iter=5, 
           learning_method='online', 
           learning_offset=50., 
           random_state=0) 
lda.fit(tfidf) 

現在我希望得到我的data_sample文檔的概率屬於比如給定主題,因爲我用5個話題:[0.2, 0.1 ,0.1, 0.1, 0.5],關於LDA的文檔prety弱,你知道這個信息是否容易訪問?

回答

2

我最近有同樣的問題。您可以將模型應用於每個樣本:lda.transform(tfidf)

請注意,您需要爲此使用向量tfidf。

我認爲名稱「變換」來自統計概念data transformation