100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Recommender Systems Cheat Sheet

Recommender Systems Cheat Sheet

Compares content-based filtering, collaborative filtering, and matrix factorization approaches, with code examples and ranking metrics for evaluation.

2 PagesIntermediateFeb 28, 2026

Recommendation Approaches

Core paradigms for building a recommender.

  • Content-based filtering- Recommends items similar to what a user liked before, based on item features (genre, tags, description)
  • Collaborative filtering (user-based)- Recommends items liked by users with similar rating patterns
  • Collaborative filtering (item-based)- Recommends items similar to ones the user already rated highly, based on co-rating patterns
  • Matrix factorization- Decomposes the user-item rating matrix into low-rank latent user and item factor matrices (e.g., SVD, ALS)
  • Hybrid- Combines content-based and collaborative signals to handle cold-start and sparsity
  • Cold-start problem- Difficulty recommending for new users/items with no interaction history

Content-Based Similarity

Recommend items with similar TF-IDF text features.

python
from sklearn.feature_extraction.text import TfidfVectorizerfrom sklearn.metrics.pairwise import cosine_similaritytfidf = TfidfVectorizer(stop_words='english')tfidf_matrix = tfidf.fit_transform(items_df['description'])sim_matrix = cosine_similarity(tfidf_matrix)similar_idx = sim_matrix[item_index].argsort()[::-1][1:11]  # top 10, excluding itselfrecommendations = items_df.iloc[similar_idx]['title']

Matrix Factorization with SVD

Factorize a sparse ratings matrix using scikit-learn's TruncatedSVD.

python
from sklearn.decomposition import TruncatedSVDimport numpy as np# ratings_matrix: rows = users, cols = items, 0 = missing ratingsvd = TruncatedSVD(n_components=20, random_state=42)user_factors = svd.fit_transform(ratings_matrix)item_factors = svd.components_.Tpredicted_ratings = user_factors @ item_factors.Ttop_items_for_user = np.argsort(predicted_ratings[user_id])[::-1][:10]

Evaluation Metrics

Rating-prediction accuracy vs. ranking quality.

  • RMSE / MAE- Measures error between predicted and actual ratings; standard for explicit-rating tasks
  • Precision@K- Fraction of the top-K recommended items the user actually interacted with
  • Recall@K- Fraction of all relevant items that appear in the top-K recommendations
  • NDCG- Rewards ranking relevant items higher, discounting relevance by position in the list
  • Coverage- Fraction of the catalog the system is capable of recommending; guards against always recommending the same popular items
Pro Tip

Optimizing for RMSE alone doesn't guarantee good rankings -- always pair rating-error metrics with a top-K ranking metric like Precision@K or NDCG before shipping a recommender.

Was this cheat sheet helpful?

Explore Topics

#RecommenderSystems#RecommenderSystemsCheatSheet#DataScience#Intermediate#RecommendationApproaches#ContentBasedSimilarity#MatrixFactorizationWithSVD#EvaluationMetrics#MachineLearning#CheatSheet#SkillVeris