Table of Contents

    Content-Based Filtering

    RECOMMENDATION SYSTEMS

    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.

    In simple words — It recommends items similar to what you already liked.

    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.
    Content-Based Filtering = "More of what you already like".

    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

    1

    Item Features

    Genre, tags, category, description, language, etc.

    2

    User Profile

    Built from items the user has interacted with.

    3

    Vectorization

    Convert text into vectors (TF-IDF, embeddings).

    4

    Similarity Measures

    Cosine, Euclidean, Jaccard similarity.

    5

    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

    1

    Cosine Similarity

    Measures angle between two vectors.

    2

    Euclidean Distance

    Distance between two vectors.

    3

    Jaccard Similarity

    Measures common features between items.

    4

    Pearson Correlation

    Compares pattern correlation.

    Cosine Similarity Formula

    COSINE SIMILARITY
    $$ \cos\theta = \frac{A \cdot B}{\|A\| \, \|B\|} $$

    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"))
    Output Suggests similar movies based on content features.

    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

    Limitation 1 Limited to user's past behavior.
    Limitation 2 Can be repetitive.
    Limitation 3 Requires good content metadata.
    Limitation 4 Cannot suggest items from new categories.

    Common Mistakes to Avoid

    Mistake 1 Using poor item features.
    Mistake 2 Skipping text cleaning.
    Mistake 3 Not normalizing features.
    Mistake 4 Using only one similarity measure.

    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

    REMEMBER
    User Profile + Item Features + Similarity = Content-Based Filtering

    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.