API to predict whether a shipment in transit will be delayed or not, based on details such as origin city, destination, weather conditions and more.
This API uses a Logistic Regression model that predicts shipment delay with an accuracy of 99.625%.
The API is deployed and accessible at: https://shipment-delay-api.onrender.com
Shipment-Delay-API/
├── api/
│ ├── utils/
│ │ ├── data_processing.py
│ │ ├── prediction.py
│ ├── __init__.py
│ ├── config.py # Configurations
│ ├── routes.py # Flask routes
│ ├── errors.py # Error handlers
├── tests/
│ ├── __init__.py
│ ├── test_api.py # API test cases
├── models/
│ ├── logistic_regression.pkl
│ ├── ohe.pkl
│ ├── scaler.pkl
├── requirements.txt # Dependencies
├── server.py # API entry point
├── README.md # Project documentation
└── .env # Environment variables
1. Clone the Repository
git clone https://github.com/your-username/Shipment-Delay-API.git
cd Shipment-Delay-API
2. Create a Virtual Environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
3. Install Dependencies
pip install -r requirements.txt
4. Configure Environment Variables
Create a .env file in the project root:
MODEL_PATH=models/model.pkl
ONE_HOT_ENCODER_PATH=models/encoder.pkl
SCALER_PATH=models/scaler.pkl
URL: /
Method: POST
Example Payload:
{
"Distance": 50.0,
"Origin": "Mumbai",
"Destination": "Delhi",
"Shipment Date": "2024-01-01",
"Planned Delivery Date": "2024-01-05",
"Actual Delivery Date": "2024-01-06",
"Vehicle Type": "Truck",
"Weather Conditions": "Fog",
"Traffic Conditions": "Heavy"
}
Response:
- Success (200):
{
"prediction": "Yes"
}
- Error (400):
{
"error": "Bad Request",
"message": "Missing required data"
}
- Flask: Web framework
- Scikit-learn: Model training and predictions
- Gunicorn: WSGI server for production
- Pytest: Unit testing
- Pickle: Model serialization
- Render: Cloud platform for deployment
Run the test suite with:
pytest tests/
- Live Deployment: Click here
- GitHub Repository: Click here
- Documentation: Click here