LDA 模型
现在是时候构建 LDA 模型了。使用 dictionary 和 corpus,您可以开始探索 Enron 邮件中包含哪些主题。通过快速打印各主题对应的词语,您可以先做一次初步探索,看看是否有显而易见的主题浮现。请注意,主题模型的计算开销较大,运行需要一段时间。我们来试试吧!
本练习是课程的一部分
Python 中的欺诈检测
练习说明
- 使用 gensim 的模型构建 LDA,传入
corpus,并将dictionary指定为id2word。 - 通过在模型结果上运行
print_topics保存 5 个主题,并选择每个主题排在前 5 的词。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Define the LDA model
ldamodel = gensim.models.____.____(____, num_topics=5, id2word=____, passes=5)
# Save the topics and top 5 words
topics = ____.____(num_words=____)
# Print the results
for topic in topics:
print(topic)