How to build a simple recommendation system?
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
A recommendation system suggests items a user is likely to care about, such as movies, books, or products. You do not need a massive production stack to learn the core idea; a small user-item matrix and a similarity measure are enough to build a useful first version.
Pick a Simple Strategy First
There are many recommender approaches, but for a beginner-friendly implementation, item-based collaborative filtering is a good starting point. The basic idea is:
- Collect user ratings
- Represent them as a matrix
- Measure similarity between items
- Recommend items similar to what the user already liked
This avoids training a heavy model and makes the logic easy to inspect.
Prepare the Ratings Data
Suppose you have a table with user_id, item, and rating.
This produces a user-item matrix where each row is a user and each column is an item.
Compute Item Similarity
Once you have the matrix, compute similarity between item columns. Cosine similarity is common because it compares rating patterns rather than raw magnitude.
If Book A and Book C have similar rating patterns across users, their similarity score will be high.
Generate Recommendations for One User
Now recommend items for a target user by looking at what they rated highly and pulling similar items they have not rated yet.
This is a deliberately small implementation, but it demonstrates the core loop used by larger systems: infer preference from similar behavior.
Improve the Baseline
A simple recommender can be useful, but real data is messy. Once the baseline works, typical improvements include:
- Ignore very unpopular items with too little data
- Normalize ratings so generous and strict users are more comparable
- Add content features such as genre, category, or tags
- Separate training data from evaluation data
If you later outgrow pure collaborative filtering, you can move to matrix factorization or hybrid recommenders. The important part is to start with something you can validate.
Evaluating Whether It Works
Do not judge a recommendation system only by whether the code runs. You need an evaluation plan. A common approach is to hide one known user interaction and see whether the system recommends that item back.
For explicit ratings, you can also compute ranking metrics or prediction error. Even a simple offline check is far better than guessing.
In production, you would also measure click-through rate, conversion rate, or watch time depending on the product.
Common Pitfalls
The most common mistake is treating missing ratings as genuine dislike. In most datasets, a missing value means the user never interacted with the item, not that they rejected it.
Another mistake is overfitting to tiny data. If only two users rated an item, a high similarity score may be misleading. Add minimum-support rules before trusting the output.
A third mistake is skipping evaluation. Recommendation systems can produce plausible-looking results that are actually weak. Always test with held-out data or online metrics.
Summary
- A simple recommendation system can be built from a user-item ratings table and cosine similarity.
- Item-based collaborative filtering is easy to understand and implement.
- Start with a pivoted ratings matrix, compute similarities, then rank unseen items.
- Missing ratings should be treated carefully because they are not always negative feedback.
- Validate the system with held-out data before trusting the recommendations.
Related reading
- How to build an image classification dataset in Azure?
- How to build and use Google TensorFlow C api
- How to build hybrid model of Random Forest and Particle Swarm Optimizer to find optimal discount of products?
- How to bulk write TFRecords?
- How to cache data during the first epoch correctly Tensorflow, dataset?
- How to calculate a logistic sigmoid function in Python?
- how to calculate binary search complexity
- How to calculate bubble sort's time complexity

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.