Recommender Systems
Explore practical ways to rank movies or products using popularity, content, user-item interactions, matrix factorization, and retrieval—then evaluate what users actually see.
A recommender does not merely predict a rating; it ranks a small set of items that may be useful to a particular person now.
A movie service may have thousands of titles, while a shopper sees only a handful of product cards. The system must select candidates, rank them for a user and context, and balance relevance with freshness, availability, diversity, and business constraints. This lesson builds a movie and e-commerce example from simple baselines to modern retrieval ideas.
The data is usually sparse: a user interacts with only a tiny fraction of the catalogue. A missing interaction does not mean a user disliked an item. A movie may never have been shown; a product may have been out of stock; a user may have watched without rating. Understanding the meaning and collection process of feedback is as important as choosing the algorithm.
Popularity is simple, measurable, and a safe fallback for users without history.
Rank movies by recent watch or positive-rating count, or products by purchases and qualified engagement. Global popularity offers a baseline for new users and an operational fallback when a personalized model is unavailable. Raw counts favor items with more exposure, so consider recency, exposure, category, availability, and smoothing when comparing items with very different traffic.
A practical e-commerce baseline can rank currently available products by recent purchase rate within a category. Filtering by inventory and policy before ranking avoids recommending an item that cannot be purchased. For a movie example, trending titles can be presented as one shelf alongside personalized shelves rather than pretending that every user has known preferences.
A popularity ranking must be computed using training-period data, not the held-out interactions later used for evaluation. If popularity is time-sensitive, calculate it using the history available at each evaluation point. Otherwise the baseline itself can leak future success.
Content-based systems recommend items similar to what a user has engaged with.
Represent items using attributes: movie genres, cast, language, release year, and text descriptions; or product category, brand, material, price band, and image/text embeddings. Build a user profile from the weighted combination of item representations they liked or purchased, then rank candidate items by similarity to that profile. This approach can recommend a new item if its content is available, even before it has many interactions.
For numeric or vector features, cosine similarity is a common score when vector direction matters more than magnitude. For sparse categorical metadata, use a suitable encoding and weighting such as TF-IDF for text. Ensure feature scaling and representation choices do not let an arbitrary field dominate. Exclude items the user should not see, such as already-consumed titles if the product experience calls for discovery.
Content-based recommendations can become narrow: the model repeatedly shows close variations of what the user already consumed. Add diversity and exploration carefully, measure their effect, and make the recommendation rationale understandable where it helps users make a choice.
Collaborative filtering learns from patterns of co-interest across users and items.
If users who watched the same dramas also watched a particular new series, that pattern can support a recommendation without relying on genre metadata. User-user methods find users with similar histories; item-item methods find items that attract similar users. Neighborhood approaches are easy to explain and can be strong baselines, but similarity becomes costly or noisy with many users and sparse observations.
Collaborative signals can discover relationships that metadata misses, but a new user or new item has no interaction history. Moreover, exposure shapes the data: users can only click items they were shown. A click is not an unbiased measure of preference, and a non-click may mean the item was never noticed. Logging impressions and position, not only clicks, improves analysis of these selection effects.
Explicit ratings and implicit events are different problems
Explicit feedback—such as a star rating—directly states a preference on a scale, though only a selected subset of users supplies it. Implicit feedback includes views, dwell time, saves, add-to-cart events, purchases, skips, and dislikes. An implicit event indicates some interaction, but the strength and meaning differ: a purchase is not equivalent to a brief impression. Weight events according to product meaning and consider negative signals separately.
Factorization compresses interaction patterns into compact user and item embeddings.
For explicit ratings, a common latent-factor model approximates a rating as a global mean plus user and item biases and the dot product of user and item vectors. The vectors are learned so observed ratings are predicted well, usually with regularization to discourage extreme parameter values. A dot product gives a score; it is not automatically a calibrated probability that a user will enjoy the item.
For implicit feedback, objectives often distinguish observed positive interactions from unobserved pairs and weight confidence rather than treating every absence as a verified dislike. Approaches include confidence-weighted factorization and sampled ranking losses. The appropriate method depends on whether the objective is to predict ratings, retrieve likely interactions, or optimize a ranked list.
Sparse data structures matter
A dense user-by-item matrix is usually wasteful: nearly every cell is empty. Store only observed interactions in a sparse representation or interaction table, and map external IDs to contiguous model indices. Keep that mapping with the model so training indices cannot be confused with production identifiers. Cold users and items need explicit fallback paths rather than invalid embedding lookups.
Two-tower models encode users and items separately so candidate retrieval can scale.
A user tower maps user history and context to an embedding. An item tower maps item features to an embedding in a compatible space. The dot product or another similarity score ranks compatibility. Because item embeddings can be computed and indexed ahead of time, approximate nearest-neighbor search can retrieve a manageable candidate set from a large catalogue. A separate ranking model can then use richer, candidate-specific features to order those candidates.
Training examples pair users and positive items with sampled or otherwise defined negatives. The sampling procedure shapes what the model learns: random negatives may be too easy, while in-batch or hard negatives can introduce their own biases. If the two towers use only independent features, the retrieval score must be computable from their separately produced embeddings. Features requiring a joint interaction are more naturally used in the ranking stage.
This retrieval-plus-ranking pattern separates scale from fine-grained decisions. It also creates multiple evaluation questions: did retrieval include relevant candidates, did ranking put them near the top, and did the final policy respect availability, safety, and diversity constraints? A strong ranker cannot recover a relevant item that retrieval omitted.
New users and new items need a deliberate experience before collaborative history exists.
User cold start: use popularity, onboarding preferences, session context, or a small number of explicitly chosen interests. Do not demand unnecessary personal information; let users skip personalization and provide controls to revise preferences. Item cold start: use content features, editorial metadata, or a controlled exploration policy to learn whether new items resonate. System cold start: use a robust popular or curated shelf while interaction logs are sparse.
Cold-start fallbacks should preserve eligibility, privacy, and user expectations. A new product still needs inventory and policy checks. A new movie may be surfaced to a relevant cohort based on content before enough ratings accumulate. The system should not infer sensitive traits from weak behavioral evidence just to make a ranking appear personalized.
Feedback loops and exposure bias
Recommendations influence what users see, and what users see determines which interactions are observed. If the system only shows historically popular products, it may collect more interactions on those products and reinforce the original popularity advantage. Track impressions and position, preserve a safe amount of exploration where appropriate, and evaluate changes using online experiments or other causal methods when suitable. Offline metrics alone do not prove that a new ranking improves user outcomes.
Precision@k, Recall@k, and NDCG answer different questions about the first k recommendations.
Precision@k is the fraction of the top-k recommendations that are relevant. It asks how many displayed items are useful. Recall@k is the fraction of relevant held-out items that appear in the top k. It asks how much of a user's relevant set was retrieved. They depend on the definition of relevant, the candidate set, and the number of held-out positives.
Discounted cumulative gain gives more credit to relevant items near the top; NDCG@k normalizes that gain against an ideal ordering. For graded feedback, relevance can have multiple levels, but mapping ratings or events to gains must be stated. A system with high offline recall may still have poor top-position quality; NDCG captures ranking position more directly.
Use a time-aware or otherwise deployment-aligned split. Avoid placing the same event in both train and test, and ensure the item universe and candidate generation match the evaluation claim. Report metrics across user cohorts, item age, popularity bands, and relevant business slices. Measure coverage and diversity alongside relevance when those properties matter to the product.
A technically accurate ranking still needs product constraints, monitoring, and user trust.
Filter candidates for availability, regional eligibility, content policy, and items already consumed when appropriate. Apply business rules transparently and do not let sponsored placement masquerade as organic relevance. Consider diversity, novelty, and repeated exposure so a ranking does not fill every slot with near-duplicates. Keep a fallback when user history or an embedding lookup is unavailable.
Monitor input freshness, recommendation coverage, catalog changes, latency, error rates, and outcome metrics. Store model version and ranking context for diagnosis while respecting data minimization and retention policies. Provide a clear way to dismiss or tune recommendations where appropriate. A recommender is part of a user-facing decision system, not just an embedding model.
Evaluate models with metrics that match the decision, not just a single accuracy score.
Next, study evaluation metrics across classification and ranking. Build a careful measurement protocol, understand the limits of each score, and interpret performance in the context of users, candidates, and deployment.
Choose metrics and validation protocols that answer the right question.
🎯 Key Takeaways
- ✓Popularity is a valuable baseline and cold-start fallback; compute it from training history and apply eligibility filters.
- ✓Content-based methods use item attributes and user profiles; collaborative filtering discovers patterns across interactions but is affected by sparse, exposure-biased data.
- ✓Explicit ratings and implicit events carry different meanings. Missing interactions are not automatically negative feedback.
- ✓Matrix factorization learns compact user and item factors; two-tower models support scalable retrieval before a richer ranking stage.
- ✓New users and items need explicit cold-start paths. Use content, context, onboarding choices, popularity, or controlled exploration with user-respecting defaults.
- ✓Precision@k measures relevant items among those shown; Recall@k measures relevant items retrieved; NDCG@k rewards higher-ranked relevant results.
- ✓Document relevance, candidate generation, time split, k, and aggregation. Offline metrics do not alone establish product impact.
- ✓Filter for availability and policy, monitor feedback loops and coverage, and preserve user trust with sensible controls and privacy-aware data handling.
HELP US IMPROVE
How was this lesson?
Your note is shared with the Chaduvuko team for review. Please don’t include personal or sensitive information.
Spotted a mistake or something unclear? Suggest a fix on GitHub or email us. Select the text first and it is quoted for you.
Discussion
0Have a better approach? Found something outdated? Share it — your knowledge helps everyone learning here.
