Example of matrix factorization

I am using the code currently given at http://www.quuxlabs.com/blog

This gives a good result. And I clearly see what changes in the matrix have occurred.

I also tried using the sklearn library at sklearn.decomposition.NMF But the results that I got with the same input are not good enough. Maybe I missed something.

Here is my sample code -

from sklearn.decomposition import NMF , ProjectedGradientNMF R = [ [5,3,0,1], [4,0,0,1], [1,1,0,5], [1,0,0,4], [0,1,5,4], ] R = numpy.array(R) nmf = NMF(beta=0.001, eta=0.0001, init='random', max_iter=2000,nls_max_iter=20000, random_state=0, sparseness=None,tol=0.001) nR = nmf.fit_transform(R) print nR print print nmf.reconstruction_err_ print 

It does not support output / populated values ​​in the matrix, as I can see, using the code provided on the blog.

Can someone help me understand!

+6
source share
1 answer

Hmmm ... very dumb! I went through nmf.py and found that fit_tranform returns only W and nmf.component_ get the value H. The dot product of them gives a new R.

 from sklearn.decomposition import NMF , ProjectedGradientNMF R = [ [5,3,0,1], [4,0,0,1], [1,1,0,5], [1,0,0,4], [0,1,5,4], ] R = numpy.array(R) nmf = NMF() W = nmf.fit_transform(R); H = nmf.components_; nR = numpy.dot(W,H) print nR 
+14
source

Source: https://habr.com/ru/post/985176/


All Articles