A full end-to-end recommendation engine built on the Global Superstore dataset, implementing and comparing three algorithms — Apriori, FP-Growth, and Naive Bayes — to generate personalised product recommendations based on customer purchase history. Accompanied by two tutorial videos published on YouTube.
This project answers the core question of recommendation systems:
"If a user bought item X, what should we recommend next — item Y or something else?"
Three approaches are implemented and benchmarked:
- Association Rules Mining (Apriori & FP-Growth) — Market Basket Analysis style, measuring support, confidence, and lift
- Naive Bayes — probabilistic model answering "What is the probability a user buys item X and item Y?"
- KNN — used as a complementary model to fill recommendation gaps left by Apriori/FP-Growth
This type of recommendation system is used in production by Amazon, Booking.com, and major airline platforms.
├── The Final Project with Apriori & Fp-Growth Models.ipynb # Main notebook (full pipeline)
├── The Final Project with Apriori & Fp-Growth Models (2).ipynb # Refined version
├── The Final Project with Apriori & Fp-Growth Models (3).ipynb # Extended version
├── Naive_Bayes_Model_Recommender_System.ipynb # Standalone Naive Bayes notebook
├── NB Model.ipynb # NB evaluation & scoring
├── README.md
└── Data/
├── superstore.csv # Source: Global Superstore dataset
└── recommendations_df.csv # Generated output: per-user recommendations
Global Superstore Dataset
Available on Kaggle: ronysoliman/global-superstore-dataset
| Feature | Description |
|---|---|
CustomerID |
Unique customer identifier |
ProductName |
Name of the ordered product |
Quantity |
Units ordered (used to derive Rating) |
Sales |
Revenue from the order |
Profit |
Profit from the order |
Discount |
Discount applied |
ShipMode |
Shipping method |
Segment |
Customer segment (Consumer / Corporate / Home Office) |
Market |
Geographic market (US, EU, APAC, etc.) |
OrderPriority |
Order urgency level |
OrderDate / ShipDate |
Used to derive DaysofOrderPreparation |
Engineered features:
Rating— min-max scaled fromQuantityto a 1–10 rating scaleDaysofOrderPreparation— difference in days between order and ship dates- One-hot encoded
Marketcolumns - Label encoded
ShipMode,Segment,OrderPriority
- Renamed columns, parsed dates, dropped PII fields (
CustomerName) and redundant columns - Cleaned
CustomerIDby stripping hyphens - Built
Ratingcolumn fromQuantityusing min-max normalisation to a 1–10 scale - Applied one-hot encoding for
Marketand label encoding for ordinal fields - Produced masked correlation heatmap —
SalesandShippingCostshow strongest correlation withRating
Approach:
- Built a customer × product pivot table (Rating values)
- Converted ratings to binary (1 = purchased, 0 = not purchased)
- Applied
mlxtend.frequent_patterns.aprioriwithmin_support=0.001 - Generated association rules using
liftas the metric
"Staples" handling:
- "Staples" dominated all itemsets due to high purchase frequency
- Re-ran Apriori excluding "Staples" to surface unique product bonds
Performance metrics visualised:
- Support distribution (binned: Average / Above Average / Strong)
- Confidence distribution (up to 28%)
- Lift ratio (up to 34x)
- Antecedent & consequent support distributions
Network diagram: built with networkx connecting antecedents → consequents for the top 15 rules
KNN gap-filling:
Users without Apriori-generated recommendations were filled using KNeighborsClassifier (k=23) trained on encoded product pairs
- Same pipeline as Apriori but using
mlxtend.frequent_patterns.fpgrowth - Faster than Apriori on large datasets (tree-based frequent pattern mining)
- "Staples" excluded and unique itemsets extracted
- KNN (k=23) used identically for recommendation gap-filling
- Final output: per-customer
main_recommendation+recommendationcolumns
Pipeline:
- Built user × product interaction matrix
- Applied TruncatedSVD (17 components) to reduce dimensionality
- Clustered users into 17 groups using K-Means
- Trained a separate MultinomialNB model per cluster
- Predicted interaction probability for every user × item pair
- Applied a 0.50 probability threshold to filter recommendations
- Exported recommendations to
recommendations_df.csv
Evaluation:
- Extracted top-3 recommended items per user for accuracy scoring
- Scored using
accuracy_score,precision_score,recall_scorefrom scikit-learn
| Metric | Apriori | FP-Growth | Naive Bayes |
|---|---|---|---|
| Algorithm type | Association Rules | Association Rules | Probabilistic ML |
| Min support threshold | 0.1% | 0.1% | — |
| Gap-filling method | KNN (k=23) | KNN (k=23) | Cluster-based NB |
| Accuracy | measured | measured | measured |
| Speed | slower | faster | depends on cluster size |
FP-Growth is generally faster than Apriori on large datasets due to its tree-based structure avoiding repeated dataset scans.
| Visual | Purpose |
|---|---|
| Treemap (top 50 countries by rating) | Geographic demand overview |
| Masked correlation heatmap | Feature relationship analysis |
| Bar charts (support / confidence / lift bins) | Apriori performance metric distributions |
| Network diagram (antecedents → consequents) | Top-15 association rule connections |
| Elbow method (K-Means) | Optimal cluster count selection |
| Tool | Purpose |
|---|---|
pandas / numpy |
Data wrangling and feature engineering |
matplotlib / seaborn |
Visualisation |
plotly |
Interactive treemap |
mlxtend |
Apriori, FP-Growth, association rules |
scikit-learn |
KNN, KMeans, TruncatedSVD, MultinomialNB, metrics |
networkx |
Association rule network diagram |
-
Download the dataset from Kaggle:
-
Install dependencies:
pip install pandas numpy matplotlib seaborn plotly mlxtend scikit-learn networkx- Run notebooks in this order:
1. The Final Project with Apriori & Fp-Growth Models (2).ipynb ← Main pipeline
2. Naive_Bayes_Model_Recommender_System.ipynb ← Generates recommendations_df.csv
3. NB Model.ipynb ← Evaluation & scoring
| Video | Link |
|---|---|
| Recommendation Systems Tutorial (Part One) | YouTube ↗ |
| Why Naive Bayes is still relevant in 2024? | YouTube ↗ |
- "Staples" dominates Apriori/FP-Growth itemsets due to its high purchase frequency — the analysis is re-run excluding it to surface meaningful product associations
- The dataset is imbalanced across markets — some regions have significantly more records than others, which may bias recommendations toward high-volume markets
- The Naive Bayes model trains one model per user cluster (17 total), which is memory-intensive on large datasets
- KNN gap-filling assumes similar customers have similar preferences — performance depends on the density of the training set
- The
min_support=0.001threshold is intentionally low to accommodate the long product name strings in this dataset
Independent research project — designed and built as a dissertation-level exploration of recommendation system architectures using real-world retail data.
YouTube Channel: RonyMLE