Recommender Systems: Collaborative and Content-Based Methods

MetaCyberGuru Academy

IntermediateEstimated learning effort: 100 minutesFree, no sign-up requiredPublished by Muhammad AzharCourse version: August 2026

Back to Graphs, Recommenders and Scalable Data Mining

A recommender chooses what receives attention. Accuracy matters, but so do coverage, diversity, freshness, safety and whether the feedback loop repeatedly amplifies a narrow slice of content.

Define relevance and exposure separately

You will build a content-similarity baseline and learn how collaborative methods, matrix factorization and implicit feedback change the evidence.

  • Distinguish content-based, neighbourhood and latent-factor recommenders.
  • Handle explicit ratings and implicit signals without treating clicks as pure preference.
  • Evaluate ranking with temporal splits and leave feedback collection realistic.
  • Measure coverage, diversity and popularity bias beside relevance.

Observed behaviour is shaped by earlier recommendations

Content-based methods compare item attributes and a user’s previous items. They can explain similarity but may overspecialize. Collaborative filtering uses patterns across users and items. It can discover unexpected relationships but struggles with new users and new items.

Matrix factorization represents users and items with latent vectors whose dot product estimates affinity. These dimensions are fitted patterns, not guaranteed human concepts. Regularization helps prevent sparse users or popular items from being memorized.

Clicks, watch time and purchases are implicit feedback. Non-interaction does not necessarily mean dislike because the user may never have seen the item. Training data needs exposure information or careful negative sampling.

Random splitting can leak future interactions and make familiar items appear easy. A chronological split asks whether past behaviour recommends later items. Prevent the same event and its derived aggregates from crossing the cutoff.

Precision at k and recall at k measure ranked relevance. Add catalogue coverage, intra-list diversity, novelty and subgroup exposure. Online experiments need guardrails and informed organisational review because optimization changes what users see.

Build a content-similarity baseline

The example uses item tags and cosine similarity. It recommends items similar to one seed item while excluding the seed itself.

Install the lesson dependencies

python -m pip install pandas scikit-learn

Rank items by tag overlap

import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity

items = pd.DataFrame({
    "item": ["A", "B", "C", "D"],
    "tags": [
        "python data beginner",
        "python machine-learning intermediate",
        "design typography beginner",
        "data sql intermediate",
    ],
})

matrix = TfidfVectorizer(token_pattern=r"(?u)\b[\w-]+\b").fit_transform(items["tags"])
seed_index = 0
scores = cosine_similarity(matrix[seed_index], matrix).ravel()
ranking = sorted(
    ((items.loc[i, "item"], float(scores[i])) for i in range(len(items)) if i != seed_index),
    key=lambda pair: pair[1], reverse=True
)

print("seed:", items.loc[seed_index, "item"])
for item, score in ranking:
    print(item, round(score, 3))

Expected ranking shape

seed: A
B <positive similarity from python>
D <positive similarity from data>
C 0.281

The tag vocabulary controls every explanation. Item C has a small overlap through the shared word beginner. A missing, broad or misleading tag changes recommendations, so content metadata is part of model quality.

Recommendation failures to simulate

Evaluate the system under empty histories and catalogue change, not only active users with many interactions.

  • A new user needs a transparent fallback such as popular, recent or selected starter items.
  • A popularity-only fallback can starve new items of exposure.
  • Using clicks as negatives for unseen items confuses no exposure with dislike.
  • Optimizing engagement alone can reduce variety or amplify harmful material.

Create an offline recommendation evaluation

Construct synthetic timestamped interactions and hide each user’s latest eligible item.

  • Compare popularity and content baselines.
  • Report precision at k, user coverage and catalogue coverage.
  • Create cold-user and cold-item slices.
  • Document filtering, safety and fallback rules before ranking.

Recommender evidence

  • Temporal evaluation table.
  • Coverage and diversity report.
  • Example recommendation with evidence and fallback behaviour.

Knowledge check

1. Why is an unclicked item not a clean negative?
Check your reasoning

Exposure affects interaction, so absence of a click cannot be interpreted as dislike without more context.

2. What does catalogue coverage measure?
Check your reasoning

Coverage exposes whether the system repeatedly recommends a narrow subset.

3. Why use a chronological split?
Check your reasoning

Recommendation deployment predicts later interaction, so time-respecting evaluation is more realistic.

Official references and further reading

Review note for Recommender Systems: Collaborative and Content-Based Methods: recheck the linked documentation after a dependency changes the relevant API, metric or modelling assumption, then record the tested version beside your result.

Save your place

Completion is stored only in this browser on this device.

Share this page

Share this page with the people who will use it next.

X Facebook LinkedIn WhatsApp Email

Discussion

No comments yet. Add the first useful question or observation.