0% found this document useful (0 votes)
6 views28 pages

Food Delivery - Python

This document presents a study on food delivery time prediction using machine learning, highlighting the growth of the online food delivery (OFD) market, especially accelerated by COVID-19. It includes a systematic literature review of 43 articles, identifying six potential research themes and four knowledge clusters related to OFD. The research emphasizes the importance of accurate delivery time predictions for enhancing customer satisfaction and operational efficiency in the food delivery industry.

Uploaded by

Munzir Hassan
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)
6 views28 pages

Food Delivery - Python

This document presents a study on food delivery time prediction using machine learning, highlighting the growth of the online food delivery (OFD) market, especially accelerated by COVID-19. It includes a systematic literature review of 43 articles, identifying six potential research themes and four knowledge clusters related to OFD. The research emphasizes the importance of accurate delivery time predictions for enhancing customer satisfaction and operational efficiency in the food delivery industry.

Uploaded by

Munzir Hassan
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

Food Delivery Time Prediction with Machine

Learning using Python.

B. Tech in Computer Science and Engineering

SUBMITTED BY- MUNZIR HASSAN

SUPERVISOR- VED PRAKASH CHAUBEY

1
ABSTRACT
Purpose Online food delivery (OFD) has witnessed momentous consumer adoption in the
past few years, and COVID-19, if anything, is only accelerating its growth. This paper
captures numerous intricate issues arising from the complex relationship among the
stakeholders because of the enhanced scale of the OFD business. The purpose of this
paper is to highlight publication trends in OFD and identify potential future research
themes. Design/methodology/approach the authors conducted a tri-method study –
systematic literature review, bibliometric and thematic content analysis – of 43 articles on
OFD published in 24 journals from 2015 to 2021 (March). The authors used VOS viewer
to perform citation analysis. Findings Systematic literature review of the existing OFD
research resulted in six potential research themes. Further, thematic content analysis
synthesized and categorized the literature into four knowledge clusters, namely, (i) digital
mediation in OFD, (ii) dynamic OFD operations, (iii) OFD adoption by consumers and (iv)
risk and trust issues in OFD. The authors also present the emerging trends in terms of the
most influential articles, authors and journals. Practical implications This paper captures
the different facets of interactions among various OFD stakeholders and highlights the
intricate issues and challenges that require immediate attention from researchers and
practitioners. Originality/value This is one of the few studies to synthesize OFD literature
that sheds light on unexplored aspects of complex relationships among OFD stakeholders
through four clusters and six research themes through a conceptual framework.

2
DECLARATION STATEMENT
I hereby declare that the research work reported in the dissertation/dissertation proposal
entitled “FOOD DELIVERY TIME PREDICTION” in partial fulfilment of the
requirement for the award of degree for Bachelor of Technology in Computer Science and
Engineering at Lovely Professional University, Phagwara, Punjab is an authentic work
carried out under supervision of my research supervisor Mr. Ved Prakash Chaubey. I have
not submitted this work elsewhere for any degree or diploma.

I understand that the work present herewith follows Lovely Professional


University’s Policy on plagiarism, intellectual property rights, and highest standards of
moral and ethical conduct. Therefore, to the best of my knowledge, the content of this
dissertation represents authentic and honest research effort conducted, in its entirely, by
me. I am fully responsible for the contents of my dissertation work.

Signature of candidate

Munzir Hassan

12106309

3
SUPERVISOR’S CERTIFICATE
This is to certify that the work reported in the [Link] Dissertation/dissertation proposal entitled “FOOD
DELIVERY TIME PREDICTION”, submitted by Munzir Hassan at Lovely Professinal University,
Phagwara, Punjab is a bonified record of his/ her original work carried out under my supervision. This
work has not been submitted elsewhere for any other degree.

4
ACKNOWLEDGMENT
I would like to express my sincere gratitude to Ved Prakash Chaubey sir and
Shivangini Gupta mam, whose expertise, understanding, and patience, added
considerably to my research experience. I am exceedingly grateful for the guidance
and insightful critiques of my work.

I owe my loving appreciation to my family, who provided encouragement and


thoughtful consideration of my work despite the many hours spent away from them.
Their unwavering support and sacrifice cannot be put into words and have been
fundamental to my studies.

Finally, I owe a deep sense of gratitude to the participants and subjects who make
this research possible. Without their involvement, this study would not
have materialized.
5
Table of Contents
1) Introduction
a. Overview of the food delivery industry
b. Online Food Delivery Market Analysis
c. Online Food Delivery Market Trends
2) Literature Review
a. Existing approaches for distance calculation between locations
b. Mobile apps are used in the food delivery sector
c. Brief of the Reviewed Literature
3) Methodology
a. Dataset Exploration
b. Distance Calculation Between Latitudes and Longitudes
c. Data Analysis
d. Food Delivery Time Prediction Model
4) Results and Discussion
a. Evaluation of Distance Calculation Accuracy
b. Performance of the Delivery Time Prediction Mode
c. Implications for Food Delivery Optimization
5) Conclusion

6
INTRODUCTION
Food delivery time prediction refers to the estimation of
how long it will take for a food delivery service to deliver an order from the time it is
placed by a customer. This prediction is crucial for both customers and delivery services,
as it helps manage expectations, optimize delivery routes, and improve overall customer
satisfaction.
Meal delivery orders are typically on demand, intended to be eaten right away, and
include hot, already-prepared food. While some service providers offer subscription
services ordering for delivery usually involves contacting a local restaurant or chain by
telephone or online. Online ordering is available in many countries, where some stores
offer online menus and ordering. Since 1995, companies such as [Link] have their
own interfaces where customers order food from nearby restaurants that have partnered
with the service. Meal delivery requires special technology and care, since the food items
are already cooked and prepared, and can be easily damaged if dropped, tilted, or left out
for long periods of time. Hot bags are often used to keep food warm. They are thermal
bags typically made of vinyl, nylon or Cordura, that passively retain heat.
The process of predicting food delivery time involves various factors such as distance,
traffic conditions, weather, restaurant preparation time, delivery personnel availability,
and order volume. Machine learning algorithms are commonly used in this domain to
analyze historical delivery data and generate accurate predictions.
These predictions are typically displayed to customers during the ordering process,
allowing them to choose delivery times that align with their preferences. Delivery services
also benefit from accurate predictions by efficiently allocating resources and improving
delivery speed and [Link], food delivery time prediction plays a significant role
in enhancing the customer experience and operational efficiency of food delivery services.

7
Overview of the food delivery industry
The Online Food Delivery Market is Experiencing Significant Growth Due To Changing
Consumer Habits Favoring Online Platforms, Driven by Increased Internet Usage,
Smartphone Accessibility, Simplified E-Banking, Improved Food Courier Logistics, and
Evolving Lifestyles. The Market is Segmented by Business Model, Platform Type, and
Geography, With North America Leading. Recent Trends Include Real-Time Meal
Delivery Tracking, Personalized Home Food Delivery, and the Rise of Cloud Kitchens.
Major Players in the Restaurant Delivery Service Market are Increasing Investments in
Research, Development, Marketing, and Geographical Expansion.

Online Food Delivery Market Analysis


The Online Food Delivery Market is expected to register a CAGR of 16.24% during the forecast period.

• Customers are rapidly heading online, which has fueled drastic growth in the e-commerce industry
over the last decade. This shift in consumer shopping habits has been driven by various causes,
some of which are industry or country-specific, while others are the product of global shifts.
• Most of it can be attributed to the availability of an increased number of online food delivery
businesses, a better understanding by consumers of the developments of online e-commerce, a
better easy and secure option for online payments of services, disposable income on the rise, and
work from home decreasing time for people to invest in making the food themselves.
• Increased internet penetration rate, quick access to smartphones, simplified e-banking systems,
improved food-service logistics, and changing lifestyles are some prime factors driving the growth
of online food delivery. As per the report published by Zomato, the Indian food delivery platforms
will have 80 million monthly active users in 2021 and have set targets of reaching 200 million
over the next few years. Hence, an increase in smartphone users and internet penetration is driving
growth in online food delivery services.
• `Some of the recent trends in the market studied include real-time order tracking and customized
food delivery. Thus, companies are increasing their investments in research and development
(R&D) and marketing and expanding their geographical reach to maintain their position in the
market. Most leading players follow logistics-focused food delivery systems due to the model's
ability to help gain scale with limited costs and increased speed.

8
Online Food Delivery Market Trends
Rising Popularity of Cloud Kitchens

The food delivery market is witnessing a rise in the popularity of cloud kitchens due to many consumers
purchasing their food through online platforms. Thus, the increasing number of food orders through cloud
kitchens is due to convenience, the hectic lifestyles of consumers, and intense internet penetration. Cloud
kitchens have become the popular investment choice for established and new restaurateurs to open a food
business. Faasos by Rebel Foods, Biryani By Kilo, and Freshmenu are some of the popular cloud kitchen
chains operating in this segment.

Established restaurant chains are now also opening cloud kitchen outlets instead of opening dine-in outlets
to cater to high food delivery orders. The ease of getting food delivered at a reasonable price and in record
time has increased the number of orders placed online. Instead of dining out, people prefer to order in.
Online food delivery is not only eating into the market share of traditional dine-in restaurants but is also
replacing home cooking. Because of the shift in customer preference and an increased sense of hassle in
dining out, the home delivery option has gained momentum and, along with that, has brought a change in
the restaurant industry as now food overpowers the dining experience. For instance, in January 2022,
Arabic REEF Technologies, a United States-based operator of delivery kitchens, logistics, and proximity
hubs, announced plans to launch cloud kitchens for its network of restaurants and brands in the Middle
East and North Africa. In November 2021, REEF acquired UAE-based cloud kitchen company iKcon,
marking its first venture in the region.

9
North America Dominates the Market
• The North American market has a high market share in the global market, mainly due to strong
user penetration rates in the United States. It is one of the largest markets for global online food
delivery. It currently represents the world's biggest online food delivery market. Several factors
drive north America's online food delivery market. The significant urban population, busy
lifestyles, and increasing penetration of the internet and smartphones are some of the key drivers
that have driven the growth of online food delivery in the region.
• Moreover, the United States' large young population, which constitutes most of the consumer base,
has further facilitated this growth. In October 2021, Delivery Hero acquired Hugo's food and
grocery delivery verticals and expanded its footprint in Central America and the Caribbean.
Various online food delivery service providers are experimenting with innovative food delivery
methods via self-driving cars, drones, and robots, positively influencing market growth.
• Moreover, individuals' high living standards continue to spur the region's demand for online food
delivery packaging services. Some of the major players in North America, including Doordash,
Uber Eats, Postmates, GrubHub -Seamless, and Caviar, are adopting strategies for developing the
online food delivery market like new product development, global expansion, acquisitions, and
investments.

10
. Literature Review
Theoretical background of food sector apps
Conceptual structure of consumers’ online food shopping
a. The perceived social norm refers to the expectations of other people (e.g. friends and
family) on the implementation of an individual’s online shopping and is linked to
online food shopping, buying desires or using.
b. Perceived compatibility represents how well online food shopping suits the actions
and beliefs of an individual, and has a favorable experience of social food shopping,
ordering, or customer attitudes.
c. The perceived relative gain is the individual’s perception of domination of online
shopping trips over modern offline food shopping.
d. The degree of complexity experienced by online food shoppers is the degree of
complexity that is negatively linked to perceptual expectations, purchasing patterns
or online food shopping.
e. The perceived risk illustrates consumer expectations for possible losses and harms
related to online food shopping (such as payment security, exchange issues and receipt
of poor quality food) and is adversely linked to desires, goals of buying and online
shopping.

Mobile apps use in the food delivery sector:


Home supply is the activity where a food supply service provider establishes a connection
between cafes, bars, and consumers in the food supply sub field. The business model of
food delivery services focuses on the benefits of the Internet, i.e. the technological ability
to connect different distribution chain agents. Mobile applications are an integral part of
everyday life today and use of them is vital to the food industry’s strategic advantage. By
using food supply applications, customers will have access to food from which they want
and order their favorites from a selection of restaurants at suitable times and locations.
Although food supply applications are an important context for distribution, there is little
understanding of why people use them. In precise, online technology enables companies to
position orders at a specific place with high accuracy and efficiency in the operational
processes of the last miles.

11
Brief of the Reviewed Literature:
Rashmi (2018), in her study titled “Swot review of online food industry in India,”
claims that the number of food startups has risen significantly in the last year. According to
BCG reports, the food industry in India is projected to rise from Rs 23 trillion to Rs 42
lakh crore by 2020. The online platform is assisting restaurants in expanding their scope,
and consumers have begun to choose online platforms over ordering food by calling
individual restaurants. According to a Red Seer report, the share of online delivery for
partner restaurants has reached 30-35 percent of their overall market, and the number is
increasing is increasing day by day. “It has been observed that the Indian food industry
will expand rapidly, growing its contribution to global food exchange year after year. The
internet's scope is increasingly expanding, and a large proportion of the young and working
population who are tech savvy is dining out more than their forefathers. Working
millennials who pay for comfort are on the rise. It is obvious that the food ordering and
distribution market has a lot of room for growth.”
Dr. Katete (2018) stated in her Journal titled “Innovative strategies of Startup firms in
India- A report on online food distribution companies in India” that the Indian food
delivery industry is currently estimated at $15 billion and is expected to expand
exponentially. She acknowledges that creativity has the power to take this sector in a
whole different direction. Restaurant partners profit from substantial cost and productivity
savings thanks to technological advancements. To remain successful, it is crucial to
concentrate on developing scalable business sources and resources with a long-term target,
as well as grow incredibly rapidly on the technological side to maximize internal
efficiencies.” Mustafa Abbas Bhotvawal and colleagues (2016) explored the business
models and operational strategies of aggregator food delivery firms in a thriving Indian
market in their research titled “Growth of Food Tech: A Comparative Study of Aggregator
Food Delivery Services in India.” In their research paper titled “Food Portals- The Growth
Engine” “Do you have an appetite?” Zamarrud Ansari and Dr. Surbhi Jain (2016)
addressed the advantages of ordering food from online portals rather than telephonic
ordering. An online grocery portal allows consumers to buy food from companies listed
on the portal. Using dynamic functionality, users can access specific details about the
restaurant/takeaway, get directions, display reviews, link to the menu, order and pay
online. The platform can also provide an open community where users can communicate
with friends and share their encounters with various food establishments. Customers find it
difficult to dial a busy number repeatedly because they simply cannot wait any longer for
food. And if they are good enough to get a service provider on the call, it is impossible to
hurry through a menu that is not in front of them. A food platform is important these days
for taking orders without having additional personnel for billing and customer support. It
12
clears traffic and gets you moving quickly. Online portals aid companies in gaining leads
and finding clients who are usually missed or who miss reading about these restaurants due
to a lack of knowledge. They addressed the proliferation of online food portals and other
topics has players in the Indian market.” Abhishek Singh, Adithya, Vaishnav Kanade, and
Prof. Salma Pathan (2018) write in their Article titled "Online food ordering system"
published by International Research Journal of Engineering and Technology that an
online food distribution system is a need due to the increased usage of smartphones
and the internet. Online portals make it easy to order food and watch it in real time. A
food menu is set up online, and consumers can position their orders and monitor them
using the proposed framework. The pay-on-delivery billing method is used for the basic
deployment of the system program. Separate accounts are maintained for each user for
more secure ordering by providing an ID and a password.
Swiggy: Swiggy is India’s most famous food ordering and delivery service. Bengaluru is
the headquarters of the group, which began operations in 2014. Swiggy functions by
bridging the gap between consumers and restaurants. It makes use of a cutting-edge
technology network that enables consumers to order food from local restaurants and have
it shipped straight to their house. Swiggy removes the need for consumers to keep track of
the phone numbers of numerous restaurants and eateries in their city. Swiggy serves as a
single point of touch for ordering food from all the restaurants in each area. Swiggy has its
own distribution squad that picks up orders from restaurants and delivers them to
customers’ homes. Customers have found it much easier to place food orders because of
this. Restaurants prosper as well by accepting further deliveries and avoiding the costs and
commitment of maintaining their own distribution employees.

13
Swiggy's cutting-edge technology, massive and nimble delivery operation, and excellent
customer focus have enabled a slew of advantages, including lightning-fast deliveries, real-
time order monitoring, and no order minimums, all while enjoying your favorite meal
wherever you want it. Swiggy started off by signing up a few restaurants in Bengaluru's
Koramangala neighborhoods in August of 2014. Soon after, the first party of Hunger
Saviors arrived to deliver food in under 40 minutes. Swiggy received its first round of
investment shortly after and unveiled the app in May of 2015. Fun fact: The technology
that carries fantastic food to your doorstep was invented entirely by mistake and developed
in-house. Swiggy grew rapidly thanks to customer love and support, first across Bengaluru
and then across the world.

14
Methodology

import pandas as pd
import numpy as np
import [Link] as px

data = pd.read_csv("[Link]")
print([Link]())
C:\Users\munzi\anaconda3\lib\site-packages\scipy\__init__.py:155: UserWarning: A NumP
y version >=1.18.5 and <1.25.0 is required for this version of SciPy (detected versio
n 1.26.4
[Link](f"A NumPy version >={np_minversion} and <{np_maxversion}"
ID Delivery_person_ID Delivery_person_Age Delivery_person_Ratings \
0 4607 INDORES13DEL02 37 4.9
1 B379 BANGRES18DEL02 34 4.5
2 5D6D BANGRES19DEL01 23 4.4
3 7A6A COIMBRES13DEL02 38 4.7
4 70A2 CHENRES12DEL01 32 4.6

Restaurant_latitude Restaurant_longitude Delivery_location_latitude \


0 22.745049 75.892471 22.765049
1 12.913041 77.683237 13.043041
2 12.914264 77.678400 12.924264
3 11.003669 76.976494 11.053669
4 12.972793 80.249982 13.012793

Delivery_location_longitude Type_of_order Type_of_vehicle Time_taken(min)


0 75.912471 Snack motorcycle 24
1 77.813237 Snack scooter 33
2 77.688400 Drinks motorcycle 26
3 77.026494 Buffet motorcycle 21
4 80.289982 Snack scooter 30

Let’s have a look at the column insights before moving


forward:
In [2]:
[Link]()
<class '[Link]'>
RangeIndex: 45593 entries, 0 to 45592
Data columns (total 11 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----

15
0 ID 45593 non-null object
1 Delivery_person_ID 45593 non-null object
2 Delivery_person_Age 45593 non-null int64
3 Delivery_person_Ratings 45593 non-null float64
4 Restaurant_latitude 45593 non-null float64
5 Restaurant_longitude 45593 non-null float64
6 Delivery_location_latitude 45593 non-null float64
7 Delivery_location_longitude 45593 non-null float64
8 Type_of_order 45593 non-null object
9 Type_of_vehicle 45593 non-null object
10 Time_taken(min) 45593 non-null int64
dtypes: float64(5), int64(2), object(4)
memory usage: 3.8+ MB

Now let’s have a look at whether this dataset contains any null
values or not:
In [3]:
[Link]().sum()
Out[3]:
ID 0
Delivery_person_ID 0
Delivery_person_Age 0
Delivery_person_Ratings 0
Restaurant_latitude 0
Restaurant_longitude 0
Delivery_location_latitude 0
Delivery_location_longitude 0
Type_of_order 0
Type_of_vehicle 0
Time_taken(min) 0
dtype: int64

Calculating Distance Between Two Latitudes


and Longitudes
The dataset doesn’t have any feature that shows the
difference between the restaurant and the delivery location.
All we have are the latitude and longitude points of the
restaurant and the delivery location. We can use the

16
haversine formula to calculate the distance between two
locations based on their latitudes and longitudes.
Below is how we can find the distance between the restaurant and the delivery location based on
their latitudes and longitudes by using the haversine formula:
In [4]:
# Set the earth's radius (in kilometers)
R = 6371

# Convert degrees to radians


def deg_to_rad(degrees):
return degrees * ([Link]/180)

# Function to calculate the distance between two points using the haversine formula
def distcalculate(lat1, lon1, lat2, lon2):
d_lat = deg_to_rad(lat2-lat1)
d_lon = deg_to_rad(lon2-lon1)
a = [Link](d_lat/2)**2 + [Link](deg_to_rad(lat1)) * [Link](deg_to_rad(lat2)) *
[Link](d_lon/2)**2
c = 2 * np.arctan2([Link](a), [Link](1-a))
return R * c

# Calculate the distance between each pair of points


data['distance'] = [Link]

for i in range(len(data)):
[Link][i, 'distance'] = distcalculate([Link][i, 'Restaurant_latitude'],
[Link][i, 'Restaurant_longitude'],
[Link][i, 'Delivery_location_latitude'],
[Link][i, 'Delivery_location_longitude'])

We have now calculated the distance between the restaurant


and the delivery location. We have also added a new feature
in the dataset as distance. Let’s look at the dataset again:
In [5]:
print([Link]())
ID Delivery_person_ID Delivery_person_Age Delivery_person_Ratings \
0 4607 INDORES13DEL02 37 4.9
1 B379 BANGRES18DEL02 34 4.5
2 5D6D BANGRES19DEL01 23 4.4
3 7A6A COIMBRES13DEL02 38 4.7
4 70A2 CHENRES12DEL01 32 4.6

Restaurant_latitude Restaurant_longitude Delivery_location_latitude \


17
0 22.745049 75.892471 22.765049
1 12.913041 77.683237 13.043041
2 12.914264 77.678400 12.924264
3 11.003669 76.976494 11.053669
4 12.972793 80.249982 13.012793

Delivery_location_longitude Type_of_order Type_of_vehicle Time_taken(min) \


0 75.912471 Snack motorcycle 24
1 77.813237 Snack scooter 33
2 77.688400 Drinks motorcycle 26
3 77.026494 Buffet motorcycle 21
4 80.289982 Snack scooter 30

distance
0 3.025149
1 20.183530
2 1.552758
3 7.790401
4 6.210138

Data Exploration
Now let’s explore the data to find relationships between the features. I’ll start by
looking at the relationship between the distance and time taken to deliver the
food:

In [6]:
figure = [Link](data_frame = data,
x="distance",
y="Time_taken(min)",
size="Time_taken(min)",
trendline="ols",
title = "Relationship Between Distance and Time Taken")
[Link]()

18
There is a consistent relationship between the time taken and
the distance travelled to deliver the food. It means that most
delivery partners deliver food within 25-30 minutes,
regardless of distance.
Now let’s have a look at the relationship between the time taken to deliver the food and the age of
the delivery partner:
In [7]:
figure = [Link](data_frame = data,
x="Delivery_person_Age",
y="Time_taken(min)",
size="Time_taken(min)",
color = "distance",
trendline="ols",
title = "Relationship Between Time Taken and Age")
[Link]()

19
There is a linear relationship between the time taken to
deliver the food and the age of the delivery partner. It means
young delivery partners take less time to deliver the food
compared to the elder partners.
Now let’s have a look at the relationship between the time
taken to deliver the food and the ratings of the delivery
partner:
In [8]:
figure = [Link](data_frame = data,
x="Delivery_person_Ratings",
y="Time_taken(min)",
size="Time_taken(min)",
color = "distance",
trendline="ols",
title = "Relationship Between Time Taken and Ratings")
[Link]()

20
There is an inverse linear relationship between the time
taken to deliver the food and the ratings of the delivery
partner. It means delivery partners with higher ratings take
less time to deliver the food compared to partners with low
ratings.
Now let’s have a look if the type of food ordered by the
customer and the type of vehicle used by the delivery partner
affects the delivery time or not:
In [9]:
fig = [Link](data,
x="Type_of_vehicle",
y="Time_taken(min)",
color="Type_of_order")
[Link]()

21
So there is not much difference between the time taken by
delivery partners depending on the vehicle they are driving
and the type of food they are delivering.
So the features that contribute most to the food delivery time
based on our analysis are:
* age of the delivery partner
* ratings of the delivery partner

* distance between the restaurant and the delivery location

In the section below, I will take you through how to train a Machine Learning
model for food delivery time prediction.

Food Delivery Time Prediction Model


Now let’s train a Machine Learning model using an LSTM neural network model for
the task of food delivery time prediction:

22
In [10]:
#splitting data
from sklearn.model_selection import train_test_split
x = [Link](data[["Delivery_person_Age",
"Delivery_person_Ratings",
"distance"]])
y = [Link](data[["Time_taken(min)"]])
xtrain, xtest, ytrain, ytest = train_test_split(x, y,
test_size=0.10,
random_state=42)

# creating the LSTM neural network model


from [Link] import Sequential
from [Link] import Dense, LSTM
model = Sequential()
[Link](LSTM(128, return_sequences=True, input_shape= ([Link][1], 1)))
[Link](LSTM(64, return_sequences=False))
[Link](Dense(25))
[Link](Dense(1))
[Link]()
C:\Users\munzi\anaconda3\lib\site-packages\keras\src\layers\rnn\[Link]: UserWarni
ng:

Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential m


odels, prefer using an `Input(shape)` object as the first layer in the model instead.

Model: "sequential"
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓
┃ Layer (type) ┃ Output Shape ┃ Param # ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩
│ lstm (LSTM) │ (None, 3, 128) │ 66,560 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ lstm_1 (LSTM) │ (None, 64) │ 49,408 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ dense (Dense) │ (None, 25) │ 1,625 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ dense_1 (Dense) │ (None, 1) │ 26 │
└──────────────────────────────────────┴─────────────────────────────┴─────────────────┘
Total params: 117,619 (459.45 KB)
Trainable params: 117,619 (459.45 KB)
Non-trainable params: 0 (0.00 B)
In [11]:
# training the model

23
[Link](optimizer='adam', loss='mean_squared_error')
[Link](xtrain, ytrain, batch_size=1, epochs=9)
Epoch 1/9
41033/41033 ━━━━━━━━━━━━━━━━━━━━ 141s 3ms/step - loss: 75.6712
Epoch 2/9
41033/41033 ━━━━━━━━━━━━━━━━━━━━ 138s 3ms/step - loss: 63.3413
Epoch 3/9
41033/41033 ━━━━━━━━━━━━━━━━━━━━ 133s 3ms/step - loss: 61.8727
Epoch 4/9
41033/41033 ━━━━━━━━━━━━━━━━━━━━ 135s 3ms/step - loss: 59.4859
Epoch 5/9
41033/41033 ━━━━━━━━━━━━━━━━━━━━ 134s 3ms/step - loss: 59.8848
Epoch 6/9
41033/41033 ━━━━━━━━━━━━━━━━━━━━ 148s 4ms/step - loss: 59.7429
Epoch 7/9
41033/41033 ━━━━━━━━━━━━━━━━━━━━ 180s 4ms/step - loss: 58.7494
Epoch 8/9
41033/41033 ━━━━━━━━━━━━━━━━━━━━ 261s 6ms/step - loss: 60.1582
Epoch 9/9
41033/41033 ━━━━━━━━━━━━━━━━━━━━ 263s 6ms/step - loss: 58.8547
Out[11]:
<[Link] at 0x1eb62645b80>

Now let’s test the performance of our model by giving inputs to predict the food
delivery time:

In [12]:
print("Food Delivery Time Prediction")
a = int(input("Age of Delivery Partner: "))
b = float(input("Ratings of Previous Deliveries: "))
c = int(input("Total Distance: "))

features = [Link]([[a, b, c]])


print("Predicted Delivery Time in Minutes = ", [Link](features))
Food Delivery Time Prediction
Age of Delivery Partner: 29
Ratings of Previous Deliveries: 2.9
Total Distance: 6
1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 1s/step
Predicted Delivery Time in Minutes = [[33.356804]]

So this is how you can use Machine Learning for the task of food delivery time
prediction using the Python programming language.

Summary

24
To predict the food delivery time in real time, you need to calculate the distance between the food
preparation point and the point of food consumption. After finding the distance between the
restaurant and the delivery locations, you need to find relationships between the time taken by
delivery partners to deliver the food in the past for the same distance. I hope you liked this article
on food delivery time prediction with Machine Learning using Python. Feel free to ask valuable
questions in the comments section below.

25
Conclusion
In conclusion, this project showcased how machine learning can be applied to
the problem of food delivery time prediction. The insights gained from the data
exploration and the performance of the LSTM model can be valuable for food
delivery companies to optimize their operations, improve customer
satisfaction, and enhance the overall delivery experience.

The key takeaways from this project are:

The distance between the restaurant and the delivery location, the age of the
delivery partner, and the ratings of the delivery partner are the most important
factors that influence the food delivery time.
Using an LSTM neural network model, we can effectively predict the food
delivery time based on these factors.
The insights and the trained model from this project can be used by food
delivery companies to improve their operations and provide better service to
their customers.
Overall, this project demonstrates the power of data analysis and machine
learning in optimizing real-world business processes, such as food delivery
services.

26
27
\

28

You might also like