Skip to content

A FastAPI-based backend application that provides RESTful APIs for predicting insurance premiums using a trained machine learning model. Designed with a modular structure for easy integration, scalability, and future enhancements.

License

Notifications You must be signed in to change notification settings

harinandanmv/insurance-prediction-backend-fastapi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🛡️ Insurance Prediction Backend (FastAPI)

A scalable and high‑performance FastAPI backend service that exposes REST APIs for predicting insurance premiums using a trained machine learning model. This backend is designed to integrate seamlessly with frontend applications (React, mobile apps) or other services.


🚀 Features

  • ⚡ Built with FastAPI for speed and modern API development
  • 🤖 Machine Learning–powered insurance premium prediction
  • 📄 Automatic API documentation with Swagger UI and ReDoc
  • 🧩 Clean, modular project structure
  • 🔌 Easy integration with frontend and external systems
  • ☁️ Ready for cloud deployment

📁 Project Structure

insurance-prediction-backend-fastapi/
├── model/                  # Saved trained ML models
├── model_train/            # Model training and preprocessing scripts
├── app.py                  # FastAPI application entry point
├── database.py             # Database configuration (optional / extensible)
├── models.py               # Pydantic / ORM models
├── requirements.txt        # Python dependencies
├── .gitignore
└── README.md

🧠 Tech Stack

Layer Technology
Backend Framework FastAPI
Language Python 3.8+
Server Uvicorn
ML Library scikit-learn
API Docs Swagger UI / ReDoc

📌 API Endpoints

Once the server is running, FastAPI provides interactive documentation automatically:

Purpose URL
Swagger UI /docs
ReDoc /redoc
Base URL /

🔮 Prediction Endpoint

POST /predict

Sample Request

{
  "age": 45,
  "bmi": 28.0,
  "children": 2,
  "smoker": "yes",
  "gender": "male",
  "region": "southwest"
}

Sample Response

{
  "predicted_premium": 12345.67
}

⚠️ Input fields depend on the trained model. Update request schema as per your implementation.


🛠️ Installation & Setup

1️⃣ Clone the Repository

git clone https://github.com/harinandanmv/insurance-prediction-backend-fastapi.git
cd insurance-prediction-backend-fastapi

2️⃣ Create a Virtual Environment

python -m venv venv
source venv/bin/activate   # Windows: venv\Scripts\activate

3️⃣ Install Dependencies

pip install -r requirements.txt

4️⃣ Run the Server

uvicorn app:app --reload

Server will start at:

http://127.0.0.1:8000

🧪 Testing the API

You can test the backend using:

  • Swagger UI (/docs)
  • ReDoc (/redoc)
  • Postman / Insomnia
  • curl

Example curl Request

curl -X POST "http://127.0.0.1:8000/predict" \
     -H "Content-Type: application/json" \
     -d '{"age":30,"bmi":26,"children":1,"smoker":"no","gender":"female","region":"northwest"}'

🧾 Model Training

The model_train/ directory contains scripts used to:

  • Load and preprocess the dataset
  • Train the insurance prediction model
  • Save the trained model to the model/ directory

This separation allows independent experimentation and model updates without affecting the API layer.


☁️ Deployment

This backend can be deployed using:

  • Docker
  • AWS / GCP / Azure
  • Render / Railway / Fly.io
  • On‑premise servers

🤝 Contributing

Contributions are welcome!

  1. Fork the repository
  2. Create a new branch
  3. Commit your changes
  4. Open a Pull Request

📜 License

This project is licensed under the MIT License.


⭐ If you find this project useful, consider giving it a star!

About

A FastAPI-based backend application that provides RESTful APIs for predicting insurance premiums using a trained machine learning model. Designed with a modular structure for easy integration, scalability, and future enhancements.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%