CoolFace
Apppublic

biplobgon/product-recommendation-system

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes
App README

๐Ÿ›๏ธ Product Recommendation System

Python Recommender FastAPI Streamlit Dataset Events Models


<!--โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•— PART 1 โ€” PRODUCT LINKS โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•-->

๐Ÿ”— Live Demos

SurfaceLinkNotes
Streamlit Dashboardhttp://localhost:8501Interactive UI โ€” get personalised recommendations, explore model metrics & data
FastAPI Servicehttp://localhost:8000REST endpoints โ€” /recommend/{visitor_id}, /similar/{item_id}, /popular
FastAPI Docs (Swagger)http://localhost:8000/docsAuto-generated OpenAPI spec
Run locally in two commands: ``bash uvicorn src.app.api:app --host 0.0.0.0 --port 8000 --reload streamlit run src/app/dashboard.py --server.port 8501 ``

<!--โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•— PART 2 โ€” EXECUTIVE SUMMARY โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•-->

๐Ÿ“Œ Overview

End-to-end Product Recommendation System built on the real-world RetailRocket e-commerce dataset (~2.75 M user interaction events). The project covers the full ML lifecycle โ€” EDA โ†’ feature engineering โ†’ model training โ†’ offline evaluation โ†’ REST API + interactive dashboard โ€” using a 4-model hybrid architecture that handles both cold-start and warm-start users.

Core prediction goal: Given a visitor's browsing session and historical interactions, predict the next N products they are most likely to purchase.

๐ŸŽฏ Executive Summary

The Problem

E-commerce recommendation engines face a brutal sparsity problem. In this dataset, >70 % of visitors have โ‰ค 3 interactions and transactions represent only 0.5 % of all events. A single model cannot solve this:

  • โ€”Pure Collaborative Filtering fails for cold-start users (most of them).
  • โ€”Pure Content-Based filtering ignores rich co-purchase signals.
  • โ€”Pure Session-Based models lose long-term preference memory.

The Solution

A hybrid stack of four complementary models working together โ€” each covering the blind spots of the others:

ModelCovers
ALS (Collaborative Filtering)Warm users with โ‰ฅ 2 interactions โ€” taste matching
TF-IDF Content-BasedCold items and new visitors โ€” property similarity
Item-KNN Session-BasedAll visitors โ€” within-session sequential intent
Hybrid BlenderWeighted merge of all three signals into top-K results

Results at a Glance

ModelHit Rate@10NDCG@10MRR@10
ALS (Collaborative Filtering)0.0000.0000.000
Content-Based (TF-IDF)0.0000.0000.000
Session-Based (Item-KNN)0.1190.0580.039
Hybrid0.1150.0560.038
ALS and Content-Based register 0.0 on this evaluation because the test set is constructed from the most recent sessions โ€” users in that window are not present in training (temporal cold-start). This is expected and realistic. The session model โ€” which requires no user history โ€” is the strongest performer.

Why This Matters for a Business

  • โ€”Personalisation from session 1 โ€” session-based model requires zero user history.
  • โ€”Full catalogue coverage โ€” content-based ensures every item (even those with no purchase history) can surface.
  • โ€”Modular, swappable stack โ€” each model is independently loadable and overridable via API parameter.
  • โ€”Sub-100 ms serving โ€” all models are loaded in-memory; no database joins at request time.

<!--โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•— PART 3 โ€” TECHNICAL DEEP DIVE โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•-->

๐Ÿ”ฌ Technical Deep Dive


๐Ÿ“Š Dataset

Source: RetailRocket E-commerce Dataset (Junโ€“Sep 2015)

FileRowsKey stat
events.csv~2.75 Mview 95.8 %, addtocart 2.7 %, transaction 0.5 %
item_properties_part1.csv~11 M~185k unique items with metadata
item_properties_part2.csv~9.2 MExtends Part 1; combined ~20 M property records
category_tree.csv~1,600 nodesDepth 2โ€“3 dominant; max depth 5

Interaction signal weights used in training: view = 1 ยท addtocart = 5 ยท transaction = 10


๐Ÿง  System Architecture

                โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                โ”‚              Incoming Request               โ”‚
                โ”‚   visitor_id  ยท  session_items  ยท  top_k   โ”‚
                โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                   โ”‚
         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
         โ–ผ                         โ–ผ                          โ–ผ
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚  ALS (CF)   โ”‚         โ”‚  TF-IDF (CB)  โ”‚         โ”‚  Item-KNN (SB)   โ”‚
  โ”‚  weight=0.4 โ”‚         โ”‚  weight=0.2   โ”‚         โ”‚  weight=0.4      โ”‚
  โ”‚  warm users โ”‚         โ”‚  cold items   โ”‚         โ”‚  all visitors    โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                        โ”‚  Weighted Blend  โ”‚
                        โ”‚  + min-max norm  โ”‚
                        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ–ผ
                       Top-K Recommendations

Session boundary: 1-hour inactivity gap ยท Max sequence length: 20 items ยท Temporal train/test split: leave-last-session-out


๐Ÿ—๏ธ Model Implementations

ALS โ€” Collaborative Filtering (src/models/collaborative_filtering.py)
  • โ€”Pure numpy / scipy implementation of the Hu-Koren-Volinsky (2008) Alternating Least Squares algorithm โ€” no external library dependency (the implicit package doesn't support Python 3.14).
  • โ€”Weighted implicit feedback matrix with factors=32, iterations=10, regularisation=0.01.
  • โ€”Trained on 31,880 warm users ร— 344,728 weighted interactions.
Content-Based โ€” TF-IDF (src/models/content_based.py)
  • โ€”Scikit-learn TfidfVectorizer over concatenated item property strings (categoryid + price bucket + availability).
  • โ€”max_features=500 to keep the matrix (417k ร— 500) tractable.
  • โ€”Cosine similarity at query time; no pre-computed pairwise matrix (memory efficient).
Session-Based โ€” Item-KNN (src/models/session_based.py)
  • โ€”Co-occurrence matrix over 386,099 training sequences, recency-weighted (more recent sessions count more).
  • โ€”No PyTorch dependency โ€” pure numpy co-occurrence counting with exponential recency decay.
  • โ€”At query time: sums co-occurrence scores for all items in the current session; returns top-K.
Hybrid (src/models/hybrid.py)
  • โ€”Calls all three models, normalises scores to [0, 1], applies configurable weights, and merges.
  • โ€”Gracefully degrades: if ALS has no embedding for a new user, only CB + Session contribute.

โš™๏ธ Feature Engineering

Feature SetFileKey columns
User featuresdata/processed/user_features.csvn_views, n_addtocart, n_transactions, n_unique_items, conversion_rate, is_cold_start
Item featuresdata/processed/item_features.csvcategoryid, price, available
Session featuresdata/processed/session_features.csvsession_id, visitorid, n_events, duration_min, n_unique_items
Interaction matrixdata/processed/interactions.csvvisitorid, itemid, weight
TF-IDF matrixdata/processed/tfidf_matrix.npzSparse (417,053 ร— 500)

Generated by running notebooks/02_feature_engineering.ipynb.


๐Ÿ“ˆ Evaluation Metrics

MetricWhat it measures
Hit Rate@KFraction of test users whose ground-truth item appears in top-K
NDCG@KRanks the true item higher โ†’ higher reward
MRR@KMean reciprocal rank of first relevant item
Precision@K / Recall@KStandard IR metrics at cutoff K
CoverageFraction of item catalogue ever recommended (diversity signal)
NoveltyAvg. log-popularity of recommended items (higher = more niche)

Results saved to outputs/reports/evaluation_report.csv. Run evaluation independently via:

bash
python src/training/run_evaluation.py

๐Ÿ”Œ API Reference

bash
uvicorn src.app.api:app --host 0.0.0.0 --port 8000 --reload
MethodEndpointDescription
GET/healthService health + loaded models
GET/recommend/{visitor_id}Personalised top-K (all models)
POST/recommend/sessionSession-only recommendations (no history needed)
GET/similar/{item_id}Items similar to a given item (TF-IDF)
GET/popularGlobal popularity fallback

Example:

bash
curl "http://localhost:8000/recommend/12345?session_items=101,202&top_k=10"
json
{
  "visitor_id": 12345,
  "recommended_items": [876, 205, 934, 412, 778, 66, 543, 188, 301, 407],
  "model": "hybrid",
  "latency_ms": 38
}

๐Ÿ“ Project Structure

product-recommendation-system/
โ”‚
โ”œโ”€โ”€ data/
โ”‚   โ”œโ”€โ”€ raw/                            # Original RetailRocket CSVs
โ”‚   โ”‚   โ”œโ”€โ”€ events.csv
โ”‚   โ”‚   โ”œโ”€โ”€ category_tree.csv
โ”‚   โ”‚   โ”œโ”€โ”€ item_properties_part1.csv
โ”‚   โ”‚   โ””โ”€โ”€ item_properties_part2.csv
โ”‚   โ””โ”€โ”€ processed/                      # Generated feature files (gitignored โ€” too large)
โ”‚       โ”œโ”€โ”€ user_features.csv           # 1,407,580 users ร— 12 features
โ”‚       โ”œโ”€โ”€ item_features.csv           # 417,053 items ร— 3 features
โ”‚       โ”œโ”€โ”€ interactions.csv            # 2,145,179 user-item weighted interactions
โ”‚       โ”œโ”€โ”€ session_features.csv        # 1,726,714 sessions ร— 9 features
โ”‚       โ”œโ”€โ”€ session_sequences.csv       # 386,099 training sequences
โ”‚       โ”œโ”€โ”€ tfidf_matrix.npz            # Sparse TF-IDF (417k ร— 500)
โ”‚       โ”œโ”€โ”€ tfidf_item_ids.csv          # Item ID โ†’ TF-IDF row index mapping
โ”‚       โ””โ”€โ”€ tfidf_vectorizer.pkl        # Fitted sklearn TfidfVectorizer
โ”‚
โ”œโ”€โ”€ notebooks/
โ”‚   โ”œโ”€โ”€ eda.ipynb                       # 01 โ€” Full EDA (25 cells, 25 visualisations)
โ”‚   โ”œโ”€โ”€ 02_feature_engineering.ipynb    # 02 โ€” User / item / session feature generation
โ”‚   โ”œโ”€โ”€ 03_model_training.ipynb         # 03 โ€” Train ALS, CB, Session, Hybrid
โ”‚   โ””โ”€โ”€ 04_model_evaluation.ipynb       # 04 โ€” Offline metrics + comparison charts
โ”‚
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ utils/
โ”‚   โ”‚   โ”œโ”€โ”€ config.py                   # YAML loader with dot-notation access
โ”‚   โ”‚   โ””โ”€โ”€ logger.py                   # Centralised logging
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ features/
โ”‚   โ”‚   โ”œโ”€โ”€ user_features.py            # Visitor-level aggregates
โ”‚   โ”‚   โ”œโ”€โ”€ item_features.py            # Item metadata + price/availability parsing
โ”‚   โ”‚   โ””โ”€โ”€ session_features.py         # Session segmentation + sequence building
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ models/
โ”‚   โ”‚   โ”œโ”€โ”€ collaborative_filtering.py  # ALSRecommender (pure numpy/scipy)
โ”‚   โ”‚   โ”œโ”€โ”€ content_based.py            # ContentBasedRecommender (sklearn TF-IDF)
โ”‚   โ”‚   โ”œโ”€โ”€ session_based.py            # SessionBasedRecommender (Item-KNN, numpy)
โ”‚   โ”‚   โ””โ”€โ”€ hybrid.py                   # HybridRecommender (weighted blend)
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ training/
โ”‚   โ”‚   โ”œโ”€โ”€ train.py                    # Full end-to-end training pipeline
โ”‚   โ”‚   โ”œโ”€โ”€ resume_training.py          # Skip CB re-training; reload saved ALS+CB
โ”‚   โ”‚   โ”œโ”€โ”€ run_evaluation.py           # Evaluate all models โ†’ evaluation_report.csv
โ”‚   โ”‚   โ””โ”€โ”€ evaluate.py                 # HR@K, NDCG@K, MRR@K, Coverage, Novelty
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ app/
โ”‚   โ”‚   โ”œโ”€โ”€ api.py                      # FastAPI service (5 endpoints)
โ”‚   โ”‚   โ””โ”€โ”€ dashboard.py                # Streamlit dashboard (3 tabs)
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ data_prep.py                    # Raw data cleaning & validation
โ”‚   โ”œโ”€โ”€ create_sample.py                # Stratified sampling for fast iteration
โ”‚   โ””โ”€โ”€ gcs_loader.py                   # Download raw files from Google Cloud Storage
โ”‚
โ”œโ”€โ”€ outputs/
โ”‚   โ”œโ”€โ”€ models/                         # Serialised PKL artefacts (gitignored โ€” large)
โ”‚   โ”‚   โ”œโ”€โ”€ als_model.pkl               # 17.6 MB
โ”‚   โ”‚   โ”œโ”€โ”€ content_based_model.pkl     # 338 MB
โ”‚   โ”‚   โ”œโ”€โ”€ session_based_model.pkl     # 14.1 MB
โ”‚   โ”‚   โ””โ”€โ”€ hybrid_model.pkl            # 370 MB
โ”‚   โ””โ”€โ”€ reports/
โ”‚       โ””โ”€โ”€ evaluation_report.csv       # All model metrics across K=5,10
โ”‚
โ”œโ”€โ”€ configs/
โ”‚   โ”œโ”€โ”€ model_config.yaml               # Hyperparameters & data paths
โ”‚   โ””โ”€โ”€ pipeline_config.yaml            # Training pipeline, MLflow, retrain schedule
โ”‚
โ”œโ”€โ”€ assets/                             # Static images for README
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ README.md

๐Ÿ”„ End-to-End Pipeline

Raw CSVs โ†’ EDA (01) โ†’ Feature Engineering (02)
                              โ”‚
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚  data/processed/                  โ”‚
              โ”‚  user_features  ยท  item_features  โ”‚
              โ”‚  tfidf_matrix   ยท  interactions   โ”‚
              โ”‚  session_sequences                โ”‚
              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚  Training (train.py)              โ”‚
              โ”‚  ALS โ†’ CB (40 min) โ†’ Session      โ”‚
              โ”‚  โ†’ Hybrid                         โ”‚
              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚  Evaluation (run_evaluation.py)   โ”‚
              โ”‚  HR@K ยท NDCG@K ยท MRR@K           โ”‚
              โ”‚  Coverage ยท Novelty               โ”‚
              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚  Serving                          โ”‚
              โ”‚  FastAPI :8000  ยท  Streamlit :8501โ”‚
              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Quick start:

bash
# 1. Install dependencies
pip install -r requirements.txt

# 2. Pull raw data (or place CSVs manually in data/raw/)
cp .env.example .env   # set GCS_BUCKET_NAME
python src/gcs_loader.py

# 3. Run feature engineering
jupyter nbconvert --to notebook --execute notebooks/02_feature_engineering.ipynb

# 4. Train models (full run ~50 min; CB is the bottleneck)
python src/training/train.py

# 5. Or, if models are already saved, run a fast retrain (session only, ~30 s)
python src/training/resume_training.py

# 6. Evaluate
python src/training/run_evaluation.py

# 7. Serve
uvicorn src.app.api:app --reload
streamlit run src/app/dashboard.py

๐Ÿชฒ Pitfalls Faced & How They Were Solved

#PitfallRoot CauseSolution
1OOM crash during TF-IDFmax_features=5000 on 417k items โ†’ 2 GB dense matrixReduced to max_features=500
2`implicit` / `torch` missing on Python 3.14No wheels available for Python 3.14Replaced ALS with pure numpy/scipy, replaced GRU4Rec with Item-KNN
3Duplicate class in `session_based.py`Old GRU4Rec class at line 162 silently overrode the new Item-KNN classTruncated file to 160 lines to remove the ghost class
4`user_features.py` OOM from `mode()` lambda.apply(lambda x: x.mode()) on 2.75 M rows with groupby is O(nยฒ)Rewrote with vectorised pandas.groupby aggregates โ€” 16ร— faster
5`pyarrow` incompatible with Python 3.14ArrowKeyError: No type extension named arrow.py_extension_typeSwitched notebook persist step from .to_parquet() โ†’ .to_csv()
6Dashboard showing wrong model filesMODEL_FILES dict still referenced old filenames (als_model.npz, gru4rec_model.pt)Updated all keys to actual .pkl filenames
7`_enrich_items` column misalignmentModels return list[tuple[int, float]]; dashboard iterated as plain intsFixed unpacking to (item_id, score) and added a Score column
8`evaluation_report.csv` cached as `None`@st.cache_data cached before file existed on first runRemoved the decorator from load_eval_report
9Large files rejected by GitHub (>100 MB)Model PKLs (338โ€“370 MB) and processed CSVs (106 MB) exceeded GitHub limitAdded to .gitignore; removed from git history with git rm --cached + amend

๐Ÿš€ Future Enhancements

PriorityItem
๐Ÿ”ด HighMLflow experiment tracking โ€” config exists; calls not yet wired into train.py
๐Ÿ”ด HighConversionRanker (LightGBM) โ€” train on session features ร— is_purchase target to re-rank hybrid output
๐ŸŸก MediumReal-time event streaming โ€” Kafka consumer to update session model with live clicks
๐ŸŸก MediumA/B testing framework โ€” statistical comparison of hybrid vs. popularity baseline
๐ŸŸก MediumTime-of-day feature โ€” inject hour-of-day signal (peak 17โ€“21h) into re-ranker
๐ŸŸข LowBERT4Rec / SASRec โ€” Transformer-based sequential model to replace Item-KNN
๐ŸŸข LowNeuMF โ€” Neural Collaborative Filtering for richer user/item embeddings vs. ALS
๐ŸŸข LowGNN over category hierarchy โ€” co-purchase + category graph for structural similarity
๐ŸŸข LowReinforcement learning bandit โ€” explore-exploit policy for dynamic recommendation

โ˜๏ธ Google Cloud Storage Setup

Raw files can be pulled from a GCS bucket automatically.

bash
gcloud auth application-default login
cp .env.example .env   # set GCS_BUCKET_NAME
python src/gcs_loader.py
BlobDescription
events.csvUser interaction events
category_tree.csvProduct category hierarchy
item_properties_part1.csvItem metadata part 1
item_properties_part2.csvItem metadata part 2

๐Ÿ‘ค Author

Biplob Gon ยท Data Scientist | AI/ML | Recommender Systems

![GitHub](https://github.com/biplobgon) ![LinkedIn](https://linkedin.com/in/biplobgon)


โญ Found this useful?

Give the repo a โญ โ€” it helps others discover it.