A Streamlit-powered app to estimate individual health insurance premiums in real time.
The Health Insurance Cost Predictor is a Streamlit application that leverages pre-trained regression models to estimate individual health insurance premiums based on user inputs such as age, BMI, smoking status, number of dependents, region, and more. By segmenting users into “young” and “rest” categories with separate models and scalers, the app delivers more accurate predictions for both demographics.
- Interactive UI: Clean, user-friendly sliders, dropdowns, and buttons to enter demographic, lifestyle, and medical attributes.
- Two-Model Approach:
- Young Model: Linear Regressor trained specifically on younger applicants.
- Rest Model: XGBoost Regressor optimized for the general adult population.
- On-the-Fly Prediction: Input parameters are passed through corresponding scalers and models to instantly return a cost estimate.
- Persisted Artifacts: Both models and their associated
Scalerobjects are serialized via Joblib and loaded at runtime. - Lightweight & Fast: Built with Streamlit for rapid prototyping and deployment, no database required.
Health_Insurance_Cost_Predictor/
│
├── artifacts/ # Serialized models and scalers
│ ├── model_rest.joblib # XGBoost model for the general adult population
│ ├── model_young.joblib # Linear Regression model for younger users
│ ├── scaler_rest.joblib # StandardScaler fitted on “rest” training data
│ └── scaler_young.joblib # StandardScaler fitted on “young” training data
│
├── .gitignore # Git ignore rules
├── LICENSE # Apache License file
├── README.md # This documentation
├── main.py # Streamlit app entry point
├── prediction_helper.py # Prediction logic: loading artifacts & processing inputs
└── requirements.txt # Frozen Python dependencies
https://health-insurance-premium-predictor-new.streamlit.app/
- Python 3.8+ installed on your system
pip(Python package installer)- (Optional) A virtual environment tool such as
venvorconda
-
Clone the repository
git clone https://github.com/MindMatrixPro/Health_Insurance_Cost_Predictor.git cd Health_Insurance_Cost_Predictor -
Create and activate a virtual environment (recommended)
python -m venv venv # Windows: venv\Scripts\activate # macOS/Linux: source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
From the project root directory, simply run:
streamlit run main.pyOnce Streamlit finishes loading, it will automatically open a browser window (or show a local URL) where you can interact with the Health Insurance Cost Predictor. If it doesn’t open automatically, navigate to:
http://localhost:8501
-
User Inputs
- Age (years)
- Number of Dependents
- Income in Lakhs
- Genetical Risk (0 = none, 1 = low, 2 = moderate, 3 = high)
- Insurance Plan (e.g., Bronze, Silver, Gold)
- Employment Status (e.g., Salaried, Self-Employed, Unemployed)
- Gender (Male/Female)
- Marital Status (Married/Unmarried)
- BMI Category (Underweight, Normal, Overweight, Obese)
- Smoking Status (No Smoking / Smoker)
- Region (Northeast, Northwest, Southeast, Southwest)
- Medical History (No Disease / Has Disease)
-
Segmentation
- If Age < 30, the app loads
scaler_young.joblibandmodel_young.joblib(Linear Regression). - Otherwise, it loads
scaler_rest.joblibandmodel_rest.joblib(XGBoost Regressor).
- If Age < 30, the app loads
-
Scaling & Prediction
- Input features are preprocessed (one-hot encoding for categorical variables, standardized numeric features via
Scaler). - The appropriate model generates a predicted premium.
- Input features are preprocessed (one-hot encoding for categorical variables, standardized numeric features via
-
Display Result
- The predicted cost is displayed under the “Predict” button in a green info box.
streamlit==1.45.0
numpy==1.26.4
pandas==2.2.3
scikit-learn==1.4.2
xgboost==2.0.3
joblib==1.3.2
If you add or upgrade any packages, remember to run
pip freeze > requirements.txtto update this file.
Contributions, issues, and feature requests are welcome! If you’d like to:
- Fork the repository
- Create a new branch (
git checkout -b feature/<your-feature>) - Commit your changes (
git commit -m "Add <feature>") - Push to the branch (
git push origin feature/<your-feature>) - Open a Pull Request
Please ensure your code follows PEP 8 style and includes any necessary unit or integration tests.
This project is licensed under the Apache License 2.0. See the LICENSE file for details.
Empower yourself with data-driven insights—predict your health insurance premium in seconds!
