Skip to content

API to predict whether a shipment in transit will be delayed or not, based on shipment details.

Notifications You must be signed in to change notification settings

Adm-2005/Shipment-Delay-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📦Shipment Delay Prediction API

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%.

🌐 Live Deployment

The API is deployed and accessible at: https://shipment-delay-api.onrender.com

📂 Project Structure

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

🛠️ Setup Instructions

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

📝 API Endpoints

Predict Shipment Delay

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"
}

🛠️ Technologies Used

  • 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

🧪 Testing the API

Run the test suite with:

pytest tests/

📎 Important Links

About

API to predict whether a shipment in transit will be delayed or not, based on shipment details.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published