Project 23: Dot-Product Recommendation Engine
A self-contained deep-dive from the canonical Math from Foundations to Machine Learning curriculum.
- Difficulty: Intermediate
- Time: 1-2 weeks
- Language: Python with NumPy and Pandas
- Prerequisites: Projects 12, 16, and 20
- Source:
ML-Found P03
What You Will Build
Build a movie recommender from ratings or explicit movie-feature vectors. Represent users and items in the same vector space, implement dot product, vector norm, cosine similarity, and top-k ranking yourself, and then compare user-user and item-item recommendations. Handle missing ratings deliberately rather than silently treating every absence as dislike. The tool should explain each recommendation by showing the strongest aligned features or the most similar contributing users. Use a small hand-checkable fixture first, then a MovieLens-style dataset. Include popularity and random baselines so a plausible-looking list is not mistaken for proof that the mathematics works.
Real World Outcome
After a user rates a few titles, the CLI returns five unseen movies with similarity scores and explanations such as “recommended because your science-fiction/action vector aligns with users 17 and 42.” An evaluation report compares precision@k or hit rate against baselines and identifies cold-start and sparse-data cases.
Core Question
When does vector alignment represent meaningful preference similarity, and when do magnitude, missing values, or popularity distort the dot product?
Concepts You Must Understand First
- Dot product: multiply aligned components and sum; geometrically it combines magnitudes and angle. See Orland, Math for Programmers, vector chapters.
- Cosine similarity: normalization isolates direction from magnitude. See Manning, Raghavan, and Schütze, Introduction to Information Retrieval, ch. 6.
- Feature vectors: every dimension needs a defined scale and meaning. See Géron, Hands-On Machine Learning, ch. 2.
- Sparse matrices: unobserved ratings are not necessarily zeros; choose overlap and imputation rules explicitly.
- Ranking evaluation: assess only unseen held-out preferences and compare with simple baselines.
Build Milestones
- Implement and test dot product, norm, cosine similarity, and stable top-k selection without library similarity helpers.
- Create a tiny ratings matrix whose expected nearest neighbors and recommendations can be computed by hand.
- Load a real ratings dataset, filter already-seen items, and build user-user and item-item recommenders.
- Add explanations and policies for zero vectors, low overlap, cold-start users, and ties.
- Hold out known ratings and compare recommendation quality with popularity and random baselines.
Hints in Layers
- Validate the math on three users and five movies before loading a large dataset.
- Compute similarity only on co-rated dimensions or document a centered/imputed alternative; require a minimum overlap.
- To explain a score, retain per-neighbor or per-feature contributions before summing them.
Common Pitfalls and Debugging
- Symptom: prolific raters appear similar to everyone. Cause: raw dot products reward magnitude. Fix: compare cosine similarity and mean-centered ratings.
- Symptom: already watched movies dominate results. Cause: seen items were not masked. Fix: exclude them before top-k selection.
- Symptom: offline accuracy looks perfect. Cause: evaluation used training ratings. Fix: create a user-stratified holdout before computing recommendations.
Definition of Done
- Core vector operations match hand calculations and NumPy references.
- Recommendations exclude rated items and are deterministic under a fixed seed.
- Missing values, low overlap, ties, and zero norms have explicit policies.
- Every result includes a human-readable contribution explanation.
- Held-out ranking quality beats at least one baseline.
- The report names limitations including sparsity, popularity bias, and cold start.
Navigation
Previous: Project 22 · Complete learning path · Next: Project 24