Skip to content

Arshpreet-Singh-2005/supply-chain-risk-intellignce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

9 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ฆ Supply Chain Risk Intelligence

Multi-class Delivery Risk Prediction using Machine Learning

Python Gradio XGBoost SMOTE License


๐ŸŽฏ Project Overview

This project develops a Multi-class Machine Learning Classification System for Supply Chain Risk Intelligence using the DataCo Supply Chain Dataset. The system predicts delivery outcomes for e-commerce orders in real-time and triggers automated Agentic Interventions based on the prediction.

The goal is to improve operational efficiency, reduce logistics costs, and enhance customer satisfaction by identifying delivery risks before they occur.


๐Ÿšš Delivery Outcome Classes

The model classifies each order into one of four delivery outcomes:

Class Description Trigger
๐Ÿšจ Late Delivery Order exceeded scheduled delivery date Actual vs Scheduled = +1 to +4
โœ… Shipping On Time Order delivered within scheduled timeline Actual vs Scheduled = 0
โšก Advance Shipping Order delivered ahead of schedule Actual vs Scheduled = -1 or -2
โŒ Shipping Canceled Order canceled before delivery Rare class

๐Ÿ“Š Model Performance

Four machine learning algorithms were trained and compared:

Algorithm Accuracy F1-Score Notes
๐Ÿฅ‡ KNN 92.2% 0.919 Best performer
๐Ÿฅˆ XGBoost 88.5% 0.886 Strong gradient boosting
๐Ÿฅ‰ Random Forest 87.4% 0.902 Best F1 after KNN
Logistic Regression 79.5% 0.847 Baseline linear model

Key Finding: KNN outperformed ensemble methods suggesting delivery outcomes are highly dependent on local patterns among similar orders rather than complex global decision boundaries.


๐Ÿ› ๏ธ Tech Stack

Category Tools
Language Python 3.10+
Data Processing Pandas, NumPy
Machine Learning Scikit-learn, XGBoost
Class Balancing imbalanced-learn (SMOTE)
Explainability SHAP
Visualization Matplotlib, Seaborn
Deployment Gradio
Model Serialization Joblib
Environment Google Colab

๐Ÿ“ Project Structure

supply-chain-risk-intelligence/
โ”‚
โ”œโ”€โ”€ app.py                          โ† Gradio dashboard (main UI)
โ”œโ”€โ”€ training_pipeline.py            โ† Full training pipeline
โ”œโ”€โ”€ requirements.txt                โ† Python dependencies
โ”œโ”€โ”€ README.md                       โ† Project documentation
โ”‚
โ”œโ”€โ”€ models/
โ”‚   โ”œโ”€โ”€ Model files are hosted on Google Drive (too large for GitHub)
โ”‚   โ”œโ”€โ”€ Download here:https://drive.google.com/drive/u/0/folders/141bQgsJoSovQI5vVp0NYh8sm1Ksj7sKi 
โ”‚
โ””โ”€โ”€ notebooks/
    โ””โ”€โ”€ Supply_Chain_Intelligence.ipynb โ† Google Colab notebook

๐Ÿ”ง Installation & Setup

1. Clone the Repository

git clone https://github.com/YOURUSERNAME/supply-chain-risk-intelligence.git
cd supply-chain-risk-intelligence

2. Install Dependencies

pip install -r requirements.txt

3. Download the Dataset

Download the DataCo Supply Chain Dataset from Kaggle: ๐Ÿ‘‰ DataCo Supply Chain Dataset on Kaggle

Place the CSV file in the root directory:

DataCoSupplyChainDataset.csv

4. Download Trained Models

Model .pkl files exceed GitHub's 25MB limit and are hosted on Google Drive.

๐Ÿ‘‰ Download All Model Files from Google Drive

After downloading place all .pkl files in the root directory.

OR skip this step and train from scratch:

5. Launch the Dashboard

python app.py

A public Gradio URL will be printed in the terminal. Open it in any browser.


๐Ÿ—ƒ๏ธ Dataset Overview

Property Value
Dataset DataCo Supply Chain
Total Rows 134,453 orders
Input Features 7
Target Variable Delivery Status (4 classes)
Encoding ISO-8859-1

๐Ÿง  Feature Engineering

Feature Description Type
Type Order type Categorical (encoded)
Days for shipment (scheduled) Planned delivery window Numeric
Shipping Mode First Class, Same Day, Second Class, Standard Categorical (encoded)
Order Region Geographic region Categorical (encoded 0โ€“4)
Order Item Product Price Price of ordered item in USD Numeric
Order Item Quantity Number of units in order Numeric
Actual_vs_Scheduled โญ Engineered: Actual days โˆ’ Scheduled days Numeric

โญ Actual_vs_Scheduled is the most critical feature. It directly measures deviation from the delivery plan. Positive = late, Zero = on time, Negative = early.


โš™๏ธ Data Preprocessing Pipeline

1. Load CSV (134,453 rows, ISO-8859-1 encoding)
        โ†“
2. Feature Engineering (Create Actual_vs_Scheduled)
        โ†“
3. Handle Missing Values (Replace inf/NaN with median)
        โ†“
4. Label Encoding (Type, Shipping Mode, Order Region, Target)
        โ†“
5. Train-Test Split (80/20, random_state=42, stratify=y)
        โ†“
6. SMOTE Balancing (Oversample minority classes in training set)
        โ†“
7. Model Training & Evaluation

๐Ÿค– Agentic Intervention System

The dashboard automatically triggers intervention actions based on prediction:

๐Ÿšจ Late Delivery โ€” HIGH RISK

โ†’ Warehouse Priority Flag ........... ACTIVE
โ†’ Customer delay notification ....... DISPATCHED
โ†’ Carrier escalation protocol ....... INITIATED
โ†’ SLA breach alert .................. SENT TO OPS

โœ… Shipping On Time โ€” LOW RISK

โ†’ Standard logistics monitoring ..... ACTIVE
โ†’ SLA compliance .................... WITHIN BOUNDS
โ†’ Carrier status .................... NOMINAL

โšก Advance Shipping โ€” EARLY DELIVERY

โ†’ Warehouse receiving alert ......... SENT
โ†’ Early arrival notification ........ DISPATCHED
โ†’ Customer notified ................. ACTIVE
โ†’ Storage slot pre-assigned ......... CONFIRMED

โŒ Shipping Canceled

โ†’ Order flagged for review .......... ACTIVE
โ†’ Customer refund initiated ......... PROCESSING
โ†’ Inventory restocked ............... PENDING

๐Ÿ–ฅ๏ธ Dashboard Interface

Input Parameters

  • Algorithm โ€” Select ML model (XGBoost, Random Forest, KNN, Logistic Regression)
  • Scheduled Shipment Days โ€” Planned delivery window (0โ€“10)
  • Actual vs Scheduled Days โ€” Key feature slider (-2 to +4)
  • Shipping Mode โ€” First Class, Same Day, Second Class, Standard Class
  • Order Region โ€” Encoded region (0โ€“4)
  • Product Price โ€” Item price in USD
  • Order Quantity โ€” Number of units

Output Panels

  • Status โ€” Predicted delivery outcome with risk indicator
  • Detail โ€” Model confidence score and accuracy
  • Agentic Action Log โ€” Automated intervention steps
  • Risk Indicator โ€” Visual bar showing risk level
  • Input Feature Vector โ€” Exact values sent to model for transparency

Quick Reference โ€” Try These Parameters

Outcome Actual vs Scheduled Shipping Mode
๐Ÿšจ Late Delivery +2 to +4 Standard Class
โœ… On Time 0 Any
โšก Early Delivery -1 or -2 First Class

๐Ÿ“ˆ Evaluation Metrics

Confusion Matrices

Plotted for all 4 models in a 2ร—2 grid. Darker diagonal = better performance.

ROC Curves

Macro-average ROC curves for all models.

  • KNN AUC: ~0.97
  • Random Forest AUC: ~0.96
  • XGBoost AUC: ~0.95
  • Logistic Regression AUC: ~0.91

SHAP Explainability

SHAP TreeExplainer used on Random Forest to rank feature importance globally. Actual_vs_Scheduled is the dominant predictor.


๐Ÿ’ก Key Design Decisions

Decision Reason
Gradio over Streamlit Avoids localtunnel/ngrok issues, instant public URL with share=True
SMOTE over class weighting Better synthetic minority representation
Saved label_encoder.pkl separately Maps numeric predictions back to real class names in dashboard
random_state=42 everywhere Ensures reproducible results across all runs
encoding_errors='replace' Loads all 134K rows without dropping rows with special characters

๐Ÿ”ฎ Future Improvements

  • Add weather data and carrier performance as features
  • Implement real-time order feed from live database
  • Add SHAP waterfall plots for individual order explainability
  • Deploy on cloud platform (AWS/GCP) for 24/7 availability
  • Add email/SMS notification integration for agentic actions
  • Build REST API endpoint for integration with order management systems

๐Ÿ“š References


๐Ÿ‘ค Author

Your Name


๐Ÿ“„ License

This project is licensed under the MIT License. See LICENSE for details.


Built with โค๏ธ for Supply Chain Intelligence
DataCo Dataset ยท SMOTE Balanced ยท Agentic Intervention System ยท ML v2.0

About

Multi-class delivery risk prediction system using XGBoost, Random Forest, KNN and Logistic Regression on DataCo Supply Chain Dataset with real-time Gradio dashboard and agentic intervention system.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors