A FastAPI-based service that predicts whether a customer will renew their insurance policy, leveraging ensemble machine learning models trained on the “Customer Insurance Policies Prediction” dataset.
.
├── Dockerfile
├── LICENSE
├── Makefile
├── README.md
├── data
│ └── dataset.csv
├── models
│ ├── bagging_model.pkl
│ └── boosting_model.pkl
├── notebooks
│ └── pipeline.ipynb
├── requirements.txt
├── temp
└── webapp
└── app.py
- data/: Raw CSV dataset.
- models/: Serialized
joblibmodels (Random Forest & Gradient Boosting). - notebooks/: EDA and model training pipeline.
- webapp/: FastAPI application source code.
- Dockerfile, Makefile: Containerization and automation scripts.
-
Clone the repository:
git clone https://github.com/your-org/insurance-policy-predictor.git cd insurance-policy-predictor -
Create and activate a virtual environment:
python3 -m venv .venv source .venv/bin/activate -
Install dependencies:
pip install -r requirements.txt
-
Run the API locally:
uvicorn webapp.app:app --reload
- Endpoint:
GET / - Response:
{ "message": "Insurance Policy Renewal Prediction API" }
-
Endpoint:
POST /predict -
Content-Type:
application/json -
Request Example:
{ "age": 30, "driving_license": 1, "region_code": 10, "previously_insured": 0, "annual_premium": 25000.0, "policy_sales_channel": 152, "vintage": 100, "gender": "Male", "vehicle_age": "< 1 Year", "vehicle_damage": "No", "model_type": "bagging" } -
Response Example:
{ "model": "bagging", "prediction": 1, "probability": 0.87 } -
Interactive API docs: Visit
/docsafter starting the server.
To build and run the application using Docker:
docker build -t insurance-predictor .
docker run -p 8000:8000 insurance-predictorAfter hyperparameter tuning:
- Random Forest (Bagging): ~90.7% accuracy
- Gradient Boosting: ~83.5% accuracy