Skip to content

kirtis111/e-commerce-recommendation-system

Repository files navigation

E-Commerce Recommendation System (Implicit Feedback)

End-to-end recommendation system built on implicit user behavior, featuring offline evaluation, multiple collaborative filtering models, a production-style FastAPI service, and a Streamlit demo UI.

This project mirrors how real-world recommender systems are trained, evaluated, and served in modern e-commerce platforms.


Problem Statement

In real-world e-commerce, users rarely provide explicit ratings. Instead, recommendation systems must learn from implicit signals such as:

  • product views
  • clicks
  • add-to-cart events
  • purchases

The challenge is to build a system that balances:

  • Ranking accuracy → relevant recommendations
  • Catalog coverage → discovery beyond popular items
  • Interpretability → business trust & explainability

This project explores that trade-off using multiple collaborative filtering approaches and a hybrid strategy inspired by production systems.


Data & Evaluation Design

  • Implicit interaction data (no ratings)
  • Time-aware split with 1 held-out future item per user
  • Evaluation on Validation and Test sets
  • Metrics:
    • Recall@K
    • NDCG@K
    • Coverage@K (fraction of catalog surfaced)

This setup closely reflects the real business question:

“Can we rank the next item a user is likely to interact with?”


Models Implemented

1️. Popularity Baseline

Ranks items by global interaction frequency.

Purpose

  • Sanity check
  • Cold-start fallback

Limitation

  • Severe popularity bias
  • Near-zero personalization and coverage

2️. Item-Item Collaborative Filtering (Co-Visitation)

Learns item similarity from user co-interaction patterns .

Strengths

  • Strong personalization over popularity
  • Very high catalog coverage (~48%)
  • Highly interpretable (“users who interacted with X also interacted with Y”)

Best suited for

  • Similar-item carousels
  • Discovery use cases
  • Repeat users

3️. Implicit Matrix Factorization (ALS)

Learns latent user and item embeddings from implicit feedback using Alternating Least Squares .

Strengths

  • Best ranking accuracy (Recall@K, NDCG@K)
  • Captures deeper personalization patterns

Trade-off

  • Lower catalog coverage
  • Less interpretable than item-item models

4️. Hybrid Recommender (ALS + Item-Item)

A weighted hybrid combining:

  • ALS → ranking accuracy & personalization
  • Item-Item → coverage, diversity, explainability

This mirrors how recommender systems are deployed in production to balance exploit vs explore .


System Architecture

architecture_overview_500

Data Flow Diagram (Training vs Inference)

1769456360234


Offline Evaluation Results

Time-aware split, 1 held-out item per user

Model Split Recall@10 NDCG@10 Coverage@10 Recall@20 NDCG@20 Coverage@20
Popularity Test 0.0059 0.0030 0.00017 0.0109 0.0043 0.00035
Item-Item CF Test 0.0624 0.0319 0.4836 0.0947 0.0401 0.4913
Implicit ALS Test 0.1182 0.0652 0.1056 0.1667 0.0775 0.1457
Hybrid Test 0.1232 0.0677 0.1327 0.1748 0.0807 0.2064

Key takeaway

The Hybrid model improves ranking quality over ALS while significantly increasing catalog coverage , achieving a more production-ready balance.


Key Insights

  • Popularity is a necessary baseline but unsuitable alone
  • Item-Item CF excels at discovery and explainability
  • ALS delivers the strongest personalization
  • Hybrid recommender offers the best real-world trade-off:
    • High Recall / NDCG
    • 2× coverage improvement over ALS
    • Supports exploration without sacrificing relevance

How This Would Be Used in Production

Use Case Model
Homepage personalization Hybrid
Similar-items carousel Item-Item
Cold-start users Popularity
Offline monitoring Recall, NDCG, Coverage

Reproducibility & Training Pipeline

End-to-end reproducible pipeline:

python -m src.data.make_dataset
python -m src.features.build_features
python -m src.models.popularity
python -m src.models.item_item
python -m src.models.mf_implicit
python -m src.models.hybrid
python -m src.models.evaluate

Or run everything via:

python scripts/train_all.py

FastAPI Recommendation Service

A production-style FastAPI service exposes recommendations via REST.

Run API locally

python -m uvicorn src.api.app:app --reload

Swagger UI:

http://127.0.0.1:8000/docs

Demo Users

user_id Description
1085562 High activity user
1371942 Medium activity
1179363 Low activity / near cold-start

Example Requests

GET /recommend?user_id=1085562&model=hybrid&k=10
GET /recommend?user_id=1085562&model=als&k=10
GET /recommend?user_id=1085562&model=itemitem&k=10

fast_api_1

fast_api_2

fast_api_3

fast_api_4

fast_api_5


Streamlit Demo UI

A lightweight Streamlit app acts as a client for the FastAPI service.

Run Streamlit

streamlit run streamlit_app.py

Features:

  • Model selection (popularity / item-item / ALS / hybrid)
  • Real-time API calls
  • Ranked results table
  • JSON download for inspection

Streamlit_UI_1

Streamlit_UI_2

Streamlit_UI_3


Docker Support (Optional)

This repository includes:

  • Dockerfile.api
  • Dockerfile.streamlit
  • docker-compose.yml

If Docker is installed:

docker compose up --build

Otherwise, both services can be run locally as shown above.


What This Project Demonstrates

  • Recommender system fundamentals (implicit feedback)
  • Offline evaluation with business-relevant metrics
  • Production-style model serving with FastAPI
  • Client-service separation using Streamlit
  • Hybrid modeling and cold-start handling
  • End-to-end ML system thinking

About

End-to-end E-Commerce Recommendation System using implicit feedback, featuring Popularity, Item-Item CF, ALS (Matrix Factorization), and a Hybrid model, with offline evaluation and online serving via FastAPI + Streamlit.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors