Content-Based Filtering
Content-Based Filtering
Learn how recommendation engines suggest items based on the actual content — not other users.
What is Content-Based Filtering?
Content-Based Filtering is a recommendation technique that suggests items to users based on the features of items they liked in the past. It focuses on the content of items — not on the behavior of other users.
Real-Life Example
- If you watched a Marvel action movie, the system recommends more action superhero films.
- If you liked a Bollywood song, similar songs by the same artist or genre will appear.
- If you read a technology article, the system shows similar tech blogs.
Why Content-Based Filtering is Important?
- Works well for new users.
- Provides personalized suggestions.
- Does not depend on other users' data.
- Best for niche & specific interests.
- Used in news, music, movies, articles, e-commerce.
How Content-Based Filtering Works
Workflow
- Extract item features (genre, title, description).
- Convert text into vectors (TF-IDF, embeddings).
- Build user profile from past liked items.
- Compute similarity between user profile and items.
- Rank items based on similarity.
- Return top recommendations.
Key Components
Item Features
Genre, tags, category, description, language, etc.
User Profile
Built from items the user has interacted with.
Vectorization
Convert text into vectors (TF-IDF, embeddings).
Similarity Measures
Cosine, Euclidean, Jaccard similarity.
Ranking Engine
Sort items based on similarity score.
Examples of Item Features
Movies
- Genre, actors, director
Songs
- Genre, artist, mood
News
- Topic, keywords
Products
- Category, price, brand
Courses
- Subject, difficulty
Books
- Author, genre
Common Similarity Measures
Cosine Similarity
Measures angle between two vectors.
Euclidean Distance
Distance between two vectors.
Jaccard Similarity
Measures common features between items.
Pearson Correlation
Compares pattern correlation.
Cosine Similarity Formula
Where:
- A & B = item vectors
- Cosine value ranges from 0 to 1
- Higher score = more similar items
Python Example — Content-Based Filtering
pip install scikit-learn pandas
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
# Sample movies
data = {
"title": ["Iron Man", "Avengers", "Titanic", "Notebook", "Spider-Man"],
"description": [
"Action superhero technology suit",
"Action superhero team save world",
"Romance love sea ship",
"Romance love story emotional",
"Action superhero spider hero"
]
}
df = pd.DataFrame(data)
# Convert text to vectors
vectorizer = TfidfVectorizer()
tfidf = vectorizer.fit_transform(df["description"])
# Calculate similarity
similarity = cosine_similarity(tfidf)
# Recommendation function
def recommend(movie):
idx = df[df["title"] == movie].index[0]
scores = list(enumerate(similarity[idx]))
scores = sorted(scores, key=lambda x: x[1], reverse=True)[1:4]
return [df["title"][i[0]] for i in scores]
print(recommend("Iron Man"))
Real-Life Analogy
Content-Based Filtering = Your Personal Librarian
Just like a librarian who recommends books similar to what you read before, content-based filtering suggests items that match your past interests.
Workflow Visual
User
- Watches movies
Item Features
- Genre, tags
Vectors
- TF-IDF
Similarity
- Cosine
Ranking
- Top results
Output
- Recommendations
Real-World Applications
Movie Apps
- Recommend similar movies
Music Apps
- Suggest similar tracks
News
- Topic-based articles
Shopping
- Similar products
Books
- Genre-based suggestions
Courses
- Recommend related topics
Advantages
- Works for new users.
- Highly personalized.
- Doesn't require other users' data.
- Easy to implement.
- Works for niche interests.
Disadvantages
Common Mistakes to Avoid
Best Practices
Quick Tips
- Use TF-IDF for text data.
- Use embeddings (BERT) for richer features.
- Combine with collaborative filtering.
- Continuously update features.
- Avoid overspecialization.
- Use multi-feature scoring.
Importance of Content-Based Filtering
Core Recommendation Method
- Used worldwide
Used by Big Tech
- Netflix, Amazon
Career Skill
- High demand
Business Impact
- Boosts engagement
Golden Rule
Key Takeaway
Content-Based Filtering is one of the most powerful recommendation techniques. It uses item attributes and the user’s past preferences to suggest similar items. From Netflix to Spotify and Amazon, content-based filtering helps deliver personalized recommendations and is a must-know skill for AI engineers.