of them similarly to the components in nmftopics don' have an inherent orderingand changing the number of topics will change all of the topics we'll use the "batchlearning methodwhich is somewhat slower than the default ("online"but usually provides better resultsand increase "max_iter"which can also lead to better modelsin[ ]from sklearn decomposition import latentdirichletallocation lda latentdirichletallocation(n_topics= learning_method="batch"max_iter= random_state= we build the model and transform the data in one step computing transform takes some timeand we can save time by doing both at once document_topics lda fit_transform(xlike the decomposition methods we saw in latentdirichletallocation has components_ attribute that stores how important each word is for each topic the size of components_ is (n_topicsn_words)in[ ]lda components_ shape out[ ]( to understand better what the different topics meanwe will look at the most important words for each of the topics the print_topics function provides nice formatting for these featuresin[ ]for each topic ( row in the components_)sort the features (ascendinginvert rows with [:::- to make sorting descending sorting np argsort(lda components_axis= )[:::- get the feature names from the vectorizer feature_names np array(vect get_feature_names()in[ ]print out the topicsmglearn tools print_topics(topics=range( )feature_names=feature_namessorting=sortingtopics_per_chunk= n_words= in factnmf and lda solve quite related problemsand we could also use nmf to extract topics topic modeling and document clustering