[scikit-learn] How to get the factorization from NMF in scikit learn

Raphael C drraph at gmail.com
Wed Sep 7 08:17:46 EDT 2016


I am trying to use NMF from scikit learn. Given a matrix A this should
give me a factorization into matrices W and H so that WH is
approximately equal to A. As a sanity check I tried the following:

from sklearn.decomposition import NMF
import numpy as np
A = np.array([[0,1,0],[1,0,1],[1,1,0]])
nmf = NMF(n_components=3, init='random', random_state=0)
print nmf.components_

This gives me a single 3 by 3 matrix as output. What is this
representing? I want the two matrices W and H from the factorization.
How can I get these two matrices?

I am sure I am just missing something simple.

Raphael


More information about the scikit-learn mailing list