如何使用scikit learn获取特定文档的主题概率?

How to get the topics probability of a specific document using scikit learn?

我想在一组文档上应用 LDA。假设计算文档属于某个主题的概率。我做了以下事情:

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 的文档很漂亮弱,你知道这个信息是否容易获得吗?

问:我也有同样的问题,请问有人解决了吗? 我不知道有没有它不允许我在这里添加评论,但它让我添加到别人的 post.

我最近遇到了同样的问题。您可以使用以下方法将模型应用于每个样本:lda.transform(tfidf)

请注意,您需要为此使用向量 tfidf。

我认为"transform"这个名字来自data transformation

的统计概念