E ExamMaster

Machine Learning · Machine Learning Core

Recommender Systems

Predict what a person will like from a user–item table — content-based versus collaborative filtering, neighbourhood similarity, a popularity baseline, and cold start — not one…

Picture a four-member cinema club that keeps a sheet of film ratings. The members are Ananya, Bharat, Chitra and Dev. The films are Dune, Arrival, Inception, Amelie and Parasite. A number from 1 to 5 is how much that person liked that film; a blank means they have not seen it. Ananya's Parasite cell is blank. This lesson is about filling blanks like that — ranking films for one person — not predicting one rent for a flat. You will separate content-based filtering from collaborative filtering, score a neighbour with cosine similarity, beat a popularity baseline, and see why a new member or a new film with no ratings is a cold start.

  • Machine Learning
  • Medium level
  • 6 concepts
  • 10 practice questions

1A table of people and items

Stay with the cinema-club sheet. Four members — Ananya, Bharat, Chitra, Dev — and five films — Dune, Arrival, Inception, Amelie, Parasite. Read Ananya's row left to right: 5, 5, 4, 1, and a blank. Those numbers are ratings she already gave; the blank is Parasite, a film she has not seen. The job is not to invent a sixth film. It is to fill blanks like that and hand Ananya a ranked list of items for one person, not one rent for a flat.

Each cell is one person-and-film pair. A 5 means she loved it; a 1 means she did not; a blank is missing, not a zero. Bharat's Parasite cell is 1 — he saw it and shrugged. Everything below uses this same sheet. Machine Learning's 200-flat rent notebook is a different table: each row was one flat and the answer was already written. Neural recommenders that eat this club sheet wait for Deep Learning; here the tools are a popularity baseline, item tags, and neighbours whose rows look like yours.

Figure. The cinema-club sheet itself: four members, five films, numbers 1–5, and a blank. Ananya's Parasite cell is the thing to fill. The 200-flat rent notebook is a different table — one number per row, not a ranked list for one person.

Cinema-club ratings (blank = unrated)
MemberDuneArrivalInceptionAmelieParasite
Ananya5541
Bharat54521
Chitra12155
Dev2145

Read one blank on the club sheet

Ananya's row is 5, 5, 4, 1, blank. Bharat's row is 5, 4, 5, 2, 1. What does Ananya's last cell mean, and what number sits in Bharat's last cell for the same film?

  • Ananya, Parasite cellBlank — she has not rated it; that is the thing to fill
  • Bharat, Parasite cell1 — he saw it and did not like it

Pro tip. A blank is missing data, not a zero. Later cosine and column means both skip it.

The 200-flat rent notebook predicts one number per row. What is the recommender's job on the cinema-club sheet?
  1. Predict the club's average rent for a new flat
  2. Rank unseen films for one member from the blank cells
  3. Compress the five films into two principal components
  4. Cluster members by age without using any ratings

Rows are people and columns are items. The output is a personalised ranking, not a single rent and not an unsupervised plot of the same table.

2Tags versus other people

There are two classical families, and they read the club sheet from opposite sides. Content-based filtering describes each film with tags you already know — Dune, Arrival and Inception are sci-fi; Amelie is a romance; Parasite is a drama — then asks what Ananya already liked. Her sci-fi ratings are 5, 5 and 4, her romance rating is 1, so a content model proposes more sci-fi and stays away from romance. It never looks at Bharat's row.

Collaborative filtering ignores the tags and reads the other people. It asks: whose other ratings look like Ananya's? Those people are her neighbours. Then it copies what they did on the blank cell. Bharat also loved the three sci-fi films and shrugged at Amelie, so he is a neighbour; he rated Parasite 1, and that 1 becomes Ananya's collaborative guess. The two families can agree or fight; they are different evidence, not two names for the same method.

Figure. The same blank — will Ananya like Parasite? — is answered two ways. Content reads the drama tag against her sci-fi mean of 4.67. Collaborative reads Bharat, whose row looks like hers, and copies his 1.

  1. Content-basedTag each item, then match those tags to the person's past ratings on the same tags.
  2. CollaborativeFind people whose filled cells look like this person's, then read their rating on the blank item.
  3. Do not mix the namesA tag model never needs another member; a neighbour model never needs the poster.
What each family reads
FamilyReadsDoes not need
Content-basedItem tags + this person's past itemsAnyone else's row
CollaborativeOther people's ratings on shared itemsThe film's poster or genre
Ananya has never rated Parasite. A collaborative filter's next look-up is
  1. The director and genre printed on Parasite's page
  2. Ratings from members whose other cells look like Ananya's
  3. The film's budget and runtime
  4. The rent column from the 200-flat notebook

Collaborative filtering never opens the poster. It finds similar rows and reads those people's Parasite cell. Tags are the content-based family's input.

3A neighbour is a similar row

A neighbour is not a friend on the app. It is a person whose rating row points the same way as yours on the films you both saw. To compare Ananya and Bharat you drop Parasite (she has no rating there) and keep the four shared films, in order: Dune, Arrival, Inception, Amelie. Ananya's four numbers are 5, 5, 4, 1. Bharat's four numbers are 5, 4, 5, 2. Those two short lists are the only inputs to the comparison.

Cosine similarity is the cosine of the angle between those two lists: 1 means they point the same way, 0 means they are unrelated. Their cosine is 0.978 — almost the same direction. Ananya versus Chitra on the same four films is only 0.527: Chitra liked what Ananya did not. Once you have those scores, start from the nearest neighbour's rating on the blank. Bharat is nearest and rated Parasite 1, so the neighbourhood guess for Ananya is 1. You can later average several neighbours, weighted by similarity; the first skill is seeing that the guess comes from people, not from the film's poster.

Figure. Similarity is drawn as closeness to Ananya, not as friendship. Bharat at 0.978 is the nearest row; Dev at 0.606 is farther; Chitra at 0.527 is the least like her on the films they both rated. The Parasite guess starts from Bharat.

  1. Keep shared filmsDrop any film either person left blank. Cosine on a padded 0 treats unrated as hated.
  2. Score the angleCosine of the two short lists: nearer to 1 means the rows point the same way.
  3. Copy the nearest ratingThe nearest neighbour's number on the blank item is the first personalised guess.

Cosine, then copy Bharat's 1

On the four shared films, Ananya is (5, 5, 4, 1) and Bharat is (5, 4, 5, 2). Compute their cosine similarity, then write the nearest-neighbour guess for Ananya's blank Parasite cell. Bharat rated Parasite 1.

  • 5\times5 + 5\times4 + 4\times5 + 1\times267
  • \sqrt{25+25+16+1} and \sqrt{25+16+25+4}\sqrt{67}\approx 8.185, \sqrt{70}\approx 8.367
  • 67 / (8.185 \times 8.367)0.978
  • Nearest neighbour's Parasite rating1 — that is Ananya's neighbourhood guess

Pro tip. Ananya versus Chitra on the same four films is 24 / (\sqrt{67}\times\sqrt{31}) \approx 0.527. Start from 0.978, not from 0.527.

Ananya–Bharat cosine is 0.978; Ananya–Chitra is 0.527. Bharat rated Parasite 1, Chitra rated it 5. The first neighbourhood guess for Ananya is
  1. 5, because Chitra gave Parasite more stars
  2. 3, the average of 1 and 5 with equal weight
  3. 1, because Bharat is the nearer row
  4. 0.978, the cosine itself

The guess is a rating copied from a similar person, not the similarity score and not the higher raw star. Equal-weight averaging would ignore that Bharat is much nearer.

4The club favourite is a baseline

Before any neighbour search, there is a one-line baseline: ignore who is asking, and score each film by the average of the stars it already has. On the club sheet that is a column mean over the filled cells only — blanks are not zeroes. Parasite's observed ratings are Bharat 1, Chitra 5, Dev 5, so its popularity is (1+5+5)/3 = 3.67. Arrival also sits at 3.67; Inception is lowest at 2.75. A popularity recommender hands every member the same ranking.

That number is useful and easy to beat. Useful, because a film nobody liked is rarely the right first suggestion. Easy to beat, because popularity ignores who is asking. Ananya's nearest neighbour rated Parasite 1, so a personalised guess is 1 while the baseline says 3.67. If you ship the baseline and call it a recommender, Ananya gets the club favourite instead of a film for her.

Figure. Each bar is that film's mean over filled cells only: Dune 3.25, Arrival 3.67, Inception 2.75, Amelie 3.00, Parasite 3.67. Parasite ties Arrival as a club favourite, which is why a baseline would offer it to Ananya — her nearest neighbour's 1 is the personalised contradiction.

  1. Average the filled starsColumn mean over observed ratings only. A blank does not pull the mean toward zero.
  2. Same list for everyoneRank films by that mean. Ananya, Chitra and a stranger receive the identical order.
  3. Keep it as a baselineCompare every personalised guess to this number. Beating it is the first proof the neighbour was worth computing.

3.67 versus 1 on the same film

Parasite was rated 1, 5 and 5 by Bharat, Chitra and Dev. Ananya's nearest neighbour is Bharat. Write the popularity score and the neighbourhood score for Ananya.

  • Observed Parasite ratings1, 5, 5 (Ananya's cell is blank, so it is omitted)
  • (1+5+5)/33.67 — popularity, same for every member
  • Bharat's Parasite rating1 — neighbourhood score for Ananya

Pro tip. The disagreement is the lesson: a shared 3.67 is not Ananya's answer.

Parasite's mean observed rating is 3.67, but Ananya's nearest neighbour rated it 1. What is the 3.67?
  1. The correct personalised score for Ananya
  2. Proof that Parasite is tagged sci-fi
  3. The cosine between Ananya and Bharat
  4. A baseline that is the same for every member

A column mean does not know who asked. Ananya's personalised number in this lesson is the neighbour's 1, not the club mean.

5Empty rows and empty columns

Collaborative filtering and the popularity baseline both starve when a row or a column is empty. A new member, Esha, has no ratings yet: there is no vector to compare to Ananya or Bharat, so she has no neighbours, and a column mean still does not know what she likes. A new film, say a sci-fi title with no ratings yet, is just as blank: nobody's row contains a number for it, so user–user collaborative filtering cannot score it, and popularity has no stars to average.

Content-based filtering can still move. If the new film is tagged sci-fi, and Ananya's sci-fi mean on Dune, Arrival and Inception is (5+5+4)/3 = 4.67, a content model can propose it to her on day one. The swap is the other cold start: a brand-new person with no history gives content nothing to match either, unless you ask for a few tags up front. The practical rule: collaborative filtering needs overlapping ratings; content-based filtering needs a description of the item and some taste on those descriptions.

Figure. Ananya already has three sci-fi ratings, so a content model can propose a brand-new sci-fi film. Collaborative filtering cannot: that film has no stars, so no neighbour has a number to copy. Esha sits alone with an empty row — neither family has a history to read unless she names a few tags.

Who can move on day one
Blank thingCollaborative / popularityContent-based
New member, empty rowNo neighbours and no personal meanOnly if she names tags up front
New film, no ratingsNo stars to copy or averageYes, if its tags match her past items

A new sci-fi film with no ratings

A new sci-fi film arrives with no ratings. Ananya's sci-fi ratings are 5, 5 and 4. Can user–user collaborative filtering score it for her? Can a content model?

  • Ratings on the new filmNone — every member's cell is blank
  • User–user CF look-upEmpty — no neighbour has a number to copy
  • Ananya's sci-fi mean (5+5+4)/34.67 — a content model can propose the new film

Pro tip. Swap the blank: Esha with no ratings starves content as well, until she names a tag or rates one film.

A brand-new film has no ratings yet. Which method can still propose it to Ananya today?
  1. User–user collaborative filtering on the empty column
  2. Content-based, if you know its tags and her taste on those tags
  3. A popularity mean of its ratings
  4. k-means on the rent notebook

An empty column gives collaborative filtering and popularity nothing to average. Tags plus Ananya's past sci-fi ratings are enough for a content guess.

6Lab: popularity versus a neighbour

The notebook rebuilds the club sheet as a 4×5 array. A 0 is unrated, not a zero-star review — that is why every cosine is computed only on the films both people actually rated, and why popularity is a column mean over the positive cells only.

Cell 1 prints each film's popularity, Ananya's cosine with Bharat and with Chitra, and Bharat's Parasite rating (the neighbourhood guess). You should see popularity 3.67 for Parasite next to neighbour_guess_parasite 1 — the same disagreement the lesson just computed by hand.

Cell 2 draws those popularity means as a bar chart so the two 3.67 films (Arrival, Parasite) stand next to Inception at 2.75. The picture is the baseline, not Ananya's list.

No diagram — the popularity bars are drawn by the coding lab plot, not a static figure.

Lab checklist
StepWhy
0 means unratedA padded zero would fake a hate-rating and bend cosine
Column mean over R > 0Popularity must ignore blanks
Cosine on the overlap onlyAnanya and Bharat share four films, not five
Print Bharat's Parasite cellNearest-neighbour guess sits next to the 3.67 baseline

Coding lab. Club-sheet popularity and neighbour cosine runs in the app, with checks on your output.

The lab prints popularity 3.67 for Parasite and neighbor_guess_parasite 1. What is the 1?
  1. Ananya's cosine with Bharat, rounded
  2. Bharat's Parasite rating — Ananya's nearest neighbour
  3. How many members rated Parasite
  4. The rent of a one-room flat in the course notebook

Cell 1 copies R[1, 4], Bharat's filled Parasite cell. The cosine is 0.978; the count of raters is 3; neither is printed as 1.

Notes

  • A recommender ranks items for one person from a user–item table of ratings; blanks are the thing to fill, not missing features on a flat.
  • Content-based filtering matches item tags to a person's past items; collaborative filtering copies ratings from people whose rows look similar.
  • Popularity (column mean of observed ratings) is a baseline that ignores who is asking; a new user or new item with no ratings is a cold start.

Exam traps & shortcuts

  • Treat an unrated cell as missing, never as a zero-star review, or cosine and column means both lie.
  • Score a neighbourhood guess from people who actually rated the blank item; a popularity mean is the fallback, not the personalised answer.

Recap

Next: the applications lessons.

Different table, different job
The rent notebook predicts one number per flat. A recommender ranks items for one person from a user–item table of ratings.
Two families
Content-based filtering matches item tags to a person's past items. Collaborative filtering copies ratings from people whose rows look similar.
Neighbours
Cosine on the films two people both rated scores how alike the rows are. The nearest neighbour's rating on the blank is the first personalised guess.
Popularity is a baseline
A column mean of observed ratings is the same list for everyone. On this sheet Parasite is 3.67 by popularity and 1 by neighbourhood for Ananya.
Cold start
An empty row or an empty column starves collaborative filtering and popularity. Content-based filtering can still move when the new item has tags.

Practise Recommender Systems

Reading is free and needs no account. Practice, mocks and progress live in the app.

  • 10 exam-style questions on this topic, with explanations
  • A 5-question practice set that ends the chapter
  • Timed mocks scored with the real marking scheme
  • Readiness tracked per topic, kept on your device
Continue with Google — freeNo card, no trial. Works offline once installed.