Prepare the rating matrix
Collect user-item ratings and pivot into a dense matrix with missing entries handled (the starter fills missing ratings with zeros).
Movie recommendation system. Recommend items from neighbours.
User-based collaborative filtering recommends items by finding similar users and returning items those neighbours liked. The method depends on a user-item rating matrix, a similarity measure (here cosine similarity) and a neighbour scoring rule. Real-world issues include sparse data, popularity bias, cold-start users and the need for offline metrics such as Precision@K or NDCG.
Learning concept · Not a validated service
User-based collaborative filtering recommends items by finding similar users and returning items those neighbours liked. The method depends on a user-item rating matrix, a similarity measure (here cosine similarity) and a neighbour scoring rule. Real-world issues include sparse data, popularity bias, cold-start users and the need for offline metrics such as Precision@K or NDCG.
A proposed extension for a small streaming catalogue: surface personalised suggestions to help users rediscover titles while keeping a human reviewer in the loop for edge cases and business rules. The supplied starter does not include production serving, metadata integration or evaluation at scale.
Collect user-item ratings and pivot into a dense matrix with missing entries handled (the starter fills missing ratings with zeros).
Use a similarity metric such as cosine similarity on user vectors to find nearest neighbours for a given user.
For a target user, aggregate neighbour ratings on items the user has not seen and sort to produce recommendations.
Measure ranking metrics (Precision@K, Recall@K, NDCG) on holdout data and add business rules, diversity and fallback logic before deployment.
The supplied starter constructs a small hand-written user-item ratings DataFrame, pivots it into a user-by-item rating matrix, computes cosine similarity between users, selects the most similar neighbour for a target user and recommends that neighbour's highest-rated unseen items.
matrix = ratings.pivot_table(index="user", columns="item", values="rating").fillna(0)
user_similarity = pd.DataFrame(
cosine_similarity(matrix),
index=matrix.index,
columns=matrix.index,
)The starter uses a tiny hand-crafted dataset and fills missing ratings with zeros; it lacks real movie metadata, offline ranking evaluation, cold-start handling, diversity/safety rules and any deployment or logging components.
Proposed extension: replace the toy table with MovieLens or product logs, compute k-nearest neighbours with shrinkage, add item metadata re-ranking and measure Precision@K and NDCG on a validation split.
This is a potential application pathway, not a delivered product. The supplied starter does not implement this service or validate it with real users.
Networkers Home runs this topic inside its AI Engineer Course, with placement support and hands-on labs.