Complete the code to import the library needed for topic modeling.
from sklearn.decomposition import [1]
The NMF class from sklearn.decomposition is used for topic modeling by factorizing the document-term matrix.
Complete the code to create an NMF model with a specified number of topics.
model = NMF(n_components=[1], random_state=42)
The n_components parameter expects an integer number of topics, such as 5.
Fix the error in the code to fit the NMF model on the document-term matrix X.
W = model.[1](X)The fit_transform method fits the model and returns the topic distribution matrix W.
Fill both blanks to compute reconstruction error and print it.
error = model.[1] print('Reconstruction error:', model.[2])
The attribute reconstruction_err_ stores the reconstruction error after fitting the model.
Fill all three blanks to create a dictionary of topic words with their weights for the first topic.
topic_words = {word: model.components_[0, [1]] for [2], word in enumerate(vectorizer.get_feature_names_out()) if [3] < 10}We use idx as the index to access weights, idx as the index variable in enumeration, and filter words with index less than 10.