Book Image

Supervised Machine Learning with Python

By : Taylor Smith
Book Image

Supervised Machine Learning with Python

By: Taylor Smith

Overview of this book

Supervised machine learning is used in a wide range of sectors, such as finance, online advertising, and analytics, to train systems to make pricing predictions, campaign adjustments, customer recommendations, and much more by learning from the data that is used to train it and making decisions on its own. This makes it crucial to know how a machine 'learns' under the hood. This book will guide you through the implementation and nuances of many popular supervised machine learning algorithms, and help you understand how they work. You’ll embark on this journey with a quick overview of supervised learning and see how it differs from unsupervised learning. You’ll then explore parametric models, such as linear and logistic regression, non-parametric methods, such as decision trees, and a variety of clustering techniques that facilitate decision-making and predictions. As you advance, you'll work hands-on with recommender systems, which are widely used by online companies to increase user interaction and enrich shopping potential. Finally, you’ll wrap up with a brief foray into neural networks and transfer learning. By the end of this book, you’ll be equipped with hands-on techniques and will have gained the practical know-how you need to quickly and effectively apply algorithms to solve new problems.
Table of Contents (11 chapters)
Title Page
Copyright and Credits
About Packt

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, and example_als_recommender. Let's see our 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,

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