Skip to content

sat-06/InsurAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

49 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿฅ InsurAI โ€” Intelligent Health Insurance Analytics Platform

InsurAI is an end-to-end Machine Learning powered health insurance analytics platform that predicts medical insurance charges, evaluates customer health risk, segments customers using clustering, and generates underwriting recommendations.

The project integrates a trained Machine Learning model with a FastAPI backend and a modern Next.js frontend to provide real-time insurance analytics through an interactive dashboard.


๐Ÿš€ Overview

Traditional insurance cost estimation often relies on broad assumptions and manual risk assessment.

InsurAI demonstrates how Machine Learning and rule-based analytics can be combined to build an intelligent insurance decision-support system.

The platform processes customer information through a complete analytics pipeline:

Customer Information
        โ†“
Insurance Charge Prediction
        โ†“
Health Risk Assessment
        โ†“
Customer Segmentation
        โ†“
Underwriting Recommendation
        โ†“
Interactive Dashboard

โœจ Key Features

๐Ÿ’ฐ Insurance Charge Prediction

Predicts estimated medical insurance charges based on customer information such as:

  • Age
  • Gender
  • BMI
  • Number of Children
  • Smoking Status

The prediction model is trained using historical medical insurance data.

Example output:

Predicted Insurance Charges: โ‚น24,850

๐Ÿ“Š Health Risk Scoring

Calculates a health risk score from 0โ€“100 using factors such as:

  • Age
  • BMI
  • Smoking Status
  • Number of Children

Customers are categorized into:

  • Low Risk
  • Moderate Risk
  • High Risk

Example:

Risk Score: 64.5
Risk Category: High Risk

๐Ÿ‘ฅ Customer Segmentation

Uses K-Means Clustering to group customers based on:

  • Age
  • BMI
  • Number of Children
  • Predicted Insurance Charges

Customer segments include:

  • Young Healthy Adult
  • Family Protector
  • High Risk Individual
  • Senior Citizen

Example:

Cluster: 1
Segment: Family Protector

๐Ÿ“‹ Underwriting Recommendation Engine

Generates underwriting recommendations based on:

  • Health Risk Score
  • Predicted Insurance Charges

Possible recommendations include:

Basic Coverage
Standard Coverage
Premium Plan + Medical Screening

Example:

Risk Level: High

Recommendation:
Premium Plan + Medical Screening

๐ŸŒ REST API Backend

The backend is built using FastAPI and exposes REST API endpoints for each analytics feature.

Available endpoints:

Method Endpoint Description
GET / API health/welcome endpoint
POST /predict Predict insurance charges
POST /risk-score Calculate health risk score
POST /segment Predict customer segment
POST /underwriting Generate underwriting recommendation

Interactive API documentation is available through Swagger UI.

http://127.0.0.1:8000/docs

๐Ÿ–ฅ๏ธ Interactive Frontend Dashboard

The frontend is built with Next.js and TypeScript.

It provides:

  • Customer profile input form
  • Real-time prediction results
  • Insurance charge visualization
  • Health risk score display
  • Customer segment display
  • Underwriting recommendation
  • Loading states
  • Error handling
  • Responsive design
  • Smooth UI animations

๐Ÿ”„ End-to-End Prediction Pipeline

When a user submits customer information, the frontend executes the following pipeline:

Next.js Prediction Form
        โ†“
POST /predict
        โ†“
Predicted Insurance Charges
        โ†“
POST /risk-score
        โ†“
Risk Score + Risk Category
        โ†“
POST /segment
        โ†“
Customer Segment
        โ†“
POST /underwriting
        โ†“
Risk Level + Recommendation
        โ†“
Interactive Results Dashboard

This demonstrates complete integration between:

Frontend
   โ†“
REST API
   โ†“
Machine Learning Model
   โ†“
Analytics Engines
   โ†“
Dashboard

๐Ÿง  Machine Learning Workflow

1. Data Exploration

The dataset was analyzed to understand:

  • Feature distributions
  • Relationships between variables
  • Correlation with insurance charges
  • Impact of smoking
  • Impact of BMI
  • Impact of age

2. Data Preprocessing

The preprocessing workflow includes:

  • Data inspection
  • Categorical encoding
  • Feature engineering
  • Feature selection
  • Train-test splitting

3. Feature Engineering

Additional BMI-based categories were explored during preprocessing:

Underweight
Normal
Overweight
Obese

Categorical variables were converted into machine-readable numerical representations.


4. Insurance Charge Prediction

A regression model predicts medical insurance charges.

Core input features used by the deployed prediction pipeline:

age
sex
bmi
children
smoker

5. Customer Segmentation

K-Means Clustering is used for unsupervised customer segmentation.

Clustering features:

age
bmi
children
predicted_charges

The clustering pipeline uses feature scaling before K-Means prediction.


๐Ÿ› ๏ธ Tech Stack

Frontend

  • Next.js
  • React
  • TypeScript
  • Tailwind CSS
  • Framer Motion
  • Axios
  • Lucide React

Backend

  • FastAPI
  • Python
  • Uvicorn

Machine Learning & Data Science

  • Scikit-learn
  • Pandas
  • NumPy
  • Joblib
  • Jupyter Notebook

Development Tools

  • Git
  • GitHub
  • VS Code
  • Swagger UI

๐Ÿ“‚ Project Structure

InsurAI/
โ”‚
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ app.py
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”‚   โ”œโ”€โ”€ predict.py
โ”‚   โ”‚   โ”œโ”€โ”€ risk.py
โ”‚   โ”‚   โ”œโ”€โ”€ segmentation.py
โ”‚   โ”‚   โ””โ”€โ”€ underwriting.py
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ utils/
โ”‚       โ”œโ”€โ”€ risk_score.py
โ”‚       โ”œโ”€โ”€ segment.py
โ”‚       โ””โ”€โ”€ underwriting_rules.py
โ”‚
โ”œโ”€โ”€ dataset/
โ”‚   โ””โ”€โ”€ insurance.csv
โ”‚
โ”œโ”€โ”€ frontend/
โ”‚   โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”œโ”€โ”€ lib/
โ”‚   โ”œโ”€โ”€ public/
โ”‚   โ”œโ”€โ”€ types/
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ””โ”€โ”€ tailwind.config.ts
โ”‚
โ”œโ”€โ”€ ml/
โ”‚   โ”œโ”€โ”€ notebooks/
โ”‚   โ”‚   โ””โ”€โ”€ Model_Training.ipynb
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ saved_models/
โ”‚   โ”‚   โ”œโ”€โ”€ insurance_model.pkl
โ”‚   โ”‚   โ”œโ”€โ”€ feature_names.pkl
โ”‚   โ”‚   โ”œโ”€โ”€ kmeans_model.pkl
โ”‚   โ”‚   โ””โ”€โ”€ scaler.pkl
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ training/
โ”‚       โ””โ”€โ”€ customer_segmentation.py
โ”‚
โ””โ”€โ”€ README.md

๐Ÿ“Š Dataset

The project uses a medical insurance dataset containing customer demographic and health-related information.

Feature Description
age Age of insured person
sex Gender
bmi Body Mass Index
children Number of dependents
smoker Smoking status
region Residential region
charges Medical insurance charges

Target variable:

charges

โš™๏ธ Running the Project Locally

1. Clone the Repository

git clone <your-repository-url>
cd InsurAI

2. Install Backend Dependencies

pip install fastapi uvicorn pandas numpy scikit-learn joblib

3. Start the FastAPI Backend

From the project root:

python -m uvicorn backend.app:app --reload

Backend server:

http://127.0.0.1:8000

Swagger documentation:

http://127.0.0.1:8000/docs

4. Install Frontend Dependencies

Open another terminal:

cd frontend
npm install

5. Start the Next.js Frontend

npm run dev

Frontend application:

http://localhost:3000

๐Ÿ“ก API Examples

Insurance Charge Prediction

Endpoint:

POST /predict

Example request:

{
  "age": 25,
  "sex": "male",
  "bmi": 24.5,
  "children": 1,
  "smoker": "no"
}

Example response:

{
  "predicted_charges": 8420.5
}

Health Risk Score

Endpoint:

POST /risk-score

Example request:

{
  "age": 25,
  "bmi": 24.5,
  "smoker": "no",
  "children": 1
}

Example response:

{
  "risk_score": 24.25,
  "risk_category": "Low Risk"
}

Customer Segmentation

Endpoint:

POST /segment

Example request:

{
  "age": 25,
  "bmi": 24.5,
  "children": 1,
  "predicted_charges": 8420.5
}

Example response:

{
  "cluster": 0,
  "segment": "Young Healthy Adult"
}

Underwriting Recommendation

Endpoint:

POST /underwriting

Example request:

{
  "risk_score": 24.25,
  "predicted_charges": 8420.5
}

Example response:

{
  "risk_level": "Low",
  "recommendation": "Basic Coverage"
}

๐ŸŽฏ Use Cases

For Customers

  • Estimate potential medical insurance charges
  • Understand health risk classification
  • Receive a simplified insurance profile

For Insurance Analytics

  • Customer risk profiling
  • Customer segmentation
  • Underwriting decision support
  • Data-driven insurance analytics

๐Ÿ“ธ Screenshots

Add screenshots of the working application here.

Suggested screenshots:

1. Landing Page
2. Prediction Form
3. Complete Prediction Dashboard
4. Swagger API Documentation

Example:

![InsurAI Landing Page](docs/screenshots/landing-page.png)

![Prediction Dashboard](docs/screenshots/prediction-dashboard.png)

๐Ÿ”ฎ Future Enhancements

Potential future improvements include:

  • SHAP-based model explainability
  • Advanced ensemble regression models
  • Model comparison experiments
  • Database-backed prediction history
  • User authentication
  • Cloud deployment
  • Docker containerization
  • Automated testing
  • CI/CD pipeline
  • Model monitoring
  • Real claim prediction using claim-labeled datasets

๐Ÿ“š What This Project Demonstrates

InsurAI demonstrates practical experience with:

  • End-to-end Machine Learning development
  • Regression modeling
  • Unsupervised learning with K-Means
  • Feature preprocessing
  • Model serialization with Joblib
  • REST API development with FastAPI
  • Frontend development with Next.js
  • Type-safe API integration with TypeScript
  • Frontend-backend integration
  • Error handling
  • ML model deployment architecture

๐Ÿ‘จโ€๐Ÿ’ป Author

Satyam Kulkarni

AI & Data Science Student


โญ Project Status

InsurAI v1 โ€” Completed

Core functionality is implemented and working end-to-end:

  • โœ… Insurance Charge Prediction
  • โœ… Health Risk Scoring
  • โœ… Customer Segmentation
  • โœ… Underwriting Recommendation
  • โœ… FastAPI Backend
  • โœ… Next.js Frontend
  • โœ… Frontend-Backend Integration

About

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors