Complete the code to import the LDA model from scikit-learn.
from sklearn.decomposition import [1]
The correct import for LDA in scikit-learn is LatentDirichletAllocation.
Complete the code to create an LDA model with 5 topics.
lda = LatentDirichletAllocation(n_components=[1], random_state=42)
We want 5 topics, so n_components=5 is correct.
Fix the error in the code to fit the LDA model on the document-term matrix named 'dtm'.
lda.fit([1])The LDA model fits on the document-term matrix, which is dtm.
Fill both blanks to get the topic-word distribution and the top words for the first topic.
topic_word = lda.[1]_ top_words = [vectorizer.get_feature_names_out()[i] for i in topic_word[[2]].argsort()[-10:]]
The components_ attribute holds topic-word distributions. Index 0 selects the first topic.
Fill all three blanks to transform documents to topic distributions and print the topic distribution for the first document.
doc_topic_dist = lda.[1](dtm) print(doc_topic_dist[[2]]) print(doc_topic_dist.shape[[3]])
transform converts documents to topic distributions. Index 0 selects the first document. Shape index 0 gives number of documents.