I'm trying to use sklearn.decomposition.NMF to a matrix R that contains data on how users rated items to predict user ratings for items that they have not yet seen.

the matrix's rows being users, columns being items, and values being scores, with 0 score meaning that the user did not rate this item yet.

Now with the code below I have only managed to get the two matrices that when multiplied together give the original matrix back.

import numpy

R = numpy.array([

from sklearn.decomposition import NMF
model = NMF(n_components=4)

A = model.fit_transform(R)
B = model.components_

n = numpy.dot(A, B)

Problem is, that the model does not predict new values in place of 0's, that would be the predicted scores, but instead recreates the matrix as was.

How do I get the model to predict user scores in place of my original matrix's zeros without underfitting? Also, the model wont accept np.nan as matrix inputs so I can't see a way to communicate that the users have not yet rated the items.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.