Collect item metadata
Assemble descriptive fields such as title, description, tags and category, and normalise text and categorical values.
Match items by content. Score items for a user.
Content-based filtering recommends items to a user by matching item attributes or content to the user's profile of liked items. Key issues include feature engineering for item metadata, representing user preferences from item features, and balancing novelty and relevance.
Learning concept · Not a validated service
Content-based filtering recommends items to a user by matching item attributes or content to the user's profile of liked items. Key issues include feature engineering for item metadata, representing user preferences from item features, and balancing novelty and relevance.
A proposed application: recommend products from a catalogue by matching item descriptions and tags to a user's historical preferences; a human reviewer should inspect recommendations before using them for important decisions.
Assemble descriptive fields such as title, description, tags and category, and normalise text and categorical values.
Convert textual fields into TF-IDF or pretrained embeddings and combine with categorical encodings to produce item feature vectors.
Aggregate features of a user's liked items into a user profile, then score candidate items by cosine similarity to that profile.
Measure Precision@K and NDCG, and manually inspect cold-start items, over-specialisation and noisy metadata.
The supplied starter builds a user-item rating matrix from six synthetic ratings, computes cosine similarity between users, selects the most similar user to a target, and recommends that neighbour's top-rated items the target has not seen. It does not use item metadata or item-content features, so it implements a nearest-neighbour collaborative recommendation, not content-based filtering.
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 code uses only user-item ratings and computes user-user similarity; it contains no item metadata, text or feature vectors and therefore does not implement content-based filtering.
Proposed extension: replace the rating-only matrix with item feature vectors (TF-IDF or embeddings from descriptions/tags), build a user profile by aggregating features from items the user liked, and score unseen items by cosine similarity to that profile.
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.