← Back to all products
$49
Product Recommendation Engine
Collaborative filtering, content-based recommendations, trending products algorithm, and A/B testing integration.
MarkdownYAMLPython
📄 Product Preview
Try the interactive reader and demo tools below, or get the full product with all content unlocked.
📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample📁 File Structure 20 files
product-recommendation-engine/
├── LICENSE
├── README.md
├── configs/
│ └── recommender_config.yaml
├── data/
│ ├── sample_interactions.csv
│ └── sample_products.csv
├── free-sample.zip
├── guide/
│ ├── 01-overview.md
│ ├── 02-recommendation-algorithms-explained.md
│ └── 03-a-b-testing-recommendations.md
├── guides/
│ └── recommendation_guide.md
├── index.html
├── src/
│ ├── __init__.py
│ ├── ab_testing.py
│ ├── collaborative_filter.py
│ ├── content_based.py
│ ├── evaluation.py
│ ├── hybrid_blender.py
│ └── trending.py
└── tests/
└── test_recommender.py
📖 Documentation Preview README excerpt
Product Recommendation Engine
A complete recommendation system for e-commerce stores. Implements collaborative filtering, content-based filtering, trending detection, and hybrid blending — all from scratch using Python's standard library. Includes A/B testing and evaluation metrics for measuring recommendation quality.
Features
- Collaborative Filtering — User-based and item-based CF using cosine similarity. Finds patterns like "customers who bought X also bought Y" without any ML libraries
- Content-Based Filtering — TF-IDF weighted feature vectors from product attributes (category, tags, brand, title words). Handles cold-start for new users and new products
- Trending Detection — Three popularity signals: raw volume, velocity (growth rate vs previous period), and recency-weighted scoring with exponential decay
- Hybrid Blender — Merges all algorithms into a single ranked list. Three strategies: weighted average, cascade (priority-based fallback), and switching (data-availability-based)
- A/B Testing Harness — Deterministic user-to-variant assignment, event tracking, and statistical significance testing with Z-test for conversion rate comparison
- Evaluation Suite — Precision@K, Recall@K, NDCG@K, MAP@K, Hit Rate, Coverage, and multi-algorithm comparison
Quick Start
from src.collaborative_filter import CollaborativeFilter
from src.content_based import ContentBasedRecommender
from src.trending import TrendingDetector
from src.hybrid_blender import HybridBlender
# 1. Load data
cf = CollaborativeFilter.from_csv("data/sample_interactions.csv")
content = ContentBasedRecommender.from_csv("data/sample_products.csv")
# 2. Get recommendations
user_recs = cf.recommend_for_user("U001", n=10, method="user")
similar = cf.similar_items("P001", n=5)
content_recs = content.similar_products("P001", n=5)
# 3. Blend signals
blender = HybridBlender(cf=cf, content=content)
recs = blender.recommend("U001", n=10, strategy="weighted",
user_history=[{"product_id": "P001", "score": 5}])
for r in recs:
print(f" {r.product_id} score={r.final_score:.3f} source={r.primary_source}")
What's Included
product-recommendation-engine/
├── README.md ← You are here
├── LICENSE ← MIT License
├── .gitignore
├── src/
│ ├── __init__.py ← Package init with public API imports
│ ├── collaborative_filter.py ← User-based and item-based CF
│ ├── content_based.py ← TF-IDF content similarity
│ ├── trending.py ← Popularity and velocity detection
│ ├── hybrid_blender.py ← Multi-algorithm blending
│ ├── ab_testing.py ← A/B test harness with stats
│ └── evaluation.py ← Offline evaluation metrics
├── data/
│ ├── sample_interactions.csv ← 100 user-product interactions
│ └── sample_products.csv ← 15 products with attributes
├── tests/
│ └── test_recommender.py ← Full test suite (35+ tests)
├── configs/
*... continues with setup instructions, usage examples, and more.*
📄 Code Sample .py preview
src/ab_testing.py"""
A/B Testing Harness for Recommendations
=========================================
Run controlled experiments to compare recommendation strategies. The
harness handles:
1. **Traffic splitting** — Deterministically assigns users to variants
(A or B) based on a hash of their user ID. This ensures:
- Same user always sees the same variant (consistency)
- Split is reproducible across runs
- No need for external random state
2. **Metric tracking** — Records clicks, conversions, and revenue per
variant so you can measure which algorithm actually drives sales.
3. **Statistical significance** — Calculates Z-scores and p-values to
determine if observed differences are real or just noise.
Usage::
harness = ABTestHarness(
test_name="cf_vs_trending",
variant_a="collaborative_filter",
variant_b="trending_popular",
traffic_split=0.5,
)
variant = harness.assign_variant("U001")
# serve recommendations from the assigned variant's algorithm
harness.record_event("U001", "click", product_id="P101")
harness.record_event("U001", "purchase", product_id="P101", revenue=49.99)
report = harness.analyze()
"""
from __future__ import annotations
import hashlib