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.
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 |
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.
| 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 |
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
git clone https://github.com/YOURUSERNAME/supply-chain-risk-intelligence.git
cd supply-chain-risk-intelligencepip install -r requirements.txtDownload the DataCo Supply Chain Dataset from Kaggle: ๐ DataCo Supply Chain Dataset on Kaggle
Place the CSV file in the root directory:
DataCoSupplyChainDataset.csv
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:
python app.pyA public Gradio URL will be printed in the terminal. Open it in any browser.
| 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 | 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.
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
The dashboard automatically triggers intervention actions based on prediction:
โ Warehouse Priority Flag ........... ACTIVE
โ Customer delay notification ....... DISPATCHED
โ Carrier escalation protocol ....... INITIATED
โ SLA breach alert .................. SENT TO OPS
โ Standard logistics monitoring ..... ACTIVE
โ SLA compliance .................... WITHIN BOUNDS
โ Carrier status .................... NOMINAL
โ Warehouse receiving alert ......... SENT
โ Early arrival notification ........ DISPATCHED
โ Customer notified ................. ACTIVE
โ Storage slot pre-assigned ......... CONFIRMED
โ Order flagged for review .......... ACTIVE
โ Customer refund initiated ......... PROCESSING
โ Inventory restocked ............... PENDING
- 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
- 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
| Outcome | Actual vs Scheduled | Shipping Mode |
|---|---|---|
| ๐จ Late Delivery | +2 to +4 | Standard Class |
| โ On Time | 0 | Any |
| โก Early Delivery | -1 or -2 | First Class |
Plotted for all 4 models in a 2ร2 grid. Darker diagonal = better performance.
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 TreeExplainer used on Random Forest to rank feature importance globally. Actual_vs_Scheduled is the dominant predictor.
| 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 |
- 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
- DataCo Supply Chain Dataset โ Kaggle
- SMOTE Paper โ Chawla et al. 2002
- XGBoost Documentation
- SHAP Documentation
- Gradio Documentation
Your Name
- GitHub: @Arshpreet-Singh-2005
- LinkedIn: Arshpreet Singh
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