Skip to content

Repository files navigation

Predictive Analytics for Order Delivery Status

Project Overview

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.

Key Features

  • 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.

The Problem

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.

Data

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).

Methodology

1. Data Cleaning and Preprocessing

  • Data Type Conversion: Converted order_date and shipping_date from 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 StandardScaler to normalize numerical features for model compatibility.

2. Exploratory Data Analysis (EDA)

  • Analyzed the distribution of the target variable label and confirmed a significant class imbalance, with 'Early' deliveries being the majority class.
  • Visualized the relationship between shipping_mode and delivery status, finding that different modes have varying reliability.
  • Examined correlations between numerical features, identifying weak correlations with the target label.

3. Model Building & Evaluation

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

Technical Stack

  • Language: Python 3.x
  • Libraries:
    • pandas for data manipulation and analysis.
    • numpy for numerical operations.
    • scikit-learn for machine learning models and preprocessing.
    • matplotlib and seaborn for data visualization.
    • lightgbm for the LightGBM model.
    • jupyter or Google Colab for the development environment.

Getting Started

To run this project locally, follow these steps:

  1. 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
  2. Install the required libraries:

    pip install -r requirements.txt

    (Note: You will need to create a requirements.txt file listing all the libraries used.)

  3. Run the Jupyter Notebook: Open the main notebook (your_notebook_name.ipynb) to view and execute the full project pipeline.

Future Work

  • 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.

Author

Acknowledgments

  • 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.

About

A data science project to predict and classify order delivery outcomes (Late, On-time, Early) for enhanced logistics and customer satisfaction.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages