# How recommendations work · AI in Bed

Intermediate level · 7 min · https://www.aiinbed.com/learn/intermediate/recommender-systems

*"Because you watched...": how apps guess what you'll like next, from similar users to embeddings, and the loops that can narrow what you see.*

Every time a streaming app suggests a film or a shop shows "you might also like", a **recommender system** is at work. Its job is to guess how much you'd like things you haven't seen yet. There are two classic approaches, and most real systems blend them.

### Collaborative filtering

**Collaborative filtering** uses only behaviour: who watched, rated or bought what. If you and another person loved the same five films, you'll probably like their sixth favourite too.

It needs no knowledge of what the items actually are. The crowd's patterns do the work.

### Content-based filtering

**Content-based** recommenders look at the items themselves: genre, actors, ingredients, the words in an article. If you read lots of gardening pieces, it suggests more gardening.

It works even for brand-new items, but tends to serve more of the same.

**Find your taste twin**

```python
from math import sqrt
# Star ratings (0 = not watched yet)
films = ["Space Saga", "Robot Love", "Baking Show", "Garden Diaries", "Alien Dawn"]
ratings = {
    "Ana":  [5, 4, 0, 1, 0],
    "Ben":  [4, 5, 1, 0, 5],
    "Cleo": [1, 0, 5, 4, 1],
    "Dev":  [0, 1, 4, 5, 2],
}

def cosine(u, v):
    dot = sum(a * b for a, b in zip(u, v))
    return dot / (sqrt(sum(a * a for a in u)) * sqrt(sum(b * b for b in v)))

me = "Ana"
sims = {other: cosine(ratings[me], r) for other, r in ratings.items() if other != me}
for other, s in sorted(sims.items(), key=lambda x: -x[1]):
    print(f"{me} vs {other}: similarity {s:.2f}")
twin = max(sims, key=sims.get)
for i, film in enumerate(films):
    if ratings[me][i] == 0 and ratings[twin][i] >= 4:
        print(f"Because {twin} liked it, try: {film}")
```

Cosine similarity compares the pattern of ratings, not the totals. Change Ana's ratings and see who her new twin becomes.

**Quick check:** A collaborative filtering system recommends you a film. What is it mainly based on?

A. The film's genre and cast
B. What people with similar viewing habits enjoyed
C. The film's age rating
D. Which film is newest

Answer: B. Collaborative filtering relies on patterns of behaviour across users, not on details about the film itself.

### Users and items as embeddings

Modern systems learn an **embedding**, a list of numbers, for every user and every item. The numbers are tuned so that a user's vector sits close to items they like.

Nobody labels the dimensions, but they often end up capturing things like "cosy", "action-heavy" or "for kids". Recommending becomes finding the nearest items to you.

### The cold start problem

A new user has no history; a new item has no ratings. Collaborative filtering has nothing to go on. This is the **cold start** problem.

Common fixes: ask a few questions at sign-up, fall back on popular items, or use content features until behaviour builds up.

> A good bookseller does both kinds of recommending. "People who loved that also adored this" is collaborative. "You like slow, quiet novels set by the sea" is content-based.

- **Feedback loops**: the system shows you things, you click some, and it learns from those clicks. Items it never showed can never earn clicks.
- Over time this can narrow what you see, sometimes called a **filter bubble**.
- Popular items get shown more, so they get more popular, while niche items struggle to be found.
- Many systems deliberately mix in some variety and new items to keep exploring.

**Quick check:** Why can a recommender's own suggestions narrow what users end up seeing?

A. Because it deletes items users haven't rated
B. Because it learns from clicks on what it chose to show, reinforcing its earlier choices
C. Because embeddings can only store a few items
D. Because users are forbidden from searching

Answer: B. The system mostly sees reactions to things it already picked. That feedback loop can reinforce past choices unless it deliberately explores.

**Key takeaways**

- Collaborative filtering uses similar people's behaviour; content-based uses the items' features.
- Modern recommenders place users and items as embeddings in the same space.
- Cold starts and feedback loops are the big challenges, and variety helps with both.

**Go deeper (free sources)**

- [Recommendation Systems course](https://developers.google.com/machine-learning/recommendation) by Google
- [Degenerate Feedback Loops in Recommender Systems](https://arxiv.org/abs/1902.10730) by Jiang et al. (2019)
