Matrix factorization in Python
In the previous section, we wanted to decompose our ratings matrix into two low-rank matrices in order to discover the intangible latent factors that drive consumers' decisions. One matrix maps the users' affinities for the discovered factors and the other maps the items' rankings on those factors.
So, let's look at how this can be implemented in Python. We've two files, als.py
and example_als_recommender
. Let's see our als.py
file. In the last section, we saw the item-to-item collaborative filter; ALS is very similar. It's going to implement RecommenderMixin
:
def __init__(self, R, factors=0.25, n_iter=10, lam=0.001, random_state=None):
We have several parameters for ALS. The first one, and the only non-optional one, is R
, our ratings matrix. In some of the math we've seen, we've referred to this interchangeably as R
and Q
. Again, that's kind of a quirk of the literature. Depending on what papers you're reading, it's one or the other. And the second parameter...