Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Order to Delivery (OTD) Time Forecasting

Order to Delivery (OTD) Time Forecasting

  • Ease of e-commerce over the last decade, along with the recent COVID-19 pandemic, has seen a marked shift in consumer behavior and expectations when it comes to purchase - and more importantly, the delivery of goods. This has caused a paradigm shift in functioning of the supply chain. Along with delivery speed, consumers feel that the transparency around delivery time and shipment status are an equally important aspect of the fulfilment process. This has direct implications in customer churn/retention. More than half of consumers are less likely to shop with a retailer if the item is not delivered within 2 days of date promised. (source)

Order to Delivery Time Forecasting as a Supply Chain Optimization Usecase:

OTD forecasting is a key aspect of supply chain optimization as it helps to ensure that customers receive their products in a timely manner, it enables companies to make informed decisions about inventory, logistics and production which in turn helps to improve the overall efficiency of the supply chain.

AI Project Cycle AI_Project_Cycle.png

Context: Understanding the Problem Statement --------Problem Scoping (AI Project Cycle - Step 1)

An ML based predictive solution for providing delivery time forecasting

  • An ML based predictive solution for providing delivery time forecasting can provide great insights to e-commerce platforms. From a customer-facing point of view these insights would help e-commerce platforms to give more accurate delivery forecasts to customers and decrease customer churn. In addition, the ML based predictive solution will also allow e-commerce platforms to take pre-emptive actions to mitigate delays, costs, and loss of revenue.

  • For the individual components of the ensemble model, we will use XGB, RF and SVM. These components will then be fed to a Voting Model, which is an ensemble model that combines the individual predictions to provide a final, consensus prediction. The final consensus prediction can be (1) a prediction for a wait time for a package and (2) if a delay will occur. To learn more about the XGB Click here, whereas for the random forest click here and SVM click here

e2e-flow_stock

To learn more about XGBoost click here

To learn about math module click here

To learn about scikit learn’s model selection module clickhere

Dataset: Data Acquisition (AI Project Cycle - Step 2)

Dataset downloading steps

DataSet: https://www.kaggle.com/datasets/olistbr/brazilian-ecommerce

“brazilian-ecommerce.zip” will get downloaded in the current data folder folderd
In the data folder execute the following command to unzip (Note: You may need to install unzip using: sudo apt-get install unzip) unzip brazilian-ecommerce.zip

Source - Before we delve into the proposed architecture of the solution pipeline, it is critical to understand the dataset and its schema. The dataset consists of real-world delivery details sourced from a Brazilian E-commerce Company which was scrubbed and anonymized. It can be found here.

It consists of multiple tables which include relevant information about the customer, seller, order, location etc. The individual tables are interconnected as shown in the following schema. Relevant features will be extracted/designed from this data and then be used to train our supervised ML model.

dataset-schema

Load/Read the Dataset

View the data

From a business perspective, we need to tackle two main challenges to ensure transparency for the customer:

  1. Extracting insights/estimates into forecasted delivery

  2. Increasing the accuracy of those insights and estimates

We can achieve the first objective by implementing multiple pipelines with separate objectives and the second one by utilizing techniques such as ensemble modeling to increase the accuracy of stand-alone ML components.

**A schematic of the proposed reference architecture is shown in the following figure. We start off with Data Ingestion from the multiple tables of the dataset, followed by merging and preprocessing for feature extraction. We can use the features to extract delivery insights in the form of predicted wait time as well as likelihood of delivery delay.

The former is a regression problem and the latter is a classification problem.

Data Preprocessing ------ Data Exploration(AI Project Cycle - Step 3)

View the information of data

Merge/Clean Data

Find the total number of missing values feature wise

Scaling the data

Splitting dataset into separate training and test set

Building a Model ------ Modeling ( AI Project Cycle - Step 4)

We will now use the sklearn library to build the model. We will begin by defining the hyperparameters and determining the best fit model. We will be comparing the accuracy of three models, namely Support Vector Machine (SVM), Random Forest, XGBoost.

What are Hyperparameters? • A hyperparameter is a parameter whose value is set before the learning process begins

• Algorithm hyperparameters affect the speed and quality of the learning process

• Hyperparameters are important because they can have a direct impact on the behaviour of the training algorithm and have a
significant impact on the performance of the model being trained

Examples - Number of epochs, number of clusters, batch size etc

Performing hyperparameter tuning

As shown below, we are trying to find which algorithm should be used to build the model and which hyperparameters would contribute to better performance:

In this case, C(adds penalty to each misclassified point) and kernel are the hyperparameters of SVM

n_estimators(this specifies the number of trees you want to build before taking the maximum voting or averages of predictions. Higher number of trees give you better performance but makes your code slower) - hyperparameter for random forest

C(logistic regression) large values of C give more freedom to the model. Conversely, smaller values of C constrain the model more

ensemble

Training the Ensemble Model

Saving the machine learning models

The code below trains and tests a voting regressor model using a dataset called ti_test_section, saves the trained model to a file using the pickle module, and evaluates the average inference time for the model.

Evaluating the Model ------- Evaluation (AI Project Cycle - Step 5)

Testing the Ensemble Model

Few questions on Interpreting MSE of an Machine Learning Model

Q1. What is a good MSE value for a machine learning model?

Q2. Can MSE be negative?

Q3. Is MSE affected by outliers in the data?