Skip to content
Tutorials Center
My learning

Topics

Lesson 17 of 38 ยท Collaborative Filtering

Shrinkage and Neighborhood Tuning

Fix noisy similarities with shrinkage, minimum overlap and significance weighting, then tune k, thresholds and the similarity measure on a validation split.

Neighborhood methods work only if the similarities are trustworthy. Two users who co-rated just two items and agreed on both have a Pearson similarity of 1.0, which is meaningless. This lesson shows how to shrink unreliable similarities toward zero, set sensible limits, and tune the handful of hyperparameters that decide whether item-based or user-based CF beats the bias baseline.

The problem: similarity from tiny overlap

A similarity is an estimate. Estimates from few observations are noisy, and with sparse data many pairs overlap on only a handful of items. If you rank neighbors by raw similarity, the top of the list fills with lucky pairs with tiny overlap.

Python Raw similarity rewards tiny overlaps

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.

Totally unrelated users show high correlations when the overlap is small. We must not trust them.

Shrinkage

Multiply the similarity by a factor that is small for small overlap and approaches 1 for large overlap:

sim' = sim ยท n / (n + ฮฒ)

n is the number of co-raters and ฮฒ the shrinkage strength (commonly 10 to 100). With ฮฒ = 25, a pair with 5 co-raters keeps only 5/30 = 17% of its similarity; a pair with 100 keeps 80%.

An alternative is significance weighting: sim ยท min(n, ฮณ) / ฮณ, which caps the penalty once the overlap reaches ฮณ. Or a hard minimum overlap: ignore pairs with n < n_min.

Python Shrinkage in action

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 "best" raw pair A-B (0.95 from 3 co-raters) falls to last place. The pair with 200 co-raters and a modest 0.40 now ranks ahead of it.

Applying it to item-based CF

Python Shrink similarities, 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.

Here the baseline alone scores about 1.15 and the neighbors bring the error to about 0.86, but changing beta from 0 to 100 moves the RMSE by less than 0.01. That is an honest result: in this synthetic set every item pair has many co-raters, so there is little noise to shrink. Shrinkage pays off when overlaps are small (sparse catalogs, long tails), so test it on your own data rather than assuming it helps.

A tuning checklist

Knob Typical values Effect
k (neighbors) 10 to 100 small = noisy, large = blurred
Shrinkage ฮฒ 10 to 100 trusts small-overlap pairs less
Min overlap 2 to 10 drops unreliable pairs
Similarity Pearson, adjusted cosine, cosine changes who counts as a neighbor
Similarity power sim ** 2 or sim ** 3 amplifies strong neighbors
Baseline none, global, user+item decides what neighbors must explain

Tune with a validation split (a time-based split when timestamps exist), change one knob at a time, and keep the test set for the end. A grid of 20 to 50 combinations is usually enough.

Make similarities honest

Shrink sim ร— n / (n + ฮฒ)
Min overlap Drop pairs with few co-raters
Significance Cap the penalty at ฮณ

Large overlap, trusted. Small overlap, doubted.

1 / 2

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why is a similarity of 1.0 based on two co-rated items unreliable?

    Small samples produce extreme values by chance; shrinkage and minimum overlap guard against this.
  2. 2. With sim' = sim * n / (n + 25), what happens when n = 25?

    25 / (25 + 25) = 0.5, so the similarity is multiplied by one half.
  3. 3. What does increasing k in a neighborhood model usually do?

    More neighbors reduce variance but include less similar ones; choose k by validation error.
  4. 4. Which data should be used to choose beta and k?

    Tuning on the test set leaks information and inflates the final score.

Summary

  • Similarities from few co-raters are noisy; shrink them by n / (n + ฮฒ) or require a minimum overlap.
  • Tune k, ฮฒ, the similarity measure and the baseline on a validation split, one at a time.
  • Combine shrinkage with a bias baseline for the most dependable neighborhood models.

Next: Item-based CF for Implicit Feedback