Predict delivery times using an LSTM. Data analysis & ML model. Optimizes logistics.
Overview
This project focuses on developing a machine learning model to predict delivery times based on various factors. Leveraging a dataset of delivery operations, this repository implements an LSTM (Long Short-Term Memory) neural network to accurately forecast how long a delivery will take. This solution can optimize logistics, enhance customer satisfaction, and provide insights into the factors that most affect delivery efficiency.
Key Features
Data Preprocessing: The project handles raw delivery data, performing data cleaning, transformation, and feature engineering. Categorical variables are effectively encoded using One-Hot Encoding, and geographical data is used to calculate distances between locations, a critical factor in delivery time. Exploratory Data Analysis (EDA): The project includes a comprehensive EDA phase. Various data visualizations, such as scatter plots and box plots, are used to explore relationships between delivery times and other variables like distance, delivery person's age, ratings, type of order, and vehicle type. The plotly library was used to create these visualizations. LSTM Model: An LSTM neural network is designed and implemented for delivery time prediction. The model is trained to learn the complex temporal patterns within the data. It's configured with multiple LSTM layers and dense layers to handle sequence data effectively. Model Evaluation: The model's performance is evaluated using mean squared error as the loss function. Real-time Prediction: The project enables real-time delivery time prediction, allowing the user to input parameters like delivery person's age, ratings, distance, type of vehicle and type of order. Model Saving: The trained model can be saved to disk using model.save(), allowing for later reuse and deployment. Haversine Formula: The distance between the restaurant and the delivery location was calculated using the Haversine formula. Technical Details
Libraries: NumPy and Pandas for data manipulation and analysis. Plotly for creating interactive visualizations. Scikit-learn for data preprocessing and model evaluation. TensorFlow/Keras for building and training the LSTM neural network. Model Architecture: The core of this project is a sequential LSTM model, well-suited for time-series and sequence data like the patterns in delivery times. Training: The model is trained on a historical dataset of delivery times and associated features, aiming to learn the underlying factors influencing delivery speed. The training included stochastic gradient decent with 128 batch_size over 10 epochs. How to Use
Clone the Repository: git clone [repository URL]
Install Dependencies: pip install -r requirements.txt
Run the Notebooks: Execute the Jupyter Notebooks in the repository to reproduce the data preprocessing, model training, and evaluation steps.
Load the Data: The data used in this project is the 'deliverytime.txt' file.
Predict: Use the real-time prediction feature by running the cells at the end of the notebook, and providing the required inputs.
Save: save the model using the method provided.
Potential improvements
Optimise the model by increasing the number of epochs and the number of layer. Add more types of data in order to add more features to the model. Why This Project Matters
Efficient delivery time prediction is vital for many industries, including e-commerce, food delivery, and logistics. Accurate predictions allow businesses to:
Optimize delivery routes and schedules. Manage customer expectations effectively. Improve overall operational efficiency. Allocate resources more effectively. Contributing
Contributions to this project are welcome! If you have ideas for improvements, new features, or bug fixes, please feel free to fork the repository and submit a pull request.
License
Copyright (c) 2025 Zakaria Tanani