Lesson 45 • Advanced
Building Recommender Systems 🎬
Learn how Netflix, Spotify, and Amazon recommend content using collaborative filtering, content-based methods, and hybrid systems.
What You'll Learn in This Lesson
- • User-based collaborative filtering with cosine similarity
- • Content-based filtering using item feature vectors
- • Matrix factorization (the algorithm behind Netflix Prize)
- • Hybrid systems that combine multiple approaches
- • How to handle the cold-start problem
1️⃣ Three Approaches to Recommendations
| Approach | How It Works | Example | Weakness |
|---|---|---|---|
| Collaborative | Find similar users/items from ratings | "Users like you watched..." | Cold start |
| Content-Based | Match item features to user preferences | "Because you liked sci-fi..." | Filter bubble |
| Hybrid | Combine both approaches | Netflix, YouTube, Spotify | Complexity |
Try It: Collaborative Filtering
Build a user-based recommendation engine using cosine similarity
import numpy as np
# ============================================
# COLLABORATIVE FILTERING
# ============================================
# "Users who liked X also liked Y"
np.random.seed(42)
print("=== User-Based Collaborative Filtering ===")
print()
print("Netflix's original algorithm: find users similar to you,")
print("then recommend what they watched that you haven't.")
print()
# User-Item rating matrix (0 = not rated)
users = ["Alice", "Bob", "Carol", "Dave", "Eve"]
movies = ["Inceptio
...Try It: Content-Based Filtering
Recommend movies by matching genre features to user preferences
import numpy as np
# ============================================
# CONTENT-BASED FILTERING
# ============================================
# "Recommend items SIMILAR to what you already liked"
np.random.seed(42)
print("=== Content-Based Filtering ===")
print()
print("Instead of needing other users, we match item features.")
print("If you liked 'Inception', we find movies with similar genres.")
print()
# Movie features: [action, romance, sci_fi, drama, comedy]
movies = {
"Inception": n
...Try It: Matrix Factorization
Decompose the rating matrix into latent factors — the algorithm behind the Netflix Prize
import numpy as np
# ============================================
# MATRIX FACTORIZATION & HYBRID SYSTEMS
# ============================================
np.random.seed(42)
print("=== Matrix Factorization (How Netflix Actually Works) ===")
print()
print("Decompose the rating matrix into User and Item latent factors.")
print("Each user and item gets a vector of 'hidden preferences'.")
print()
# Ratings matrix (0 = missing)
R = np.array([
[5, 3, 0, 1, 4],
[4, 0, 4, 1, 5],
[1, 5, 0, 5
...⚠️ Common Mistakes
📋 Quick Reference — Recommender Systems
| Method | Use When |
|---|---|
| User-CF | Rich interaction data, many users |
| Item-CF | More items than users (e-commerce) |
| Content-Based | New users, good item metadata |
| Matrix Factorization | Large sparse matrices (SVD, ALS) |
| Deep Hybrid | Large-scale production (Two-Tower) |
🎉 Lesson Complete!
You can now build recommendation engines! Next, learn how Graph Neural Networks model relationships in social networks and knowledge graphs.
Sign up for free to track which lessons you've completed and get learning reminders.