Prepare interaction data
Collect user–article interactions (clicks, reads, ratings) and pivot into a user–item matrix, filling missing values appropriately.
User-based collaborative filtering. Suggest unread items.
News recommendation uses user behaviour and item signals to suggest articles a reader may like. Common error cases include sparse user histories, popularity bias, and recommendations that reinforce narrow viewpoints.
Learning concept · Not a validated service
News recommendation uses user behaviour and item signals to suggest articles a reader may like. Common error cases include sparse user histories, popularity bias, and recommendations that reinforce narrow viewpoints.
A possible application: surface recent articles a reader has not seen yet, while allowing editors to apply business rules for freshness and diversity. This extension is not delivered by the supplied starter.
Collect user–article interactions (clicks, reads, ratings) and pivot into a user–item matrix, filling missing values appropriately.
Compute user or item similarity scores such as cosine similarity on the interaction matrix to find neighbourhoods.
For a target user, aggregate neighbour preferences over unseen items and produce a ranked list for recommendation.
Measure ranking metrics (Precision@K, NDCG) and add freshness, diversity or safety filters before deployment.
The supplied starter builds a tiny user–item rating table from nine interactions, pivots it into a dense user–item matrix, computes cosine similarity between users, finds the most similar user to a target, and recommends that neighbour's unseen items sorted by their rating.
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,
)
target_user = "user_1"
neighbor = user_similarity[target_user].drop(target_user).idxmax()
unseen_items = matrix.loc[target_user][matrix.loc[target_user] == 0].index
scores = matrix.loc[neighbor, unseen_items].sort_values(ascending=False)The starter uses a toy rating table with generic item IDs, not news articles or real clickstream data. It implements a single nearest-neighbour user-based recommendation and prints a small set of recommendations; it does not compute ranking metrics, handle cold starts, include item metadata, or address temporal freshness and diversity.
Proposed extension: replace the toy table with real clickstream or event logs, incorporate article metadata (section, timestamp), evaluate Precision@K and NDCG, and add freshness and diversity business rules before serving.
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.