A student has just finished resource A on a learning platform, and the platform has to choose which of resources B, C and D to suggest next. It could suggest whatever most students used, or it could use this student’s record together with the records of students who behaved similarly. Most students never rated most resources, though, so the data are full of gaps, and a gap is not a verdict. This lesson builds recommendation scores from item content, from patterns across users and from matrix factorization, and grades the ranked lists with precision at k and normalized discounted cumulative gain under a stated candidate set, cutoff and time boundary.
Key terms
Recommender system
Definition A recommender system takes a user and a decision time and returns a ranked list of items, in three stages. Candidate generation selects the candidate set , the items of the catalog that may be recommended to this user at that time, for example the available items the user has not already completed. Scoring assigns each candidate a number computed only from information recorded before . Ordering lists the candidates by decreasing score, breaks ties by a stated rule and returns the first , which needs or a stated rule for shorter lists. The simplest scoring rule is the popularity baseline, which scores each item by the number of interactions it received in a training period that ends before , so it gives every user the same order.
In plain words A recommender answers one request, for one user at one moment, and its list can only be as good as the candidate set it ranks. Before choosing an algorithm, fix what may be recommended, what feedback exists and what a successful recommendation would mean. Every input to the score, whether a popularity count, a user history or an item description, has to come from before the decision time. Otherwise an offline evaluation grades a system that knew part of the future.
Example A platform offers four learning resources, A, B, C and D. The user has completed A, so the candidate set is . In a constructed training period before the decision time, the four resources were completed 8, 12, 3 and 6 times. The popularity baseline ranks the candidates B, D, C, and it gives this order to every user who has completed A. Resource A was removed before scoring, so its count plays no part in this list.
Explicit and implicit feedback
Definition Explicit feedback is a value a user supplies on purpose to state a preference, such as a rating from 1 to 5 by user for item . Implicit feedback is behavior recorded during use, such as a click, a completion or a purchase, from which a preference is inferred. In both cases only some user-item pairs are observed. Write for the set of pairs with an observed rating or interaction. A pair outside carries no value. It is not a rating of zero and not a recorded dislike. Whether a pair enters depends on the user’s interest and also on exposure, meaning whether, where and how often the item was shown to the user, and exposure depends on the recommendation policy that was running when the data were collected. The resulting distortion of the observed data is called exposure bias.
In plain words A missing rating means that nobody asked or nobody answered. An unclicked resource may never have been seen, may have been seen when the student had no time, or may cover material the student learned elsewhere. Historical clicks therefore record the old system’s choices of what to show as well as the users’ preferences. Implicit-feedback methods often give unobserved pairs a small weight, or compare each observed item with a few sampled unobserved ones, but these are modeling choices, and they do not turn an absence into an observed dislike.
Example Three constructed users rated some of the four resources from 1 to 5, and the blank cells were never rated.
| User | A | B | C | D |
|---|---|---|---|---|
| 1 | 5 | 4 | 1 | |
| 2 | 4 | 2 | 1 | |
| 3 | 1 | 2 | 5 |
Nine of the twelve pairs are in , and a model of explicit ratings is fitted to these nine values only. Filling the three blanks with zeros would add three ratings below the lowest value the scale allows, and a model fitted to them would learn that unrated means disliked. The same caution applies to an implicit log. If a student clicked B, which was shown at the top of a list, and never clicked C, which appeared only on a second page, the log cannot say whether the student would have liked C.
Content-based recommendation and collaborative filtering
Definition Content-based recommendation scores an item for a user by comparing the item’s attributes, such as topic, language, level and format, with a profile of the user’s interests, built from stated preferences or from the attributes of items the user responded to well. Collaborative filtering scores an item for a user from the observed interactions of many users with many items, without using item descriptions. Neighborhood methods predict from the responses of similar users to the same item, or of the same user to similar items, with similarity computed from co-observed interactions. Latent factor models such as matrix factorization learn a vector for each user and each item from the observed interactions. Hybrid systems combine both kinds of information.
In plain words Content-based recommendation asks whether this item resembles what this user likes. Collaborative filtering asks what users with similar records did. Content can score a new item on its first day, but only as well as the descriptions and the chosen similarity allow. Collaborative information can find useful connections that no description mentions, but it uses only interactions that were recorded, so it inherits the exposure patterns, popularity effects and gaps of the process that produced them.
Example Suppose a new resource E covers the same topic at the same level as A, which the user completed and rated well. A content-based score can rank E highly for this user although nobody has used E yet. In the rating table above, users 1 and 2 both rated A well above D, so their correlation over the two resources they both rated is . Users 2 and 3 both rated A and C but in opposite order, so their correlation is . A neighborhood method that weights users by this correlation therefore leans on user 1 when it predicts for user 2, and user 1’s rating of 4 for B becomes evidence that user 2 would rate B well too, without any knowledge of what B contains. With only two co-rated items a correlation can only be or , so these similarities rest on very little evidence.
Matrix factorization
Definition Suppose users and items have observed ratings for the pairs in . Matrix factorization with latent dimension gives each user a vector and each item a vector , and it predicts
where is a global intercept. User and item bias terms and are often added. Stacking the user vectors as the rows of an matrix and the item vectors as the rows of an matrix , the matrix of all scores is with added to every entry. The parameters are fitted to the observed ratings only, for example by minimizing
with a penalty weight chosen on validation data and the intercept left unpenalized. This objective is not jointly convex in and , so gradient methods and alternating least squares can end at different solutions from different starting values. The latent axes are not unique either. For any orthogonal matrix , replacing by and by leaves every score and the penalty unchanged.
In plain words Each user and each item becomes a short list of numbers, and a dot product turns a pair of lists into a score. The model is fitted only where ratings exist, and the penalty keeps a vector small when little evidence supports it. The axes come out of the fit and need not match any named preference. A score is a model output, so it can fall outside the rating scale unless it is clipped or mapped back, and ranking one user’s candidates needs only the order of the scores.
Example Take and , with no bias terms. The user vector and the item vectors , , and are chosen by hand to show the arithmetic, not fitted to data. Each score is , for example , and the four scores are
so the factor model ranks the candidates B, C, D. To see one learning step, use the training rating , recorded when the user completed A, and the single-pair objective
with . The error is , and the gradients are
With step size , and both vectors updated from their old values, the new vectors are and . The prediction for A falls from 5 to about 4.46, closer to the rating 4, and the objective falls from 0.7625 to about 0.326. The new scores of B, C and D are 4.285, 3.99 and 2.4575, still in the order B, C, D. A full fit repeats such steps over the pairs in and never visits the blank cells.
Cold start
Definition Cold start is the situation of a user or an item with too little interaction history for the personalized estimate a model is meant to provide. A new user has no observed ratings or clicks, and a new item has not yet been shown or used. In the factorization objective above with , the vector of an item with no observed ratings appears only in its penalty term, so its minimizing value is , and the item’s score is for every user. In the same way a user without observed ratings gets , and every item then scores for that user, a complete tie. If penalized bias terms and are added, the new item’s score becomes , which contains nothing specific to the item, and the new user’s scores become , the same order for every new user. With such a vector does not affect the objective at all and is not determined by the data.
In plain words A factor vector learned from no evidence says nothing about the user or the item, and the model cannot tell that it knows nothing. Cold-start cases need a stated fallback, such as content-based scores, preferences a new user states when signing up, the training-period popularity order, or a hybrid of these. A report should say which fallback is used and score cold-start cases separately, because an average dominated by established users can hide a failure on new ones.
Example A new user arrives with no history, and the fallback ranks all four resources by training-period popularity, giving B, A, D, C from the counts 12, 8, 6 and 3. For a new resource E with no interactions, the factor score is for everyone, a value that reflects missing evidence rather than any judgment of E, so E’s description is what can place it for a user. Now suppose a constructed evaluation has 90 established users with a mean precision at 2 of 0.6 and 10 new users with a mean of 0.1. The overall mean is
close to the value for established users, while the new users are served poorly.
Precision at k and normalized discounted cumulative gain
Definition Fix a user , a candidate set with at least items, a relevance label for every candidate, and a ranked list whose item at position is . With binary labels, 1 for relevant and 0 for not relevant, let be the number of relevant candidates. The precision at and the recall at are
The discounted cumulative gain at is
and the normalized discounted cumulative gain, NDCG, is . The ideal value is the DCG at of the candidates sorted by decreasing relevance, the largest value any ordering of can reach, so NDCG lies between 0 and 1. If every candidate has relevance 0, then and NDCG is undefined, as is recall, so a report states how such users are handled and how many there are. Ties in the scores are broken by a stated rule, and an average over users states whether every user counts equally. Some definitions use the gain in place of , and the two agree for binary labels.
In plain words Precision at k is the share of the k shown slots filled by relevant items, and recall at k is the share of the relevant candidates that made it into those slots. Both ignore the order inside the top k. When there are more relevant candidates than slots, recall at k cannot reach 1, and when there are fewer, precision at k cannot. NDCG gives each relevant item less credit the lower it appears and compares the total with the best possible order of the same labels. All three numbers depend on the candidate set, the labels and the cutoff, so they are reported with them. Labels taken from logged clicks inherit the exposure of the old system. Evaluation interactions must come after the training cutoff, from a later period when the question is future recommendations for existing users, and from held-out users when the question is new users. A high offline score shows agreement with recorded labels. It is not a causal estimate of what showing the list would do for users, which needs a designed experiment.
Example For the candidates B, C and D, suppose constructed relevance labels mark B and C as relevant and D as not, so , and take . The factor ranking B, C, D has both relevant items in its top two, so . The popularity ranking B, D, C has one, so . The ideal order puts both relevant items first, so
The factor ranking is ideal, with . The popularity ranking has gains 1 and 0, so its DCG at 2 is 1 and
At both lists contain all three candidates, so both have precision and recall 1. Their NDCG values still differ. The popularity ranking reaches only , because its second relevant item sits at position 3 with discount .
Check yourself
- A top-three list has binary relevance labels 1, 0 and 1 in positions 1 to 3, and the user’s candidate set contains four relevant items. Compute the precision at 3, the recall at 3 and the NDCG at 3.
Show the answer
Two of the three slots hold relevant items, so the precision at 3 is . Two of the four relevant candidates were retrieved, so the recall at 3 is . Even a perfect list could reach a recall of only here, since only three of the four relevant items fit.
The gains are 1, 0 and 1, so
Four relevant candidates are available, so the ideal list has relevant items in all three positions, and
The NDCG at 3 is .
- A new resource E is added to the catalog on Monday, and nobody has rated it yet. That night the factorization model of this lesson, without bias terms, is refitted with . What vector does E receive, what score does it get for each user, and what should the system do instead? Does the answer change with ?
Show the answer
No observed pair involves E, so its vector enters the objective only through the penalty term . With that term is smallest at , so the fitted vector is zero and E scores for every user, whatever the user’s history. That score reflects missing evidence, not a judgment of E.
The system should handle E with a stated fallback, for example a content-based score that compares E’s topic, level and format with each user’s profile, and it can move to factor scores or a hybrid once ratings arrive. Results on new items should be reported separately from results on established ones.
With the vector of E does not appear in the objective at all. Every vector gives the same objective value, so the data do not determine it, and gradient training would keep its random starting value, which would give E arbitrary scores that look personalized.
- A recommendation for the user above is made on Monday morning from the candidates B, C and D, and relevance is judged by what the user completes during the following week, which turns out to be B and C. The training-period counts recorded before Monday morning are 12, 3 and 6. A teammate recomputes popularity from all completions through Monday night, which adds 6 completions of C, one of them by this user, and gets 12, 9 and 6. Compare the precision at 2 of the two popularity rankings and say which one the evaluation should report.
Show the answer
The honest counts rank the candidates B, D, C, so the top two contain one relevant item and the precision at 2 is . The recomputed counts rank them B, C, D, so the top two contain both relevant items and the precision at 2 is 1.
The evaluation should report . The recomputed counts use completions recorded after the decision time, including the user’s own completion of C, which is part of the outcome being predicted. The higher score comes from information the system could not have had on Monday morning. Every input, including popularity counts, user histories, item availability and metadata, has to be cut off at the decision time, and the evaluation interactions have to come after it.