Contents — 26 sections
Project Overview
Personalizes content and products with collaborative filtering — "people like you liked this" — the engine behind modern discovery.
Recommendation engines quietly shape a huge part of digital life — the films suggested, the products shown, the posts surfaced — by predicting what each person will like from the behaviour of many. This project builds one using collaborative filtering, the classic and powerful idea behind most recommenders: "people who liked what you liked also liked this". It personalizes content or products by learning patterns across users' interactions, without needing to understand the items themselves.
The core insight of collaborative filtering is that you can recommend well using only the matrix of user–item interactions (ratings, clicks, purchases) — no knowledge of what the items are. If your tastes overlap strongly with another user's, things they liked that you haven't seen are good recommendations for you. Modern versions use matrix factorisation: decompose the sparse interaction matrix into latent factors — compact vectors for each user and item — such that a user's predicted preference for an item is their vectors' similarity. These learned factors capture hidden taste dimensions (a "sci-fi-ness", an "arthouse-ness") automatically, purely from behaviour.
The value is personalization at scale — better discovery, engagement and sales. It is honest about the well-known hard problems every recommender faces: the cold-start problem (you cannot collaboratively recommend to a brand-new user or a brand-new item with no interactions), sparsity (most users rate very few items), popularity bias (popular items get over-recommended, the long tail ignored), and the societal concerns of filter bubbles and echo chambers (over-personalization narrows what people see). It is also honest that engagement is not the same as genuine value, and recommenders can optimise for the wrong thing. Built with matrix-factorisation collaborative filtering and clear eyes about cold-start, bias and filter bubbles, it is both a genuinely useful personalization engine and the definitive lesson in the recommender systems that shape what billions of people see.
What this project does
- Recommends items personalized to each user
- Uses collaborative filtering ("people like you liked…")
- Learns from the user–item interaction matrix only
- Uses matrix factorisation into latent factors
- Captures hidden taste dimensions from behaviour
- Powers discovery for content and products
- Handles cold-start and bias thoughtfully
Real-World Applications
| Setting | How it is used |
|---|---|
| Content recommendation | Films, shows, music, articles. |
| Product recommendation | E-commerce personalization. |
| Discovery / feeds | Surfacing relevant items. |
| Recommender-systems learning | Collaborative filtering done right. |
Deployment contexts where a build of this kind earns its keep.
Features & Capabilities
- Collaborative filtering recommendations
- Matrix factorisation (latent factors)
- Interaction-only (no item understanding needed)
- Top-N personalized recommendations
- Cold-start handling (hybrid fallback)
- Popularity-bias and diversity awareness
- Honest about filter bubbles and engagement traps
Difficulty, Time & Required Skills
| Attribute | Value |
|---|---|
| Difficulty level | Intermediate |
| Estimated completion time | 12–18 hours |
| Indicative build cost | Software; compute-light to moderate |
| Primary discipline | Predictive ML |
| Reference platform | CPU/GPU workstation or server |
Skills you should have (or will pick up)
- Collaborative filtering and matrix factorisation
- Latent-factor modelling
- Top-N recommendation and evaluation
- Cold-start and hybrid approaches
- Bias, diversity and filter-bubble awareness
Bill of Materials
Every part below is commonly available from Indian and international hobby-electronics suppliers. Prices are indicative 2026 retail figures in Indian rupees and will drift — treat them as a budgeting guide, not a quotation.
| Component | Key specification | Qty | Approx. cost |
|---|---|---|---|
| Compute | CPU/GPU for factorisation/training | 1 | — |
| Recommender libraries | Matrix factorisation / collaborative filtering | 1 | — |
| Interaction data The core signal | User–item ratings/clicks/purchases | 1 | — |
| Item metadata (for cold-start) Hybrid fallback | Content features for new items/users | 1 | — |
Estimated total: ₹0, excluding tools, shipping and consumables.
Tools and consumables
- Soldering iron (temperature controlled, 350 °C) with 0.8 mm 60/40 or lead-free solder
- Digital multimeter — continuity, DC volts and current ranges
- Wire strippers, flush cutters and a small set of precision screwdrivers
- Heat-shrink tubing and a heat gun (or a lighter, carefully)
- A laptop with a USB port and the toolchain listed above
Hardware Specifications
This is a pure-software recommender system — no electronic hardware to specify. The "platform" is a computer: a CPU handles matrix factorisation for moderate catalogues; a GPU accelerates large-scale training.
Memory scales with the number of users × items and factor dimensions; storage holds the interaction matrix and learned factors. A deployment adds an interaction log, a serving layer for top-N recommendations, and metadata for cold-start. Everything else is the software stack, models and libraries below.
Software Requirements & Development Environment
Reference toolchain: Python 3.11 + recommender ML. Anything newer normally works; anything older may lack the board definitions used here.
- Install the Arduino IDE 2.3.x (or PlatformIO if you prefer a real editor and dependency locking).
- Add
https://espressif.github.io/arduino-esp32/package_esp32_index.jsonunder File → Preferences → Additional Board Manager URLs, then install esp32 from the Boards Manager. - Set the correct port under Tools → Port. On Linux add yourself to the
dialoutgroup:sudo usermod -aG dialout $USERand log out and back in. - Open the Serial Monitor at 115200 baud — every sketch here logs its state there.
- Keep File → Preferences → Show verbose output during: compilation switched on while you are debugging build errors.
Required libraries
| Library | Why it is needed | Install |
|---|---|---|
| Python 3.11+ | Runtime for the analysis, training and service code. | sudo apt install python3 python3-venv python3-pip |
| NumPy 1.26+ | Vectorised array maths underpinning every other library here. | pip install numpy |
| pandas 2.2+ | Tabular data loading, cleaning and time-series resampling. | pip install pandas |
| scikit-learn 1.5+ | Classical models, preprocessing pipelines and evaluation metrics. | pip install scikit-learn |
Block Diagram
The block diagram shows the functional decomposition of the system — what senses, what decides, what acts, and where the data ends up.
Circuit Diagram & Wiring
The "wiring" is the recommendation data flow — the user–item interaction matrix is factorised into latent vectors; a user's vector scored against item vectors yields personalized top-N recommendations.
| Peripheral | Peripheral pin | Controller pin | Signal |
|---|---|---|---|
| Interactions | user×item | — | Ratings/clicks |
| Matrix factorisation | learn | — | Latent vectors |
| Score | user·item | — | Predicted preference |
| Top-N | recommend | — | Personalized list |
Wire one row at a time and tick it off — most "it does not work" reports trace back to a single swapped pair.
Wiring explanation
- Collect the user–item interaction matrix (ratings/clicks/purchases).
- Factorise it into latent user and item vectors.
- Score a user against items by vector similarity for predicted preference.
- Recommend the top-N unseen items; handle cold-start with a hybrid fallback.
- Watch popularity bias and diversity — do not just recommend the popular.
System Architecture
Read the stack from the bottom up: physical hardware, the firmware that drives it, the transport that moves data off the device, and the software a human actually looks at.
Working Principle
The elegant, almost surprising idea at the heart of collaborative filtering is that you can recommend things well without understanding them at all. You do not need to know that a film is a sci-fi thriller or that a product is a running shoe; you only need the matrix of who interacted with what — ratings, clicks, purchases. The core principle is "people who agreed with you in the past will agree with you in the future": if your tastes overlap strongly with another user's, the items they liked that you haven't seen are excellent recommendations for you. This behaviour-only approach is what made recommenders scale to millions of items no human could catalogue.
Naïve collaborative filtering (find similar users, average their likes) struggles with scale and sparsity, so modern recommenders use matrix factorisation. The insight is to approximate the huge, mostly-empty user–item matrix as the product of two smaller matrices of latent factors — a short vector for each user and each item — chosen so that a user's known interactions are reconstructed by the dot product of their vector with the item vectors. Once learned, a user's predicted preference for any item is just that similarity, so you can score every unseen item and recommend the top ones. Remarkably, the learned latent factors discover hidden taste dimensions on their own — one factor might implicitly capture "action-vs-arthouse", another "mainstream-vs-niche" — purely from interaction patterns, never told what the items are. That automatic discovery of taste structure is the beautiful part.
The genuine value is personalization at scale: every user gets recommendations tuned to their revealed tastes, which powers discovery, engagement and sales across content and commerce. But every recommender runs into a set of well-known, unavoidable problems that this project must confront honestly. The most famous is cold-start: collaborative filtering needs interactions, so it cannot recommend to a brand-new user (no history) or a brand-new item (no one has interacted with it) — the matrix has no signal there. The standard remedy is a hybrid approach: fall back on content features or popularity until enough interactions accumulate. Sparsity (most users interact with a tiny fraction of items) makes learning hard, and popularity bias pushes recommenders to over-recommend already-popular items while the long tail goes unseen — often the opposite of the useful discovery you want.
The deepest honesty is societal. Because recommenders shape what billions of people see, over-personalization creates filter bubbles and echo chambers: if the system only ever shows you more of what you already engaged with, it narrows your exposure, can entrench views, and reduces serendipity — a real, documented concern, not a hypothetical. Relatedly, recommenders are usually optimised for engagement (clicks, watch-time), and engagement is not the same as genuine value or wellbeing — a system can learn to recommend the most addictive or outrage-provoking content rather than the most valuable, so what you optimise for is an ethical choice. A responsible recommender therefore balances accuracy with diversity and serendipity, handles cold-start gracefully, is mindful of popularity bias, and is thoughtful about its objective. Built with matrix-factorisation collaborative filtering and clear eyes about cold-start, sparsity, bias, filter bubbles and the engagement trap, the engine delivers real personalization value while teaching both the elegant mechanics and the serious responsibilities of the systems that increasingly decide what people see.
The maths behind it
Collaborative filtering (the idea)
Use ONLY the user–item interaction matrix R (ratings/clicks).
"users who agreed before will agree again"
→ recommend items liked by users similar to you.
No understanding of the items needed.
Matrix factorisation
R ≈ U · Vᵀ (learn latent vectors)
u_user (k-dim), v_item (k-dim)
predicted preference = u_user · v_item
Latent factors auto-discover hidden taste dimensions.
The hard problems (be honest)
cold-start: new user/item has NO interactions → CF can't
→ hybrid: use content/popularity until data accrues
popularity bias: popular over-recommended; long tail ignored
filter bubbles: over-personalization narrows exposure
engagement ≠ value: optimise the right objective.
Program Flowchart
The firmware is a single cooperative loop. Nothing blocks for long, so networking, sensing and the user interface all stay responsive.
Assembly Instructions
Build on a breadboard first and only commit to solder once the whole system has run for an hour without a fault.
Build the interaction matrix and factorise
Assemble the user–item interaction matrix and learn latent user/item vectors by matrix factorisation.
Score and recommend top-N
Score a user against unseen items by vector similarity and recommend the top-N, re-ranking for diversity.
Handle cold-start and bias
Fall back on content/popularity for new users/items, and guard against popularity bias and filter bubbles.
Step-by-Step Implementation Guide
Work through these in order. Each step ends in something you can observe, so a failure is always localised to the step you just finished.
Recommend from latent factors with cold-start fallback
Score a user's latent vector against item vectors for top-N, falling back to a hybrid approach on cold-start and diversifying.
pythonrecommend.pyimport numpy as np def recommend(user_id, U, V, seen, k=10): if user_id not in U: # COLD-START (no interactions) return popular_or_content_based(k) # hybrid fallback scores = V @ U[user_id] # predicted preference = dot product ranked = [i for i in np.argsort(-scores) if i not in seen] # unseen items return diversify(ranked[:k]) # counter popularity bias/bubblesif user_id not in U: # COLD-START (no interactions)A brand-new user has no latent factors, so collaborative filtering cannot help — the cold-start problem, handled by a hybrid fallback.scores = V @ U[user_id] # predicted preference = dot productPredicted preference is the similarity between the user's and each item's latent vector — the core of matrix factorisation.ranked = [i for i in np.argsort(-scores) if i not in seen] # unseen itemsRecommendations are the highest-scoring items the user has not already seen.return diversify(ranked[:k]) # counter popularity bias/bubblesRe-ranking for diversity guards against popularity bias and filter bubbles rather than only chasing accuracy.Balance accuracy, diversity and objective
Tune for top-N quality while adding diversity/serendipity, and be deliberate about optimising for genuine value rather than raw engagement.
Complete Source Code
The listing below is complete and compiles as written — there are no elided sections. Read the annotations under each block before you upload it.
#!/usr/bin/env python3
"""
Recommendation Engine (collaborative filtering)
Personalizes items via collaborative filtering — "people who liked what
you liked also liked this" — using MATRIX FACTORISATION over the
user–item interaction matrix (no item understanding needed). Handles
COLD-START (hybrid fallback) and is mindful of popularity bias, filter
bubbles, and that engagement != genuine value.
"""
import numpy as np
class Recommender:
def __init__(self, k=50, reg=0.05):
self.k = k; self.reg = reg
self.U = {}; self.V = None
def fit(self, interactions):
# learn latent user (U) and item (V) vectors s.t. U·Vᵀ ≈ interactions
self.U, self.V = matrix_factorise(interactions, self.k, self.reg)
def recommend(self, user_id, seen, n=10):
if user_id not in self.U: # COLD-START: no factors
return self._hybrid_fallback(n) # content/popularity
scores = self.V @ self.U[user_id] # predicted preference
ranked = [i for i in np.argsort(-scores) if i not in seen]
return self._diversify(ranked[:n * 3])[:n] # counter bias/bubbles
def _hybrid_fallback(self, n):
return popular_or_content_based(n) # until interactions accrue
def _diversify(self, items):
return rerank_for_diversity(items) # serendipity, long tail
if __name__ == "__main__":
rec = Recommender(k=50)
rec.fit(INTERACTIONS) # only user–item interactions
print(rec.recommend(user_id="u123", seen=SEEN["u123"], n=10))
# Mind cold-start/sparsity/popularity bias/filter bubbles; engagement != value.
Configuration & Calibration
Configuration steps
- Configure the interaction matrix (explicit/implicit feedback).
- Configure factorisation (latent dimension, regularisation).
- Configure top-N, diversity re-ranking and cold-start fallback.
- Configure the optimisation objective (value vs raw engagement).
Calibration procedure
An uncalibrated sensor produces confident, precise, wrong numbers. Do this once per physical unit and record the constants.
Factorisation
Tune latent dimension and regularisation for sparse data; evaluate top-N.
Cold-start
Verify graceful hybrid fallback for new users/items.
Diversity/bias
Measure coverage/diversity; counter popularity bias and filter bubbles.
Dataset, Model & Training
Dataset
The user–item interaction matrix (ratings/clicks/purchases) is the core signal; item/user metadata helps cold-start (hybrid).
Sparsity and popularity distribution in the data shape difficulty and bias.
| Dataset | Size | Licence | Use here |
|---|---|---|---|
| User–item interactions | Large, sparse | Yours (privacy) | Collaborative filtering signal |
| Item metadata | Per item | Yours | Cold-start / hybrid |
| User profiles (optional) | Per user | Consented | Cold-start for new users |
| Held-out interactions | — | — | Evaluate recommendations |
Data preprocessing
- Build the sparse interaction matrix; handle implicit vs explicit feedback.
- Split for evaluation (leave-some-out per user).
- Prepare metadata for cold-start fallback.
| Layer / stage | Shape or configuration | Purpose |
|---|---|---|
| Interaction matrix | users × items (sparse) | The only required signal |
| Matrix factorisation | latent user/item vectors | Learn taste from behaviour |
| Scorer | dot product | Predicted preference |
| Cold-start | hybrid (content/popularity) | New users/items |
| Diversity | re-ranking | Counter popularity bias/bubbles |
Hyperparameters
| Hyperparameter | Value | Why |
|---|---|---|
| Latent factors (k) | ≈ 20–200 | Capacity vs overfit |
| Regularisation | tuned | Sparse-data overfit |
| Top-N | app-specific | List length |
| Diversity weight | tuned | Accuracy vs serendipity |
Training process
- Learn latent factors from the interaction matrix (with regularisation for sparsity).
- Add a hybrid fallback for cold-start; re-rank for diversity.
- Evaluate top-N with held-out interactions (precision@k/recall@k), not just RMSE.
Evaluation, Metrics & Deployment
Ranking metrics (precision@k, recall@k, NDCG) matter more than rating error, alongside coverage/diversity to guard against popularity bias and bubbles.
| Metric | Value | What it tells you |
|---|---|---|
| Precision@k / NDCG | primary | Top-N recommendation quality |
| Coverage / diversity | watch | Long tail vs popularity bias |
| Cold-start handling | graceful | New users/items |
| Objective | value ≥ engagement | Optimise the right thing |
Figures from the reference training run described above — reproduce them before trusting your own changes.
Inference example
import numpy as np
def recommend(user_id, U, V, seen, k=10):
if user_id not in U: # COLD-START: no factors yet
return popular_or_content_based(k) # hybrid fallback
scores = V @ U[user_id] # predicted preference (dot product)
ranked = np.argsort(-scores)
recs = [i for i in ranked if i not in seen][:k] # unseen items
return diversify(recs) # counter popularity bias/bubbles
# CF uses only interactions; mind cold-start, bias, filter bubbles, and
# that engagement != genuine value.
Testing Procedure & Expected Output
Test from the bottom up. Confirm power, then each sensor in isolation, then the integrated loop — the first failing step tells you exactly where to look.
| Test | What you should see |
|---|---|
| Recommend for an active user | Relevant, personalized top-N |
| New user (cold-start) | Hybrid/popular fallback (CF can't) |
| New item (cold-start) | Surfaced via hybrid, not CF |
| Check recommendation coverage | Not only popular items (bias check) |
| Assess diversity | Some serendipity, not an echo chamber |
| Evaluate with ranking metrics | Precision@k/NDCG, not just RMSE |
Bench-test checklist. If a row fails, stop and fix it before moving on.
Expected output
Personalized top-N recommendations with cold-start handling and diversity, evaluated by ranking metrics.
{
"user": "u123",
"recommendations": ["item_88", "item_12", "item_204"],
"method": "collaborative filtering (matrix factorisation)",
"cold_start": false,
"diversity_reranked": true,
"note": "mind popularity bias, filter bubbles; engagement != value"
}
Personalized recommendations from learned latent factors, diversity-reranked — useful discovery, produced with awareness of popularity bias and filter bubbles rather than blindly maximising engagement.
Troubleshooting: Common Errors & Fixes
Performance Optimisation
- Learn latent factors from interactions; regularise for sparsity.
- Handle cold-start with a hybrid fallback.
- Re-rank for diversity to counter popularity bias/bubbles.
- Evaluate top-N with ranking metrics and coverage.
- Replace every
delay()with amillis()comparison — blocking delays are the single most common cause of dropped readings. - Sample sensors on a fixed cadence and publish on a slower one; you almost never need to transmit at the sampling rate.
- Move networking into its own FreeRTOS task so a slow DNS lookup cannot stall the control loop.
- Use
uint8_t/uint16_twhere the range allows; on an 8-bit AVR a 32-bit add costs four times as much. - Profile before optimising — print
micros()deltas around each stage and fix the slowest one first.
Safety Precautions
- Beware filter bubbles and echo chambers — over-personalization narrows what people see.
- Engagement is not genuine value — be deliberate about the optimisation objective.
- Interaction data is personal — secure and handle it lawfully with privacy in mind.
- Guard against popularity bias that buries the long tail.
- Wear eye protection when soldering or cutting, and solder in a ventilated space — rosin flux fumes are a respiratory irritant.
- Power the circuit through a bench supply with a current limit while you are testing. A 300 mA limit turns a wiring mistake into a beep instead of a dead board.
- Disconnect power before changing any wiring. Hot-plugging a sensor onto a live bus is the fastest way to lose a controller.
Maintenance
- Retrain as interactions grow and tastes shift.
- Monitor diversity/coverage and cold-start behaviour.
- Re-evaluate the objective for value vs engagement.
- Audit for bias and privacy.
- Re-check every screw terminal and header after the first week — thermal cycling loosens connections that felt tight on day one.
- Recalibrate at the interval given in the calibration section, and keep the constants in a text file next to the firmware — not only in flash.
- Keep a short logbook of firmware versions and what changed. Six months later you will not remember why that constant is 1.083.
Future Improvements & Upgrades
A working v1 is a platform, not a finish line. These are the upgrades that add the most capability for the least rework.
- Add hybrid content+collaborative models.
- Add sequence/session-based recommendation.
- Add explainable recommendations ("because you liked…").
- Add fairness/diversity objectives explicitly.
- Design a proper PCB. Once the breadboard version has run for a month, moving to a two-layer board removes the intermittent-contact failures that dominate prototype faults.
- Add connectivity — an ESP32 and an MQTT publish turn a local gadget into something you can graph, alert on and analyse over months.
- Add persistent local storage (microSD or the on-chip flash) so a network outage does not create a hole in your data.
- Move configuration out of the source: a captive-portal setup page or a JSON config file makes the build reusable without a recompile.
- Add a battery and solar option so the unit survives a power cut and can be sited away from a socket.
- Write a small test harness that feeds synthetic sensor values through the decision logic, so you can validate thresholds without physically triggering the event.
Frequently Asked Questions
References & Learning Resources
These are the primary sources worth reading in full. Manufacturer datasheets always outrank forum posts when the two disagree.
- Recommender systemReference
- Collaborative filteringReference
- Matrix factorization (recommenders)Reference
- Cold start problemReference
- Filter bubbleReference