開始使用免費開始

LDA 模型

現在是時候來建立 LDA 模型了。利用 dictionary 與 corpus,你就能找出 Enron 郵件中包含哪些主題。先快速列印每個主題所對應的字詞,做第一步的探索,看看是否有明顯的主題浮現。請注意,主題模型計算量很大,執行需要一段時間。來試試看吧!

本練習屬於課程

Fraud Detection in Python

檢視課程

練習說明

  • 從 gensim 的 models 建立 LDA 模型,並插入 corpus 與 dictionary。
  • 透過在模型結果上執行 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)
編輯並執行程式碼