0% found this document useful (0 votes)
8 views13 pages

E-Commerce Delivery Time Prediction

Uploaded by

nimitbharti235
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views13 pages

E-Commerce Delivery Time Prediction

Uploaded by

nimitbharti235
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Dr.

Akhilesh Das Gupta Institute of


Professional Studies

Department of Electronics and Communication Engineering


Project Based Learning Classes Activity
/ Group Discussions

Name of Faculty: MR. Varun Jain

Subject: Machine Learning


Class: T13
Topic: E-Commerce Product Delivery
pridiction
No. of Students: 2
Name of students:
1. Akash (04396202822)
2. Vipul Bharti (00496207323)
INTODUCTION
In the fast-paced world of e-commerce, predicting product delivery times and optimizing logistics is
crucial for customer satisfaction and business success. This involves leveraging data analytics and
predictive modeling to anticipate potential delays and ensure timely deliveries, ultimately
enhancing the overall customer experience.
Here's a more detailed explanation:

 The Importance of Accurate Delivery Predictions:


o Customer Satisfaction: Timely and accurate delivery is a key factor in customer
satisfaction, which directly impacts customer retention and loyalty.
o Operational Efficiency: Predicting delivery times allows businesses to optimize
their logistics operations, reduce costs, and improve efficiency.
o Competitive Advantage: Businesses that can consistently deliver products on
time gain a significant competitive advantage in the e-commerce market.
 Data Analytics and Predictive Modeling:
o Data Collection: E-commerce businesses collect vast amounts of data related to
orders, shipping, customer behavior, and external factors (e.g., weather, traffic).
o Data Analysis: This data is analyzed to identify patterns, trends, and correlations
that can be used to predict future delivery times.
o Predictive Models: Machine learning algorithms and other predictive models are
used to forecast delivery times based on historical data and identified patterns.
 Factors Influencing Delivery Predictions:
o Order Details: Order size, product type, and shipping method can influence
delivery time.
o Customer Location: Distance and location-specific factors (e.g., traffic, weather)
can affect delivery times.
o Shipping Carrier: The chosen shipping carrier and its performance track record
play a crucial role in delivery accuracy.
o External Factors: Unexpected events like weather conditions, holidays, or
logistical disruptions can also impact delivery times.
 Benefits of Accurate Delivery Prediction :-
o Improved Customer Experience: Accurate delivery predictions allow
businesses to provide customers with realistic and reliable delivery timelines,
reducing frustration and enhancing the overall shopping experience.
o Optimized Logistics: By predicting potential delays, businesses can proactively
address issues and optimize their logistics operations to ensure timely deliveries.
o Reduced Costs: Accurate predictions can help businesses reduce costs associated
with late deliveries, such as refunds, returns, and lost sales.
o Enhanced Customer Loyalty: Consistent and reliable deliveries build trust and
loyalty among customers, leading to increased repeat business.
E-COMMERCE PRODUCT DELIVERY PRIDICTION

# Context
The company, specializing in electronic products, seeks insights from its customer database to optimize
delivery performance and enhance customer satisfaction .
# Data Description
The dataset comprises 10999 observations across 12 variables, detailing customer interactions, product
characteristics, and delivery outcomes. Key variables include:

- Warehouse block

- Mode of shipment

- Customer care calls

- Product cost

- Prior purchases

- Product importance

- Delivery performance (target variable)

# Methodology
Data Preprocessing: Cleaned and prepared data, handling missing values, duplicates, and irrelevant
columns.

Exploratory Data Analysis (EDA): Investigated distribution of variables, customer behavior, and
logistics factors using visualizations.

Feature Engineering: Transformed categorical variables using label encoding.

Model Building: Deployed machine learning models like Random Forest, Decision Tree, Logistic
Regression, and KNN to predict delivery outcomes.

Model Evaluation: Assessed models based on accuracy, confusion matrix, and classification reports.

# Model performance
Decision Tree Classifier demonstrated the highest accuracy at 69%.Random Forest and Logistic
Regression showed comparable performance, with accuracies around 68% and 67%..KNN had the lowest
accuracy at 65%
E-Commerce Product Delivery Prediction
The aim of this project to predict whether the product from an e-commerce company
will reach on time or not. This project also analyzes various factors that affect the delivery
of the product as well as studies the customer behavior.

Context
An international e-commerce company based wants to discover key insights from their
customer database. They want to use some of the most advanced machine learning
techniques to study their customers. The company sells electronic products.

Data Dictionary
The dataset used for model building contained 10999 observations of 12 variables. The
data contains the following information:

Variable Description

ID ID Number of Customers

The Company have big Warehouse which is divided into block such as
Warehouse_block
A,B,C,D,E

The Company Ships the products in multiple way such as Ship, Flight
Mode_of_Shipment
and Road

Customer_care_calls The number of calls made from enquiry for enquiry of the shipment

The company has rated from every customer. 1 is the lowest (Worst),
Customer_rating
5 is the highest (Best)

Cost_of_the_Product Cost of the Product in US Dollars

Prior_purchases The Number of Prior Purchase

The company has categorized the product in the various parameter


Product_importance
such as low, medium, high

Gender Male and Female

Discount_offered Discount offered on that specific product

Weight_in_gms It is the weight in grams

It is the target variable, where 1 Indicates that the product has NOT
[Link].Time_Y.N
reached on time and 0 indicates it has reached on time

In [ ]: #Importing the libraries


import numpy as np
import pandas as pd
import [Link] as plt
import seaborn as sns
In [ ]: #Loading the dataset
df = pd.read_csv('E_Commerce.csv')
[Link]()

Out[ ]: ID Warehouse_block Mode_of_Shipment Customer_care_calls Customer_rating Cos

0 1 D Flight 4 2

1 2 F Flight 4 5

2 3 A Flight 2 2

3 4 B Flight 3 3

4 5 C Flight 2 2

Data Preprocessing 1
In [ ]: #Checking the shape of the dataset
[Link]

Out[ ]: (10999, 12)

In [ ]: #Checking data types of the columns


[Link]

Out[ ]: ID int64
Warehouse_block object
Mode_of_Shipment object
Customer_care_calls int64
Customer_rating int64
Cost_of_the_Product int64
Prior_purchases int64
Product_importance object
Gender object
Discount_offered int64
Weight_in_gms int64
[Link].Time_Y.N int64
dtype: object

Dropping column ID because it is an index column

In [ ]: #Drop column
[Link](['ID'], axis=1, inplace=True)

In [ ]: #Checking for null/missing values


[Link]().sum()
Out[ ]: Warehouse_block 0
Mode_of_Shipment 0
Customer_care_calls 0
Customer_rating 0
Cost_of_the_Product 0
Prior_purchases 0
Product_importance 0
Gender 0
Discount_offered 0
Weight_in_gms 0
[Link].Time_Y.N 0
dtype: int64

In [ ]: #Checking for duplicate values


[Link]().sum()

Out[ ]: 0

Descriptive Statistics

In [ ]: [Link]()

Out[ ]: Customer_care_calls Customer_rating Cost_of_the_Product Prior_purchases Disc

count 10999.000000 10999.000000 10999.000000 10999.000000

mean 4.054459 2.990545 210.196836 3.567597

std 1.141490 1.413603 48.063272 1.522860

min 2.000000 1.000000 96.000000 2.000000

25% 3.000000 2.000000 169.000000 3.000000

50% 4.000000 3.000000 214.000000 3.000000

75% 5.000000 4.000000 251.000000 4.000000

max 7.000000 5.000000 310.000000 10.000000

In [ ]: [Link]()

Out[ ]: Warehouse_block Mode_of_Shipment Customer_care_calls Customer_rating Cost_of_

0 D Flight 4 2

1 F Flight 4 5

2 A Flight 2 2

3 B Flight 3 3

4 C Flight 2 2
Exploratory data analysis
Train Test Split
In [ ]: from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split([Link]('[Link].Time_Y.N

I will be using the following models to predict the product delivery :

Random Forest Classifier


Decision Tree Classifier
Logistic Regression
K Nearest Neighbors
Random Forest Classifier

In [ ]: from [Link] import RandomForestClassifier

#Random Forest Classifier Object

rfc = RandomForestClassifier()

In [ ]: #Using GridSearchCV for hyperparameter tuning

from sklearn.model_selection import GridSearchCV

#Parameter grid

param_grid = {'max_depth': [4,8,12,16],

'min_samples_leaf': [2,4,6,8],

'min_samples_split': [2,4,6,8],
'criterion': ['gini', 'entropy'],
'random_state': [0,42] }

#GridSearchCV object

grid = GridSearchCV(estimator=rfc, param_grid=param_grid, cv=5, n_jobs=-1, verbo

#Fitting the model

[Link](X_train, y_train)

#Best parameters

print('Best parameters: ', grid.best_params_)

Fitting 5 folds for each of 256 candidates, totalling 1280 fit Best parameters:
{'criterion': 'gini', 'max_depth': 8, 'min_samples_leaf': 8, 'm in_samples_split':
2, 'random_state': 42}

In [ ]: #Random Forest Classifier Object

rfc = RandomForestClassifier(criterion='gini', max_depth=8, min_samples_leaf=8,

#Fitting the model

[Link](X_train, y_train)

Out[ ]: ▾ RandomForestClassifier
RandomForestClassifier(max_depth=8, min_samples_leaf=8, random_state=4
2)
#Training accuracy

In [ ]: print('Training accuracy: ', [Link](X_train, y_train))

Training accuracy: 0.7253096942834413

In [ ]: #predicting the test set results


rfc_pred = [Link](X_test)

Decision Tree Classifier

#Decision Tree Classifier Object


In [ dtc
]: from [Link] import DecisionTreeClassifier
= DecisionTreeClassifier(criterion='gini', max_depth=6, min_samples_leaf=6,

#Fitting the model


#Decision Tree Classifier Object
dtc = DecisionTreeClassifier()
[Link](X_train, y_train)

In [ ]: #Using GridSearchCV for hyperparameter tuning


from sklearn.model_selection import GridSearchCV
#Parameter grid
param_grid = {
'max_depth': [2,4,6,8],
'min_samples_leaf': [2,4,6,8],
'min_samples_split': [2,4,6,8],
'criterion': ['gini', 'entropy'],
'random_state': [0,42]}

#GridSearchCV object

grid = GridSearchCV(estimator=dtc, param_grid=param_grid, cv=5, n_jobs=-1, verbo

#Fitting the model

[Link](X_train, y_train)

#Best parameters

print('Best parameters: ', grid.best_params_)

Fitting 5 folds for each of 256 candidates, totalling 1280 fits

Best parameters: {'criterion': 'gini', 'max_depth': 6, 'min_samples_leaf': 6, 'm


in_samples_split': 2, 'random_state': 0}

In [ ]: #Decision Tree Classifier Object

dtc = DecisionTreeClassifier(criterion='gini', max_depth=6, min_samples_leaf=6,

#Fitting the model

[Link](X_train, y_train)

Out[ ]: ▾ DecisionTreeClassifier

DecisionTreeClassifier(class_weight='balanced', max_depth=6, min_sample


s_leaf=6,
#Training accuracy
In [ ]: print('Training accuracy: ', [Link](X_train, y_train))

Training accuracy: 0.6913285600636436

In [ ]: #predicting the test set results


dtc_pred = [Link](X_test)

Logistic Regression

In [ ]: from sklearn.linear_model import LogisticRegression

#Logistic Regression Object


lr = LogisticRegression()

In [ ]: #fitting the model


[Link](X_train, y_train)

Out[ ]: ▾ LogisticRegression

LogisticRegression()

#Training accuracy

In [ ]: [Link](X_train, y_train)

Out[ ]: 0.6356404

#predicting the test set results

lr_pred = [Link](X_test)

K Nearest Neighbors

In [ ]: from [Link] import KNeighborsClassifier

#KNN Classifier Object

In [ ]: #fitting the model

[Link](X_train, y_train)

Out[ ]: ▾ KNeighborsClassifier

KNeighborsClassifier()

In [ ]: #training accuracy

[Link](X_train, y_train)

Out[ ]: 0.778270257983861

#predicting the test set results

knn_pred = [Link](X_test)
Model Evaluation

In [ ]: from [Link] import accuracy_score, confusion_matrix, classification_rep

In [ ]: fig, ax = [Link](2,2,figsize=(15,10))

[Link](confusion_matrix(y_test, rfc_pred), annot=True, cmap='coolwarm', ax


[Link](confusion_matrix(y_test, dtc_pred), annot=True, cmap='coolwarm', ax
[Link](confusion_matrix(y_test, lr_pred), annot=True, cmap='coolwarm', ax=
[Link](confusion_matrix(y_test, knn_pred), annot=True, cmap='coolwarm', ax=

Out[ ]: Text(0.5, 1.0, 'KNN Classifier')

In [ ]: #classification report

print('Random Forest Classifier: \n', classification_report(y_test, rfc_pred))


print('Decision Tree Classifier: \n', classification_report(y_test, dtc_pred))
print('Logistic Regression: \n', classification_report(y_test, lr_pred))

Model Comparison
Out[ ]: Text(0, 0.5, 'Accuracy')

In [ ]: models = ['Random Forest Classifier', 'Decision Tree Classifier', 'Logistic Regr


accuracy = [accuracy_score(y_test, rfc_pred), accuracy_score(y_test, dtc_pred),
[Link](x=models, y=accuracy, palette='magma').set_title('Model Comparison')
[Link](rotation=90)

[Link]('Accuracy')
Random Forest Classifier:
Precision recall f1-score support
0 0.57 0.89 0.70 908
1 0.87 0.54 0.66 1292
Accuracy 0.68 2200
macro avg 0.72 0.71 0.68 2200
weighted avg 0.75 0.68 0.68 2200
Decision Tree Classifier:
precision recall f1-score support
0 0.57 0.97 0.72 908
1 0.95 0.49 0.65 1292
Accuracy 0.69 2200
macro avg 0.76 0.73 0.68 2200
weighted avg 0.80 0.69 0.68 2200
Logistic Regression:
precision recall f1-score support
0 0.55 0.58 0.57 908
1 0.69 0.67 0.68 1292
Accuracy 0.63 2200
macro avg 0.62 0.62 0.62 2200
weighted avg 0.64 0.63 0.63 2200
KNN Classifier:
precision recall f1-score support
0 0.58 0.61 0.59 908
1 0.71 0.68 0.70 1292
Accuracy 0.65 2200
macro avg 0.65 0.65 0.65 2200
weighted avg 0.66 0.65 0.66 2200
Conclusion
The aim of the project was to predict whether the product from an e-commerce
company will reach on time or not. This project also analyzes various factors that
affect the delivery of the product as well as studies the customer behavior. From
the exploratory data analysis, I found that the product weight and cost has an
impact on the product delivery. Where product that weighs between 2500 - 3500
grams and having cost less than 250 dollars had higher rate of being delivered on
time. Most of the products were shipped from warehouse F though ship, so it is
quite possible that warehouse F is close to a sea [Link] customer's behaviour
also help in predicting the timely delivery of the product. The more the customer
calls, higher the chances the product delivery is delayed.
Interestingly, the customers who have done more prior purchases have higher count of
products delivered on time and this is the reason that they are purchasing again
from the company. The products that have 0-10% discount have higher count of
products delivered late, whereas products that have discount more than 10% have
higher count of products delivered on time. Coming to the machine learning
models, the decision tree classifier as the highest accuracy among the other
models, with accuracy of 69%. The random forest classifier and logistic regression
had accuracy of 68% and 67% respectively. The K Nearest
Neighbors had the lowest accuracy of 65%.

Common questions

Powered by AI

The Decision Tree Classifier demonstrated the highest accuracy at predicting e-commerce product delivery outcomes with an accuracy of 69%. Other models like Random Forest and Logistic Regression showed similar performance, with accuracies of 68% and 67%, respectively, while the K Nearest Neighbors (KNN) had the lowest accuracy at 65% . The evaluation of these models involved comparing accuracy rates and determining the effectiveness of each model in anticipating whether products reached on time .

The choice of shipping carrier is critical in influencing prediction accuracy for delivery times. Different carriers have varying performance records and logistical capabilities, which directly affect delivery accuracy and timelines . Effective predictive models incorporate carrier performance data to adjust delivery forecasts, allowing companies to better manage customer expectations and avoid delays . Properly accounting for carrier differences in models can enhance overall prediction accuracy by matching carrier capabilities with delivery requirements .

The methodology involved several key steps: Data Preprocessing, Exploratory Data Analysis (EDA), Feature Engineering, Model Building, and Model Evaluation. Data preprocessing handled missing values, duplicates, and irrelevant columns . EDA investigated customer behavior and logistics factors using visualizations . Feature engineering included transforming categorical variables using label encoding . Various machine learning models such as Random Forest, Decision Tree, Logistic Regression, and KNN were deployed to predict delivery outcomes . Model performance was assessed using accuracy metrics, confusion matrices, and classification reports .

E-commerce companies face challenges such as variable external factors (e.g., weather, traffic), logistics disruptions, and inconsistencies in shipping carrier performance that impact delivery times. Predictive modeling techniques can address these challenges by leveraging data analytics to predict delays and optimize logistics operations . By analyzing vast datasets on customer interactions and historical deliveries, companies can build models that forecast delivery times with higher accuracy and adaptively manage logistical uncertainties .

Machine learning models analyze historical data to identify patterns and trends that influence delivery times. These models, such as Random Forest, Decision Tree, Logistic Regression, and KNN, are used to forecast delivery outcomes by transforming data into predictive insights . The models learn from variables like order details, shipping carrier performance, and external factors, thus helping businesses optimize logistics and predict potential delays with greater accuracy .

Customer interactions, measured through customer care calls, were found to correlate with delivery delays; frequent calls likely indicate complications requiring resolution, contributing to late deliveries . Conversely, customers with more prior purchases experienced higher rates of on-time deliveries, suggesting customer loyalty and purchase history positively influence service prioritization and delivery efficiency. This indicates that trusted repeat customers might be accorded more efficient service, streamlining their delivery processes .

The exploratory data analysis revealed that product weight and cost significantly impact delivery outcomes. Products weighing 2500-3500 grams and costing less than $250 were more often delivered on time . The analysis also showed that frequent customer care calls were associated with delayed deliveries, while customers with more prior purchases had higher rates of on-time deliveries. Additionally, products with higher than 10% discounts were more likely to be delivered on time, indicating that price reductions might positively influence delivery efficiency .

Products delivered on time typically weigh between 2500-3500 grams and cost less than $250 . These characteristics suggest manageable logistics related to handling and costing align with efficient operational capabilities. Products with more than 10% discount also tend to be delivered on time, possibly because they attract more immediate purchasing and logistic accommodation . In contrast, products delivered late often have higher costs, lower weights, or receive smaller discounts, indicating discrepancies in prioritization and logistical adjustments .

Accurate delivery predictions significantly benefit e-commerce businesses by enhancing customer experience, optimizing logistics, reducing costs, and improving customer loyalty. Providing customers with realistic delivery timelines reduces frustration and enhances their shopping experience . Additionally, predicting potential delays allows businesses to address issues proactively and optimize logistics for timely deliveries . By minimizing costs related to late deliveries, businesses can also increase profitability . Consistently reliable deliveries build customer trust, fostering loyalty and repeat business .

Several factors were identified as significantly influencing product delivery outcomes: product weight and cost, the mode of shipping, the frequency of customer care calls, prior purchases, product importance, and discounts offered. For instance, products weighing between 2500-3500 grams and costing less than $250 were more likely to be delivered on time . A higher number of customer calls was associated with delayed deliveries, whereas more prior purchases were linked to timely deliveries . Additionally, products with discounts greater than 10% tended to be delivered on time more often than those with smaller discounts .

You might also like