Skip to content
Tutorials Center
My learning

Topics

Lesson 16 of 38 ยท Collaborative Filtering

Bias Baselines and Rating Prediction

Predict ratings with global mean plus user and item biases, fit them by regularized least squares, evaluate with RMSE, and use the baseline inside neighborhood models.

Before any clever neighborhood or factor model, there is a surprisingly strong prediction: this user's usual rating, adjusted for how good this item usually is. Some users give 5 stars to everything; some films are loved by everyone. These biases explain a large part of the variance in ratings, and ignoring them makes every other model worse.

This lesson fits a bias baseline, checks how far it gets, and shows how to plug it into item-based and user-based prediction so that neighbors only have to explain what the biases cannot.

The model

rฬ‚(u, i) = ฮผ + b_u + b_i

  • ฮผ is the global mean rating.
  • b_u is how much user u rates above or below average.
  • b_i is how much item i is rated above or below average.

Example: ฮผ = 3.5, a harsh user with b_u = -0.6 and a beloved film with b_i = +0.8 give a prediction of 3.7.

Simple estimates: mean offsets

The quickest fit is two passes. First, b_i = the item's mean residual after removing ฮผ; then b_u = the user's mean residual after removing ฮผ + b_i. Add regularization so items with three ratings do not get extreme biases:

b_i = ฮฃ (r - ฮผ) / (ฮปโ‚ + n_i)

The ฮป in the denominator shrinks the bias toward zero when n_i is small. It is the same shrinkage idea used in the popularity baseline.

Python Fit biases and measure 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 step lowers the error. A bias baseline alone is often within a few percent of far more complex models, which is why reporting it is the honest first line of any evaluation table.

Choosing the regularization

Large ฮป shrinks all biases toward zero (underfit); ฮป = 0 trusts tiny samples (overfit). Choose by validation RMSE. A typical starting range is 5 to 25.

Python Tune lambda on validation data

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.

Using the baseline inside neighborhood models

Instead of averaging raw ratings of neighbors, average their residuals from the baseline b(u, i) = ฮผ + b_u + b_i:

rฬ‚(u, i) = b(u, i) + ฮฃ sim(i, j) ยท (r(u, j) - b(u, j)) / ฮฃ |sim(i, j)|

This is the generalization of mean-centering: it removes both user and item effects, so neighbors explain only the interaction (the part you cannot get from biases).

Python Item-based CF on top of the baseline

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.

Here the neighbors cut the RMSE from about 0.99 to 0.90, so they do add information beyond the biases. How much they add depends on the number of co-ratings behind each similarity, which is why the next lesson shrinks similarities.

Bias terms are also the first two parameters of matrix factorization: the complete model is ฮผ + b_u + b_i + p_u ยท q_i.

Baseline predictor

Global mean ฮผ Average of all ratings
User bias b_u Generous or harsh
Item bias b_i Loved or disliked

rฬ‚ = ฮผ + b_u + b_i

1 / 2

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In rฬ‚ = ฮผ + b_u + b_i, what does b_u capture?

    It is the user's average offset: positive for generous raters, negative for harsh ones.
  2. 2. Why divide by (ฮป + n_i) instead of n_i?

    Regularization prevents extreme biases from tiny samples, reducing overfitting.
  3. 3. How should you select lambda?

    Lambda is a hyperparameter; choose the value with the best validation error.
  4. 4. What do neighborhood models average when built on top of a baseline?

    Residuals remove user and item effects so neighbors explain only what the baseline cannot.

Summary

  • A baseline ฮผ + b_u + b_i captures generosity and item quality and is a strong benchmark.
  • Fit biases by alternating regularized mean offsets; choose lambda on validation data.
  • Neighborhood models are better applied to baseline residuals.
  • The same biases appear again in matrix factorization.

Next: Shrinkage and Neighborhood Tuning