This project focuses on building a machine learning model to predict the delivery status of orders: 'Late' (-1), 'On-time' (0), or 'Early' (1). By leveraging historical order and logistical data, this solution aims to provide proactive insights for optimizing supply chain operations, enhancing customer satisfaction, and improving resource allocation. The project employs a complete data science pipeline, from data cleaning and exploratory analysis to model building and evaluation.
- Comprehensive Data Preprocessing: A robust pipeline for handling missing values, temporal data, and categorical features.
- Insightful Exploratory Data Analysis (EDA): Analysis of key factors influencing delivery outcomes, including shipping modes and customer demographics.
- Multi-Class Classification: Development and evaluation of several machine learning models to solve a multi-class prediction problem.
- Performance Evaluation: Detailed analysis of model performance using metrics like Accuracy, F1-Score, and a Confusion Matrix to understand class-specific strengths and weaknesses.
- Actionable Recommendations: Final insights and recommendations for business stakeholders on how to improve logistics based on model findings.
In the e-commerce and logistics industry, delivery timeliness is a critical metric. However, predicting whether an order will be late, on-time, or early is a complex challenge due to a multitude of influencing factors and significant class imbalance in the data. This project addresses this problem by developing a predictive model that can provide an early warning system for potential delivery issues, enabling businesses to take proactive measures.
The dataset used in this project is a collection of historical order data containing various features related to the order, customer, product, and shipping details.
Key features include:
- Order Details:
order_date,shipping_date,order_item_total_amount, etc. - Product Details:
product_price,order_item_quantity. - Customer Details:
customer_segment,customer_city. - Logistics Details:
shipping_mode,delivery_lead_time. - Target Variable:
label, which indicates the delivery status (-1: Late, 0: On-time, 1: Early).
- Data Type Conversion: Converted
order_dateandshipping_datefrom string to datetime objects. - Feature Engineering: Created new temporal features (
order_year,order_month,delivery_lead_time) to capture patterns. - Handling Missing Data: Imputed missing values in newly created features using the median.
- Outlier Analysis: Performed IQR analysis on numerical features, noting the data's wide distribution.
- Categorical Encoding: Applied One-Hot Encoding to key categorical features (
payment_type,shipping_mode,customer_segment). - Feature Scaling: Used
StandardScalerto normalize numerical features for model compatibility.
- Analyzed the distribution of the target variable
labeland confirmed a significant class imbalance, with 'Early' deliveries being the majority class. - Visualized the relationship between
shipping_modeand delivery status, finding that different modes have varying reliability. - Examined correlations between numerical features, identifying weak correlations with the target
label.
Three different machine learning models were trained on the preprocessed, imbalanced dataset:
- Logistic Regression: Served as a baseline model.
- Random Forest Classifier: A powerful ensemble model.
- LightGBM Classifier: A high-performance gradient boosting model.
The Random Forest Classifier was selected as the final model due to its superior performance balance across all classes, especially its ability to better predict 'Late' and 'On-time' deliveries compared to the other models.
Final Model Performance (on Test Set):
| Metric | Score |
|---|---|
| Accuracy | 0.5839 |
| Weighted F1 Score | 0.5424 |
| F1 (-1: Late) | 0.43 |
| F1 (0: On-time) | 0.14 |
| F1 (1: Early) | 0.72 |
- Language:
Python 3.x - Libraries:
pandasfor data manipulation and analysis.numpyfor numerical operations.scikit-learnfor machine learning models and preprocessing.matplotlibandseabornfor data visualization.lightgbmfor the LightGBM model.jupyterorGoogle Colabfor the development environment.
To run this project locally, follow these steps:
-
Clone the repository:
git clone [https://github.com/your-username/your-repo-name.git](https://github.com/your-username/your-repo-name.git) cd your-repo-name -
Install the required libraries:
pip install -r requirements.txt
(Note: You will need to create a
requirements.txtfile listing all the libraries used.) -
Run the Jupyter Notebook: Open the main notebook (
your_notebook_name.ipynb) to view and execute the full project pipeline.
- Address Class Imbalance: Implement advanced techniques like SMOTE or use
class_weight='balanced'to improve performance on the 'On-time' class. - Advanced Models: Experiment with more sophisticated models like XGBoost and CatBoost.
- Error Analysis: Conduct a deeper analysis of misclassified samples to understand the model's blind spots.
- Hyperparameter Tuning: Perform a more extensive hyperparameter tuning search for the final model.
- Emmanuel Itighise [https://ng.linkedin.com/in/emmanuel-itighise-a51633189]
- This project was completed as part of the 3 Million Technical Talents (3mtt) program.
- Special thanks to Darey.io for their invaluable guidance and mentorship.