Skip to content

anujjainbatu/insurance-premium-prediction-fastapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

insurance-premium-prediction-fastapi

This project is an Insurance Premium Prediction API built with FastAPI. The main objective is not only to provide a working insurance premium prediction service, but also to serve as a blueprint for building industry-grade FastAPI applications. The codebase demonstrates best practices in API design, modular code organization, input/output validation, and production readiness.

Features

  • FastAPI: High-performance, easy-to-use Python web framework.
  • Modular Structure: Clear separation of models, schemas, and API logic.
  • Input Validation: Uses Pydantic for robust request/response validation.
  • Prediction Endpoint: /predict endpoint for premium category prediction.
  • Health Check: /health endpoint for service monitoring.
  • Interactive Docs: Swagger UI available at /docs.
  • Error Handling: Graceful error responses for invalid requests or server issues.
  • Production Ready: Example .gitignore, clear project structure, and extensible code.

Demo

Below is a demonstration of the working product:

Insurance Premium Prediction API Demo

Docker Hub

You can pull the pre-built Docker image from Docker Hub:

https://hub.docker.com/r/anujjainbatu/insurance-premium-api

docker pull anujjainbatu/insurance-premium-api

API Link

Once running (locally or via Docker), access the API at:

Public API Endpoint

If you want to use this API in your own application, you can access the deployed instance at:

Feel free to integrate this endpoint directly into your projects for insurance premium

Project Structure

insurance-premium-prediction/
│
├── app.py                      # Main FastAPI application
├── model/
│   └── predict.py              # Model loading and prediction logic
│   └── model.pkl               # Serialized ML model (not included in repo)
├── schema/
│   ├── user_input.py           # Pydantic model for input validation
│   └── prediction_response.py  # Pydantic model for output schema
├── venv/                       # Virtual environment (excluded from git)
├── README.md                   # Project documentation
├── .gitignore                  # Git ignore file
└── ...

Getting Started

  1. Clone the repository

    git clone <repo-url>
    cd insurance-premium-prediction
  2. Create and activate a virtual environment

    python3 -m venv venv
    source venv/bin/activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Run the API

    uvicorn app:app --reload
  5. Access the API

Example Request

POST /predict

{
  "bmi": 27.5,
  "lifestyle_risk": "medium",
  "age_group": "30-40",
  "city_tier": "tier_1",
  "income_lpa": 12,
  "occupation": "salaried"
}

Response

{
  "premium_category": "Medium",
  "confidence": 0.85,
  "class_probabilities": {
    "Low": 0.1,
    "Medium": 0.2,
    "High": 0.7
  }
}

Notes

  • This project is intended as a reference for building scalable, maintainable FastAPI applications in a production setting.

License

MIT License


Blueprint for Industry-Grade FastAPI Apps
Use this project as a starting point for your own robust, production-ready APIs!

About

A FastAPI-based Insurance Premium Prediction API designed as a blueprint for building scalable, production-ready, and industry-grade FastAPI applications. Demonstrates best practices in modular architecture, input/output validation, error handling, and API documentation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors