Bayesian Popularity
GLOBAL · SHRINKAGE · COLD STARTShrink item means toward the global mean according to evidence count.
Select Run recommender SQL.
PURE SQL RECOMMENDER SYSTEMS · NO PYTHON
A recommender connects evidence about users, items, time and context. SQL can construct those relationships directly: self-joins create graphs, aggregates learn statistics, windows rank candidates, and CTEs preserve the reasoning path.
SEVEN LIVE METHODS
User 1 has rated Space Odyssey = 5, Robot City = 4 and Quiet Letters = 1. Every method ranks the same three unseen candidates, so students can compare evidence rather than datasets.
Shrink item means toward the global mean according to evidence count.
Select Run recommender SQL.
Modernizes the original KeyValue and probview flow into a positive-interaction graph.
Select Run recommender SQL.
Learns adjusted-cosine item similarity from co-rating users.
Select Run recommender SQL.
Finds similar users on overlapping items and aggregates neighbor deviations.
Select Run recommender SQL.
Builds a rating-weighted genre profile and scores candidates with cosine similarity.
Select Run recommender SQL.
Applies exponential decay when taste or inventory changes over time.
Select Run recommender SQL.
Combines normalized popularity and content ranks with transparent weights.
Select Run recommender SQL.
SHARED TEACHING DATA
The dataset is intentionally tiny. A student should be able to trace one recommendation back through every join and aggregate before scaling the pattern to retail events or MovieLens.
| User | Item | Rating |
|---|---|---|
| 1 | 1 | 5 |
| 1 | 2 | 4 |
| 1 | 3 | 1 |
| 2 | 1 | 4 |
| 2 | 2 | 5 |
| 2 | 4 | 1 |
| 3 | 3 | 5 |
| 3 | 4 | 4 |
| 3 | 5 | 4 |
| 4 | 1 | 2 |
| 4 | 3 | 4 |
| 4 | 5 | 5 |
| 5 | 2 | 4 |
| 5 | 4 | 5 |
| 5 | 6 | 4 |
| Item | Title | Content features |
|---|---|---|
| 1 | Space Odyssey | sci-fi, drama |
| 2 | Robot City | sci-fi, action |
| 3 | Quiet Letters | drama |
| 4 | Fast Track | action |
| 5 | Family Table | drama, comedy |
| 6 | Cosmic Joke | sci-fi, comedy |
The supplied retail SQL first reduces transactions to unique CustomerID–StockCode pairs. A self-join counts co-occurring products; item occurrence converts counts to conditional probabilities; the target customer’s owned products activate outgoing edges, and unseen destinations are ranked by summed probability.
The graph is explainable: every recommendation has a path from something the customer already selected.
Explicit positive-event policy, evidence count, modern CTEs, alternative models and ranking evaluation.
SYSTEM ARCHITECTURE
A useful list also needs eligibility, deduplication, inventory or policy constraints, diversity, exploration and logging. Leaving these out creates a model demo—not a recommender system.
EVALUATION & RESPONSIBILITY
Therefore evaluation must include ranking quality, system behavior and human consequences. High click-through can coexist with low diversity, fatigue or unfair exposure.
Precision@K · Recall@K · MAP · NDCG · MRR
Coverage · diversity · novelty · serendipity · popularity concentration
CTR · conversion · revenue · retention · hide/dismiss rate
Exposure fairness · frequency caps · safety · inventory · latency
CONTINUE
Connect this lesson to Pure SQL ML, Declarative ML and Data Systems Labs.