ClickPost Data Science Internship Assignment
- Project Overview
- Problem Statement
- Deliverables
- Evaluation Metrics
- Dataset Description
- Installation Instructions
- Usage
- Model Description
- Variable Importance & Trends
- Data Visualization
- Engineering Documentation
- Conclusion
- Contact
Logistics is a rapidly growing sector, with millions of orders dispatched daily. Accurately predicting the Estimated Delivery Date (EDD) is both challenging and crucial for enhancing customer satisfaction and optimizing logistics operations. This project focuses on developing a machine learning model to predict the EDD for orders of an e-commerce enterprise, based on historical shipment data.
Objective:
Predict the Estimated Delivery Date (EDD) for each order of an e-commerce company.
Definition of EDD:
EDD is defined as the number of days between the shipment date and the order delivery date.
Context:
The training dataset comprises daily shipment data of an e-commerce enterprise from June 2022 to August 2022. The goal is to predict the predicted_exact_sla for shipments in the test dataset covering a subsequent 3-week period.
-
submission.csv:
Contains the predicted EDD values corresponding to theidcolumn in the test dataset. -
Model Description:
A concise explanation of the machine learning model used, including its performance metrics and variable importance. -
Data Visualization:
Visual representations highlighting important and useful patterns in the data. -
Code:
The complete codebase (Jupyter Notebook) utilized for data preprocessing, model training, evaluation, and prediction generation. -
Engineering Documentation:
A brief document outlining suggestions on integrating the EDD prediction model with the ClickPost system, enabling EDD consumption at both order and bulk levels.
The submission will be evaluated based on the following parameters:
-
Accuracy of Predicted Values:
The closeness of the predicted EDD values to the actual observed values. -
Root Mean Squared Error (RMSE):
Measures the average magnitude of the prediction errors, emphasizing larger errors. -
Additional Metrics:
- Mean Absolute Error (MAE): Average of absolute differences between predictions and actual values.
- R² Score: Proportion of variance in the dependent variable predictable from the independent variables.
- Classification Metrics (if applicable):
- Accuracy
- Precision
- Recall
The dataset consists of three files:
-
train_.csv:
- Description: Contains historical shipment data used to train the predictive model.
- Time Frame: June 2022 to August 2022.
- Key Columns:
id: Unique identifier for each shipment.order_shipped_date: Date when the order was shipped.order_delivered_date: Date when the order was delivered.courier_partner_id: Identifier for the courier partner.account_type_id: Type identifier for the account.drop_pin_code: PIN code where the order is to be delivered.pickup_pin_code: PIN code from where the order is picked up.quantity: Number of items in the order.account_mode: Mode of the account (e.g., Air, Ground).order_delivery_sla: Service Level Agreement (SLA) in days.
-
test_.csv:
- Description: Contains shipment data for which EDD predictions are to be made.
- Key Columns: Similar to
train_.csvbut without theorder_delivered_dateandorder_delivery_sla.
-
pincodes.csv:
To replicate the project environment, follow these steps:
-
Clone the Repository:
git clone https://github.com/meakc/assignment.git cd assignment -
Set Up a Virtual Environment (Optional but Recommended):
python3 -m venv venv source venv/bin/activate -
Install Required Packages:
pip install -r requirements.txt
If a
requirements.txtfile is not provided, you can install the necessary packages manually:pip install pandas numpy matplotlib seaborn scikit-learn
-
Ensure Data Files are Available:
Placetrain_.csv,test_.csv, andpincodes.csvin the project directory. -
Open the Jupyter Notebook:
Launch Jupyter Notebook or JupyterLab and openEDD_Prediction.ipynb. -
Run the Notebook Cells:
Execute each cell sequentially to perform data preprocessing, model training, evaluation, and prediction generation. -
Generate
submission.csv:
After running all cells, asubmission.csvfile will be created containing the predicted EDD values. -
Download the Trained Model (Optional):
A download link will be provided within the notebook to download the serialized model (random_forest_regressor.pkl).
Algorithm Used:
Random Forest Regressor
Rationale:
Random Forest is an ensemble learning method known for its robustness and ability to handle both numerical and categorical features. It effectively manages feature interactions and reduces the risk of overfitting, making it suitable for predicting continuous variables like EDD.
Model Performance:
- RMSE: 0.76
- MAE: 0.36
- R² Score: 0.81
These metrics indicate a strong correlation between the predicted and actual EDD values, showcasing the model's effectiveness.
The Random Forest model provides insights into the importance of each feature in predicting EDD. The most significant variables influencing the predictions are:
-
courier_partner_id:
Importance: 0.3735
Indicates the courier partner's efficiency and reliability. -
drop_pin_code:
Importance: 0.3663
Reflects geographic factors influencing delivery times. -
order_shipped_date:
Importance: 0.1469
Captures temporal patterns and seasonality in deliveries. -
pickup_pin_code:
Importance: 0.0878
Represents the origin location's impact on delivery speed. -
account_mode:
Importance: 0.0185
Differentiates between various account types, such as Air or Ground. -
account_type_id:
Importance: 0.0070
Classifies the account type, though it has minimal impact. -
quantity:
Importance: 0.0000
Surprisingly, the number of items in the order does not influence EDD.
Several visualizations have been created to understand the data and model performance:
-
Feature Importance Bar Plot:
Highlights the significance of each feature in the model. -
SLA Distribution Histogram:
Shows the distribution of predicted SLA values. -
Residual Distribution Plot:
Illustrates the residuals to assess the model's prediction errors. -
Confusion Matrix:
(Applicable if classification metrics are used) Displays the performance of the classification model. -
Classification Report Heatmap:
Visualizes precision, recall, and F1-score for each class. -
Class Distribution Plots:
Compares the distribution of true and predicted classes. -
Performance Comparison Bar Plot:
Compares regression and classification metrics side by side.
All visualizations are generated using Seaborn and Matplotlib and are embedded within the Jupyter Notebook.
To seamlessly integrate the EDD prediction model with the ClickPost system, consider the following steps:
-
API Deployment:
- Containerization: Use Docker to containerize the trained model and its dependencies.
- API Framework: Deploy the model using frameworks like Flask or FastAPI to create RESTful endpoints.
- Endpoints:
- Single Order Prediction: An endpoint to receive order details and return the predicted EDD.
- Bulk Prediction: An endpoint to handle batch requests for bulk EDD predictions.
-
Model Serving:
- Scalability: Utilize platforms like AWS SageMaker, Google AI Platform, or Azure ML for scalable model serving.
- Monitoring: Implement monitoring to track model performance and latency.
-
Data Pipeline Integration:
- Real-Time Data: Ensure that real-time shipment data is fed into the model for immediate EDD predictions.
- Batch Processing: For bulk predictions, integrate with existing batch processing workflows.
-
Security and Compliance:
- Authentication: Secure the API endpoints with authentication mechanisms.
- Data Privacy: Ensure compliance with data privacy regulations when handling shipment data.
-
User Interface (UI):
- Dashboard: Develop dashboards to visualize EDD predictions, model performance, and other key metrics for internal stakeholders.
- Notifications: Integrate EDD predictions with notification systems to inform customers about their order status.
-
Continuous Integration and Deployment (CI/CD):
- Automation: Set up CI/CD pipelines to automate model retraining, testing, and deployment as new data becomes available.
-
Documentation and Training:
- User Guides: Provide comprehensive documentation for end-users on how to interpret and utilize EDD predictions.
- Training Sessions: Conduct training for the logistics team to understand the model's capabilities and limitations.
-
Hyperparameter Tuning:
Optimize model parameters using techniques like Grid Search or Random Search to improve performance. -
Feature Engineering:
Incorporate additional features such as weather data, holidays, or traffic conditions that may affect delivery times. -
Alternative Models:
Experiment with other regression algorithms like Gradient Boosting, XGBoost, or Neural Networks to potentially enhance prediction accuracy. -
Ensemble Methods:
Combine predictions from multiple models to leverage their individual strengths. -
Model Explainability:
Utilize tools like SHAP or LIME to provide deeper insights into model predictions, aiding in transparency and trust.
This project successfully developed a Random Forest Regressor model to predict the Estimated Delivery Date (EDD) for an e-commerce company's shipments. The model demonstrates strong performance with an R² score of approximately 0.81, indicating a significant ability to predict EDD based on the provided features. Feature importance analysis revealed that the courier partner and drop PIN code are the most influential factors affecting delivery times. Future enhancements can focus on integrating additional data sources, optimizing the model through hyperparameter tuning, and deploying the model within the ClickPost system for real-time EDD predictions.
Abhishek Kumar Choudhary


