Skip to content
Tutorials Center
My learning

Topics

Lesson 37 of 38 ยท Projects and Practice

Project: An Implicit-Feedback Music Recommender

Build a play-count recommender: log-scale the counts, compare popularity, item-kNN, ALS and EASE on recall, NDCG and coverage, then add similar-artist lists and explanations.

Streaming services have no star ratings: they have play counts. This second project uses the implicit-feedback toolbox of the track. You will build a listening dataset with a long tail, transform play counts into useful weights, compare four recommenders on the same split with ranking metrics and coverage, and finish with two product features: a "similar artists" list and a human-readable explanation.

Step 1: the data and the weights

We simulate 250 listeners and 80 artists in four music scenes. Artist popularity follows a long-tail (power-law) shape, and listeners play artists from their own scene more often. Play counts are skewed: most listener-artist pairs have a few plays, while a few reach dozens. Using raw counts as "preference strength" lets those outliers dominate, so we compress them with log1p.

Python Step 1: skewed play counts and log scaling

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 log weights 0.69, 2.40 and 4.62 grow far slower than the raw counts: one hundred plays is not one hundred times stronger evidence of taste than one play.

Step 2: four recommenders, one evaluation

For each listener we hide 20% of their artists. We then rank unheard artists with:

  1. Popularity: the number of listeners per artist.
  2. Item-kNN: cosine similarity between artist columns of the training matrix (see similarity measures).
  3. ALS with confidence 1 + ฮฑ ยท log1p(plays) as in ALS and Implicit Feedback.
  4. EASE, the closed-form linear autoencoder from Autoencoders for Recommendation.

We score recall@10, NDCG@10 and the catalog coverage of the top-10 lists, which is the metric trio recommended in the evaluation chapter.

Python Step 2: popularity vs kNN vs ALS vs EASE

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.

Read the table the way a reviewer would. All three personalized models beat popularity by a wide margin (recall about 0.64 to 0.70 against 0.37). Item-kNN and EASE are nearly tied, and ALS is a little behind here with its untuned ฮฑ and factor count; on 250 listeners, differences of a few hundredths are noise. Coverage shows the other side: popularity shows only about a quarter of the catalog, the personalized models almost all of it. A model that gains accuracy by recommending only the most popular artists to everyone is a worse product than the numbers suggest.

Step 3: product features

A recommender produces more than a list. Two features that listeners notice:

  • Similar artists: for an artist page, show the artists with the highest item-item similarity.
  • Explanations: "Because you listened to A and B". The explanation for a recommended artist j is the listened artists i that contribute most to its score, S[i, j]. Explanations build trust and give the user a way to correct the system.
Python Step 3: similar artists and explanations

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.

Notice that the explanations are cheap to compute for neighborhood models because the score is a sum of contributions. For factorization or neural models you need other techniques (feature attributions, or generating explanations from similar items), which is one reason item-kNN remains common as a first model and as an explainer.

Where to go from here

  1. Replace the random listener-artist generator with a real play-count file; keep the same pipeline.
  2. Split by time (last week of listening as test) instead of hiding artists at random.
  3. Add BPR as a fifth model.
  4. Serve the best model with an ANN index of artist vectors.
  5. Plan the experiment that would prove the new model helps real listeners (see A/B testing).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why apply log1p to play counts before using them as weights?

    Log scaling compresses the tail, so 100 plays is stronger evidence than 1 play but not 100 times stronger.
  2. 2. How is the explanation 'because you listened to X' computed in item-kNN?

    The score is a sum of similarity contributions from heard items; the largest ones are the explanation.
  3. 3. Which metric trio gives a balanced view of a recommender in this project?

    Recall and NDCG measure accuracy; coverage shows whether the lists are spread over the catalog.
  4. 4. What makes it fair to compare popularity, kNN, ALS and EASE here?

    Comparisons are only meaningful on identical splits, candidates and cutoffs.

Summary

  • Implicit data needs weights: compress play counts (for example log1p) before learning.
  • Compare popularity, item-kNN, ALS and EASE on the same split with recall, NDCG and coverage.
  • Neighborhood scores give cheap similar-item lists and explanations.
  • Next steps: real data, time splits, BPR, ANN serving and an online experiment.

Next: Recommender Systems Practice Set