Sub topic 2
Explicit and implicit feedback
This chapter assumes you know basic Python, NumPy arrays, and the idea of a user-item matrix from the previous chapter. It covers the two kinds of signal that fill that matrix, how they differ, and how to turn a raw event log into usable matrices.
Two kinds of signal
A collaborative filtering system learns only from recorded behavior. That behavior comes in two forms.
- Explicit feedback is a deliberate statement of opinion by the user. Examples are a 1 to 5 star rating, a thumbs up or down, and a "not interested" button.
- Implicit feedback is behavior that suggests an opinion without stating one. Examples are clicks, page views, purchases, play counts, watch time, and adding an item to a wishlist.
The same algorithm family can consume either kind. The meaning of a number in the matrix is different, though, and that changes how you model, evaluate, and interpret it.
Explicit feedback
Explicit feedback is the cleaner signal. A rating of 1 says "I disliked this" and a rating of 5 says "I liked this". Both positive and negative opinions are observed. Because ratings are numbers on a known scale, you can treat prediction as a regression problem and measure it with RMSE.
Explicit data has these weaknesses:
- Scarcity. Most users rate very little. Rating takes effort and has no immediate payoff for the user, so the matrix is extremely sparse.
- Self-selection. People rate what they feel strongly about, or what they chose to consume in the first place. Missing ratings are therefore not random. A user who never watched a horror film has not rated one, which says nothing about how they would rate it.
- Scale differences. One user gives 4 to everything they enjoy. Another reserves 4 for exceptional items. Neighborhood methods usually correct for this by centering each user's ratings, which a later chapter covers.
- Context effects. Ratings given right after consuming an item, or in a public setting, can differ from private opinion.
Implicit feedback
Implicit feedback is abundant. Every interaction produces an event, and users do not have to do anything extra. This is why most production systems rely on it. It has properties that differ sharply from explicit data:
- No negative signal. A missing entry is ambiguous. The user may dislike the item, may never have seen it, or may not have had time. An observed event is also ambiguous. A user can click on an item and regret it.
- Values are confidence, not preference. A play count of 20 does not mean "rated 20 out of 5". It suggests the user probably likes the item, and with more confidence than a play count of 1.
- Noise. Accidental clicks, shared accounts, bots, autoplay, and auto-generated sessions all produce events.
- Exposure bias. Users can only interact with items the system showed them. Interactions reflect your interface and previous recommendations as well as taste.
Comparison
| Property | Explicit | Implicit |
|---|---|---|
| Volume | Low | High |
| Negative information | Yes (low ratings) | No |
| Meaning of a value | Preference strength | Confidence that the user likes the item |
| Meaning of a missing entry | Not rated (unknown) | Unknown, possibly dislike |
| Typical target | Predict the rating | Rank items |
| Typical metric | RMSE | precision@k, recall@k |
From event log to matrices
Real data arrives as a log of events, not a matrix. Each row records who did what to which item. Turning the log into a matrix involves three decisions: how to weight each event type, how to aggregate repeated events, and how to represent absence.
The following code implements this pipeline on a small log. A purchase counts for more than a view, and repeated events accumulate.
import numpy as np
events = [
("ana", "book", "view"), ("ana", "book", "view"), ("ana", "book", "purchase"),
("ana", "lamp", "view"),
("ben", "lamp", "view"), ("ben", "lamp", "add_to_cart"),
("ben", "desk", "view"),
("cy", "book", "view"),
("cy", "desk", "view"), ("cy", "desk", "view"), ("cy", "desk", "view"),
]
weights = {"view": 1.0, "add_to_cart": 3.0, "purchase": 5.0}
users = sorted({u for u, _, _ in events})
items = sorted({i for _, i, _ in events})
u_idx = {u: n for n, u in enumerate(users)}
i_idx = {i: n for n, i in enumerate(items)}
S = np.zeros((len(users), len(items)))
for u, i, kind in events:
S[u_idx[u], i_idx[i]] += weights[kind]
alpha = 0.5
P = (S > 0).astype(int) # did the user interact at all?
C = 1.0 + alpha * S # how much do we trust that preference?
print(items)
print(P)
print(C)Running it prints the following. The item columns are book, desk, lamp.
['book', 'desk', 'lamp']
[[1 0 1]
[0 1 1]
[1 1 0]]
[[4.5 1. 1.5]
[1. 1.5 3. ]
[1.5 2.5 1. ]]Read the two matrices together. P records what we believe the user likes. C records how strongly we believe it. Ana's purchase of the book gives it a confidence of 4.5. Her missing desk entry has the minimum confidence of 1, because the system does not know whether she dislikes it. This split into preference and confidence is the basis of the factorization method for implicit data covered later in the tutorial.
Design choices that matter
Weights per event type
The weights above (1, 3, 5) are assumptions. They encode a belief that a purchase is stronger evidence than a view. Tune them against a ranking metric on held-out data. Do not set them once and forget them.
Aggregating repeated events
Summing raw counts lets a heavy user or a single looping song dominate. Common alternatives are:
- Clip the score at a maximum.
- Compress it with
np.log1p(S). - Use a binary "ever interacted" value, which discards strength entirely.
Choose one deliberately. Counts that span several orders of magnitude can distort similarity and factorization training.
Time
An interaction from three years ago is weaker evidence than one from yesterday. If your catalog or users drift, apply a decay to old events before aggregating, or keep only a recent window.
Duration signals
Watch time and dwell time are often better than clicks. Normalize them, for example as a fraction of the item's length. Otherwise long items always look more popular than short ones.
Mixing both kinds
Some platforms have both ratings and behavior. Do not put them in one column as if they meant the same thing. Either train separate models and combine their outputs, or use a model that takes both as inputs. A rating of 1 should not be treated as a positive event just because it is nonzero.
Common errors
- Treating 0 as a dislike. In both matrices, 0 means "no observation". For explicit data, algorithms must ignore these entries, as the SGD training loop does later by iterating only over observed ratings. For implicit data, zeros are weak, low-confidence negatives at best.
- Evaluating implicit models with RMSE. There is no ground-truth rating to predict. Use ranking metrics such as precision@k and recall@k.
- Treating clicks as satisfaction. Clickbait gets clicks. If you optimize for them, you promote clickbait. Prefer signals that occur after consumption, such as completion, repeat use, or purchase.
- Ignoring exposure. An item with no interactions may simply never have been shown. Keep impression logs if you can.
Exercises
Exercise
A music app records play counts per user and track. User A played track X 40 times. User B played track Y once. Why is it wrong to say A rated X at 40 and B rated Y at 1, and what is a better interpretation?
Show answer
Play counts are implicit feedback. They do not measure preference on a fixed scale. A count of 40 is strong evidence that A likes X, and a count of 1 is weak evidence that B likes Y. A better interpretation is a binary preference (1 for both) with a confidence that grows with the count, for example c = 1 + alpha * count, possibly compressed with log1p so one looping track does not dominate.
Exercise
In the code above, ben has no entry for "book" and ana has none for "desk". Both zeros in S give a confidence of 1. What does that tell the model, and why is it not the same as a rating of 0 on a 1 to 5 scale?
Show answer
A zero means "no observation", so the model should treat it as unknown. It is a weak, low-confidence hint of dislike at most. A rating of 0 on a scale that starts at 1 would not be valid. If it were used, it would claim the user disliked the item more than any rating could say. Explicit data would exclude these entries from training. Implicit data keeps them with minimum confidence.
Exercise
You add a new event type, "share", and give it weight 10 because sharing seems important. List two things you should do before trusting that choice.
Show answer
First, evaluate the model with and without the new weight on held-out data, using a ranking metric such as precision@k or recall@k. Second, check how often "share" events occur and whether a few users or bots produce most of them. If they do, the weight rewards noise. Clipping or log-compressing the aggregated score can also limit the effect of outliers.