Search code examples
machine-learningscikit-learnrecommendation-enginenmf

What is n_components in NMF(Non-Negative Matrix Factorization) in sklearn?


What is n_components in sklearn.NMF?

nmf = NMF(n_components=2, init='random', random_state=0)
nmf.fit(V)

Solution

  • Here's one example of how I've seen this parameter used:

    When used for topic modeling in natural language processing, n_components can be used as the number of topics to print out.

    For example, if I fit the NMF object on a TF-IDF vectorizer and set n_components = 10, I can use it to show me 10 different collections of words that I can interpret as my topics.