Content-based recommendations with a transparent baseline
In this article (3 sections)
A content-based baseline recommends items similar to what a user already liked. It can serve new items with metadata and produce readable explanations. It can also narrow exposure to familiar topics and inherit every weakness in the tags.
Build the profile in six visible dimensions
Our synthetic catalogue has 20 items and six binary tags: Python, SQL, statistics, machine learning, generative AI and cloud. A user liked I0, tagged Python/statistics, and I4, tagged generative AI/Python.
The mean profile is Python 1.0, statistics 0.5 and generative AI 0.5, with zeros elsewhere. We compute cosine similarity to every catalogue item, remove the two seen items and use stable item order for ties.
The top results are I13 and I16 at cosine 0.8660, followed by I10, I14 and I2 at 0.5774. The model has no clicks, ratings, recency or outcomes beyond the two authored likes.
The scikit-learn pairwise metrics guide defines cosine similarity as the normalized dot product.
from unsupervised_cases import content_case
r = content_case()
assert r['liked'] == ['I0', 'I4']
assert r['profile']['python'] == 1
assert [row['item'] for row in r['top_five'][:2]] == ['I13', 'I16']
assert all(row['item'] not in r['liked'] for row in r['top_five'])
print(r)Run it in the unsupervised lab. The output is a deterministic baseline, not a measured recommendation improvement.
Treat metadata as a model input
Define who assigns tags, their version and allowed values. Missing tags can make a good item invisible. Broad tags make many items tie; narrow tags create sparse profiles. Weighting terms with TF-IDF can reduce ubiquitous tags, but the weighting remains a design choice.
User profiles may use ratings, dwell time or recency rather than an unweighted mean. Each signal has bias. A click can reflect position or exposure, and a completion can reflect required curriculum rather than preference.
Evaluate with temporal holdouts and compare popularity, recent-item and random baselines. Report relevance metrics, catalogue coverage, diversity and cold-start behaviour. Offline similarity does not estimate whether showing an item causes useful engagement.
Explanations should cite actual shared attributes: “recommended because both cover Python and generative AI.” Avoid implying psychological traits. Allow users to correct interests and provide a discovery path beyond existing preferences.
Exercise: add tag weights, recency-weighted likes and one disliked item. Define how negative evidence changes the profile without producing negative cosine surprises. Evaluate each variant on a temporal holdout rather than choosing the most appealing example recommendation.
NeuraPath's Data Science course uses transparent baselines to make later recommender complexity earn its place. Every score can be traced to a profile and item vector.
Continue learning
This article is part of the Clustering, reduction and recommendations sequence. Use the neighbouring tasks when you need the prerequisite or the next application.
- Review the prerequisite or neighbouring task in Association rules: compare lift, confidence and support.
- Continue with Collaborative filtering and the cold-start problem.
Pankit Kumar has 10 years in Data Science & AI, building and shipping production systems in regulated pharma and clinical environments. He is a freelance trainer at Boston Institute of Analytics, AnalytixLabs and Scaler, and has taught this material to thousands of working professionals.
This article is part of our Data Science programme — 6 months. From data foundations to machine learning, deep learning and deployment.
Explore Data Science