Complete the code to import the LDA model from scikit-learn.
from sklearn.decomposition import [1]
The correct import for Latent Dirichlet Allocation in scikit-learn is LatentDirichletAllocation.
Complete the code to create an LDA model with 5 topics.
lda = LatentDirichletAllocation(n_components=[1], random_state=42)
n_components with other parameters.Setting n_components=5 creates an LDA model with 5 topics.
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 named dtm here.
Fill both blanks to get the topic distribution for the first document.
topic_distribution = lda.[1]([2])[0]
fit_transform after fitting the model.Use transform on the document-term matrix dtm to get topic distributions. Index 0 gets the first document's distribution.
Fill all three blanks to create a dictionary of top words per topic from the LDA components.
top_words = {i: [feature_names[j] for j in lda.components_[i].argsort()[-[1]:][::-1]] for i in range([2])}
print(top_words)
# feature_names = vectorizer.get_feature_names_out()
# lda = LatentDirichletAllocation(n_components=[3])We get the top 5 words per topic, so 10 is too many. The number of topics is the number of rows in lda.components_, which is lda.components_.shape[0]. The n_components parameter is the number of topics set in the model.