An end-to-end Machine Learning application that predicts insurance premium categories based on customer demographics, lifestyle factors, health indicators, and financial information.
The project follows a complete MLOps-inspired workflow:
- Data Analysis & Feature Engineering
- Random Forest Classification Model
- FastAPI REST API Development
- Pydantic Request Validation
- Interactive Streamlit Frontend
- Cloud Deployment on Render
https://insurance-premium-prediction-api-serving.onrender.com
https://insurance-premium-prediction-api-serving-98v3.onrender.com/
- Open the API documentation link first.
- Wait for the API to respond successfully.
- Open the Streamlit application.
- Enter the required details and generate a prediction.
The backend is hosted on Render and may enter a sleep state after periods of inactivity. The first request may take a little longer while the server wakes up. Once initialized, the application should respond normally.
The project is also available as a Docker image on Docker Hub.
Docker Hub Repository
https://hub.docker.com/r/omikalix/insurance-premium-app
docker pull omikalix/insurance-premium-appdocker run -p 8000:8000 -p 8501:8501 omikalix/insurance-premium-app- Streamlit UI: http://127.0.0.1:8501
- FastAPI Docs: http://127.0.0.1:8000/docs
Note: The services listen on
0.0.0.0inside the container but should be accessed through127.0.0.1orlocalhostfrom your browser.
Insurance companies determine premium categories based on multiple factors such as:
- Age
- BMI
- Smoking Habits
- Income
- Occupation
- City Tier
- Lifestyle Risk
This project leverages Machine Learning to automate premium category prediction.
The model classifies customers into:
| Category | Meaning |
|---|---|
| π’ Low | Lower insurance risk |
| π‘ Medium | Moderate insurance risk |
| π΄ High | Higher insurance risk |
User
β
βΌ
Streamlit UI
β
βΌ
FastAPI REST API
β
βΌ
Random Forest Model (.pkl)
β
βΌ
Prediction Response
serving-ml-models/
β
βββ images/
β βββ low.png
β βββ medium.png
β βββ high.png
β βββ background_image.png
β
βββ model.ipynb
βββ insurance_premium_model.pkl
βββ insurance_premium_api.py
βββ UI.py
βββ Indian_Insurance_Data.csv
β
βββ requirements.txt
βββ README.md
| Feature | Description |
|---|---|
| age | Customer age |
| weight | Weight in kg |
| height | Height in meters |
| income_lpa | Annual income |
| smoker | Smoking status |
| city | Customer city |
| occupation | Occupation |
The following custom features were created:
BMI = weight / (height ** 2)income_lpa / ageweight / heightincome_lpa * bmismoker * income_lpa(bmi * 0.4) + (age * 0.3) + (smoker * 20)Tier 1
Tier 2
Tier 3
RandomForestClassifier()- One Hot Encoding
- Feature Engineering
- Pipeline Architecture
- Column Transformer
80% Training
20% Testing| Class | Precision | Recall | F1 |
|---|---|---|---|
| High | 0.91 | 0.90 | 0.91 |
| Low | 0.91 | 0.93 | 0.92 |
| Medium | 0.88 | 0.87 | 0.87 |
Accuracy : 89.63%
Macro F1 Score : 0.90
Fold 1 : 89.25%
Fold 2 : 89.63%
Fold 3 : 87.25%
Fold 4 : 90.75%
Fold 5 : 91.75%
Mean CV Accuracy : 89.73%
Top contributing features:
1. Health Risk Index
2. BMI
3. Age
4. Weight Height Ratio
5. Smoker Income
6. Income (LPA)
7. Income Γ BMI
8. Income Per Age
Key Insight:
Insurance premium category is primarily influenced by:
- Health Risk
- BMI
- Age
- Smoking Status
- Income
while City Tier and Occupation contribute less to prediction.
The backend API is developed using:
- FastAPI
- Pydantic
- Uvicorn
- Request Validation
- JSON Response
- Interactive Swagger Documentation
- Fast Prediction Serving
POST /predict{
"age": 30,
"weight": 70,
"height": 1.75,
"income_lpa": 12,
"smoker": 0,
"city": "Pune",
"occupation": "Software Engineer"
}{
"predicted_insurance_premium_category": "Low"
}The project includes an interactive Streamlit application featuring:
- Modern Insurance Dashboard
- Dynamic Background Design
- Interactive Form Inputs
- Real-Time Predictions
- Personalized Recommendations
- Category-Based Visual Cards
π’ Low Premium
- Low Risk
- High Savings
- Healthy Lifestyle
π‘ Medium Premium
- Balanced Risk
- Balanced Coverage
π΄ High Premium
- Higher Risk
- Enhanced Protection
The application generates dynamic recommendations based on:
- BMI
- Age
- Income
- Occupation
- Smoking Status
- Predicted Premium Category
Examples:
π Quit smoking to reduce risk.
π Maintain a healthy BMI.
π©Ί Schedule annual checkups.
π° Build an emergency healthcare fund.
Clone Repository
git clone https://github.com/yourusername/insurance-premium-prediction.gitMove into Project
cd insurance-premium-predictionInstall Dependencies
pip install -r requirements.txtuvicorn insurance_premium_api:app --reloadAPI Docs
http://127.0.0.1:8000/docs
streamlit run UI.pyThis project is fully deployed on Render.
β FastAPI Backend
β Streamlit Frontend
- Render
- FastAPI
- Streamlit
- Uvicorn
- Random Forest Model
OMKAR SAWANT
Dataset: Health Insurance Dataset by Parth Patel
Source: https://www.kaggle.com/datasets/patelparth3399/indian-insurance-premium-prediction-dataset
License: MIT

