In this project, we build a machine learning model to predict health insurance costs based on customer demographics and lifestyle factors. The project takes you step by step through the entire data science workflow — from data cleaning and exploration to building, evaluating, and deploying predictive models. We achieve an R² score of 84%, demonstrating strong predictive performance.
Additionally, we deploy the model as an interactive web application using Streamlit, allowing users to input features and see real-time predictions for health insurance costs.
You can access the live deployed application here: Health Insurance Cost Predictor App
Here’s a screenshot of the interactive Streamlit dashboard:
- Project Overview
- Dataset
- Technologies Used
- Installation
- Usage
- Modeling
- Evaluation
- Deployment
- License
The goal of this project is to predict an individual’s health insurance cost based on features such as:
- Age
- Sex
- Body Mass Index (BMI)
- Number of children
- Smoking status
- Region
We follow a complete machine learning workflow:
- Data Cleaning & Preprocessing: Handle missing values, encode categorical variables, scale features.
- Exploratory Data Analysis (EDA): Visualize patterns and relationships between features and target variable.
- Modeling: Train multiple regression models including:
- Linear Regression
- Polynomial Regression
- Random Forest Regressor
- Support Vector Regressor (SVR)
- XGBoost Regressor
- Model Evaluation: Compare models using R², RMSE, and MAE metrics.
- Deployment: Build a Streamlit app for interactive predictions.
The dataset contains the following columns:
| Column | Description |
|---|---|
| age | Age of the individual |
| sex | Gender (male/female) |
| bmi | Body Mass Index |
| children | Number of children covered by health insurance |
| smoker | Smoking status (yes/no) |
| region | Residential region (northeast, northwest, southeast, southwest) |
| charges | Health insurance charges (target variable) |
You can find the dataset in Kaggle: Medical Cost Personal Dataset.
- Python 3.9+
- Pandas, NumPy
- Matplotlib, Seaborn
- Scikit-learn
- XGBoost
- Streamlit
- Clone this repository:
git clone https://github.com/Dharmendra-07/Health-Insurance-Cost-Predictor.git
cd health-insurance-predictor- Create a virtual environment (optional but recommended):
python3 -m venv venv
source venv/bin/activate # On Mac/Linux
venv\Scripts\activate # On Windows- Install required packages:
pip3 install -r requirements.txtRun the Jupyter notebook to explore data, train models, and evaluate their performance:
jupyter notebookStart the interactive web app:
python3 -m streamlit run streamlit_app.pyOpen the displayed URL in your browser to interact with the predictor.
We experimented with multiple regression algorithms:
| Model | R² Score |
|---|---|
| Linear Regression | 0.75 |
| Polynomial Regression | 0.79 |
| Random Forest Regressor | 0.82 |
| SVR | 0.78 |
| XGBoost Regressor | 0.84 |
The XGBoost Regressor achieved the best performance and is used in the Streamlit app.
We evaluated models using:
- R² Score (coefficient of determination)
- Root Mean Squared Error (RMSE)
- Mean Absolute Error (MAE)
Visualizations and detailed evaluation metrics can be found in the notebook.
The model is deployed as an interactive Streamlit app. Features:
- Input user data (age, BMI, smoking status, etc.)
- Predict health insurance cost in real-time
- User-friendly interface with sliders and dropdowns
Run the app:
python3 -m streamlit run streamlit_app.pyThis project is open-source and available under the MIT License.
