Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Supervised Machine Learning with Python

You're reading from   Supervised Machine Learning with Python Develop rich Python coding practices while exploring supervised machine learning

Arrow left icon
Product type Paperback
Published in May 2019
Publisher Packt
ISBN-13 9781838825669
Length 162 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Taylor Smith Taylor Smith
Author Profile Icon Taylor Smith
Taylor Smith
Arrow right icon
View More author details
Toc

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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £16.99/month. Cancel anytime