Course contentsShow
← Machine Learning and Deep Learning
Lesson 2343 of 3,53851. Recommender SystemsFree lesson

Similarity Metrics for Content Matching

Computing similarity between user profiles and items using cosine similarity and other distance measures.

Similarity Metrics for Content Matching

You'll learn how to measure how similar a user's preferences are to available items using mathematical distance metrics.

The Core Idea

Once you've represented users and items as feature vectors (from TF-IDF or other methods), you need to quantify which items are "closest" to what a user likes. Think of it like finding which books in a library are most similar to ones you've enjoyed—but instead of human intuition, we use mathematical measures of distance or similarity.

Cosine Similarity

The most popular metric in content-based filtering is cosine similarity, which measures the angle between two vectors:

cosine_similarity = (user_vector · item_vector) / (||user_vector|| × ||item_vector||)

This ranges from -1 (opposite) to 1 (identical). The beauty of cosine similarity is that it focuses on direction rather than magnitude—two vectors can have different lengths but point the same way, indicating similar preferences.

Analogy: Imagine two people describing their favorite movie. One uses 100 words, another uses 10, but they emphasize the same themes. Cosine similarity captures that they're talking about similar things despite different verbosity.

Other Distance Measures

  • Euclidean distance: Straight-line distance between points. Sensitive to magnitude differences.
  • Manhattan distance: Sum of absolute differences along each dimension. Useful when features are independent.
  • Jaccard similarity: Overlap between binary feature sets (e.g., genre tags).

Each metric has trade-offs: cosine works well for text (TF-IDF vectors), Euclidean for continuous features, and Jaccard for categorical presence/absence.

Key Takeaway: Similarity metrics transform the recommendation problem into geometry—finding items whose feature vectors are closest to a user's profile vector, with cosine similarity being the go-to choice for most content-based systems.