Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 38 ยท Projects and Practice

Project: A Movie Recommender

End-to-end project: build a movie rating dataset, split it by time, set baselines, train biased matrix factorization, evaluate with RMSE and NDCG, and produce readable top-N lists.

In this project you put the track together: data, a leakage-free split, baselines, a matrix factorization model, evaluation with both rating and ranking metrics, and finally a function that prints recommendations a person can read. Everything runs in your browser with NumPy.

The dataset is synthetic, so the whole project is self-contained and the results are reproducible. Its structure resembles a real movie site: users with a taste for particular genres, movies with titles and genres, ratings from 1 to 5 stamped with a day number. The same steps apply unchanged to a real ratings file with columns user, movie, rating, timestamp.

Step 1: data and a time-based split

We create 200 users and 100 movies with 4 genres, generate ratings whose value depends on the user's genre taste plus a user generosity and a movie quality effect, and keep each rating's day. The last 20% of days become the test set, as the dataset lesson recommends.

Python Step 1: ratings, genres and the time split

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Always look at the histogram: here most ratings are 3s and 4s (real rating sets are usually skewed to the high end), which is why a global-mean baseline is already decent. The final output should show the model clearly ahead of every baseline in both RMSE (about 0.71 against 1.01 for the global mean) and NDCG@10 (about 0.15 against 0.07 for popularity).

Step 2: baselines

We need numbers to beat. The next block repeats the data code in compact form, then scores three baselines on the test set: the global mean, the per-movie mean and a user-and-movie bias model. It reports RMSE.

Python Step 2: baselines with RMSE

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Each baseline improves on the previous one, and the bias model is the one a factorization has to beat: if a fancy model cannot beat it, the added complexity is not paying off.

Step 3: matrix factorization, evaluation and recommendations

Now we fit biased matrix factorization with SGD (the model from SGD and Biased Matrix Factorization) and evaluate it in two ways. RMSE on the held-out ratings measures rating accuracy. For ranking, for every user with at least one liked test movie (rating of 4 or more) we rank all movies that user has not rated in training and compute NDCG@10 against those liked movies, then compare with a popularity ranking. Finally we print a recommendation list with titles.

Python Step 3: train, evaluate and recommend

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The final lines are the part a product owner cares about: a short, readable list. For user 7 the top two are Drama, the user's hidden favorite, followed by Sci-Fi titles that the model predicts well: a sensible list, though not a perfect one, which is what an NDCG of 0.15 on a tiny dataset looks like.

What to try next

Extend the project as practice. Each idea uses a lesson from the track:

  1. Tune k, reg and lr on a validation split carved from the training days, then retrain on everything and report the test score once.
  2. Add the item-item collaborative model and a genre-based content model, and combine them in a hybrid. Compare light and heavy users separately.
  3. Add beyond-accuracy metrics: coverage and intra-list diversity of the top 10 lists. Apply MMR and see what it costs in NDCG.
  4. Cold start: hide all but 3 ratings of 20 users and measure how the model copes (see Cold Start).
  5. Swap in real data: load a public ratings file with pandas, build the same arrays and rerun every step.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does this project split the ratings by day instead of randomly?

    A time split reproduces production use, where the model only knows the past.
  2. 2. What is the purpose of the baselines (global mean, movie mean, bias model)?

    A model's score has no meaning without simple reference points on the same split.
  3. 3. Why are movies already rated by a user removed before ranking recommendations?

    Known items must be excluded from the candidates for both the product and the evaluation.
  4. 4. Why evaluate with both RMSE and NDCG@10?

    A good rating predictor is not automatically a good ranker, so you check both.

Summary

  • A complete project: data, time split, baselines, biased MF, rating and ranking evaluation, readable output.
  • Baselines (global mean, movie mean, biases) set the bar the model must clear.
  • Report RMSE and NDCG@10, excluding seen items from the ranking.
  • Extend it with tuning, hybrids, diversity metrics and cold-start tests.

Next: Project: An Implicit-Feedback Music Recommender