AI Hints
Home›Machine Learning Tutorial›Reducing Dimensions
Machine Learning · Lesson 50 of 85

Recommendation Systems

Because you liked this.

⏱ 2 min read▶ Video at 1:47:44🎓 Free
Watch this lesson in the Machine Learning courseWatch on YouTube ↗Full Machine Learning course

Most of what people watch on the big streaming services comes from recommendations, not from searching. These systems earn billions. And at heart, the idea is one that you already know. People who liked what you liked may like other things you have not tried yet.

Recommendation Systems
From the video: Recommendation Systems
  • Most viewing comes from recommendations
  • Worth billions
  • The idea is simple

Two main approaches

There are two classic approaches. Content based filtering looks at the items themselves. You liked a science fiction film, so here is another. Collaborative filtering ignores the content completely, and only looks at behaviour. People who liked Alien also liked Blade Runner. It can find surprising connections, but it struggles with brand new items, which have no history. That is called the cold start problem. Modern systems mix both.

Content basedsimilar items
Collaborativesimilar people
Cold startnew items have no history
Hybridmodern systems mix both

A tiny film recommender

Here is a tiny ratings table, with five people and five films. We turn each film into a list of who rated it, and how. Cosine similarity measures the angle between two of those lists. If the same people like both films, the angle is small. We look up Alien, and sort by similarity. Run it. It recommends Blade Runner first. We gave it no genres and no descriptions, and it found the link from behaviour alone. Real systems use the same idea, on billions of ratings.

recommender.pypython
import numpy as np
from sklearn.metrics.pairwise import cosine_similarity

films = ["Alien", "Blade Runner", "Toy Story", "Frozen", "Up"]
ratings = np.array([[5, 5, 1, 1, 2],
                    [4, 5, 0, 1, 1],
                    [1, 0, 5, 4, 5],
                    [0, 1, 4, 5, 4],
                    [5, 4, 1, 0, 0]], dtype=float)

sim = cosine_similarity(ratings.T)
target = films.index("Alien")
order = np.argsort(-sim[target])

for i in order[1:4]:
    print(f"Because you liked Alien: {films[i]:<13} {sim[target, i]:.3f}")
Output
Because you liked Alien: Blade Runner  0.970
Because you liked Alien: Up            0.342
Because you liked Alien: Toy Story     0.279

Summary

Whether it is finding groups, spotting oddities, or recommending films, unsupervised ideas are everywhere. That is the end of this module, and you have now covered the core algorithms of machine learning. Next, a new skill. How do you squeeze the last bit of performance out of a model, without fooling yourself?

Key takeaways
  • Content: similar items
  • Collaborative: similar people
  • Cosine measures similarity
Next up: Hyperparameter Tuning — grid search and random search