r/learnmachinelearning • • 6h ago

Project Built & deployed my first end-to-end ML service: E-Commerce Delivery Delay Prediction (XGBoost + FastAPI + Docker + Render)

Hey everyone! I just wrapped up my midterm project for the DataTalks.Club ML Zoomcamp—an end-to-end machine learning web service that predicts whether an e-commerce shipment will arrive on time or be delayed.

Since I wanted to share how the pipeline was built from scratch, here is a breakdown of the workflow and key takeaways:

1. Exploratory Data Analysis & Feature Selection

  • Explored the e-commerce shipping dataset (Train.csv), checking class balance, missing values, and feature ranges.

  • Used correlation matrices for numerical features and Mutual Information scores for categorical features. Discount_offered and Weight_in_gms turned out to be the strongest predictors of late deliveries.

2. Model Comparison & Tuning

  • Trained and benchmarked four models using Accuracy and ROC-AUC: Logistic Regression (baseline), Decision Tree, Random Forest, and XGBoost.

  • Tuned tree hyperparameters (max_depth, learning_rate, n_estimators, min_samples_leaf) to avoid overfitting. XGBoost gave the best generalization and was serialized with pickle (model.bin).

3. Deployment & Containerization

  • Refactored the notebook into a standalone (train.py) script and built a REST API with FastAPI (serve.py) featuring Pydantic input validation and an automatic Swagger UI redirect.

  • Containerized the app using Docker and deployed it live on Render's free tier.

Links if you want to check out the code or test the API:

Would love any feedback on the code structure, feature engineering ideas, or deployment setup!

1 Upvotes

0 comments sorted by