Skip to content

Repository files navigation

Predicting Health Insurance Costs Using Machine Learning

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.


Live Demo

You can access the live deployed application here: Health Insurance Cost Predictor App

Dashboard Preview

Here’s a screenshot of the interactive Streamlit dashboard:

Health Insurance Cost Predictor Dashboard

Table of Contents


Project Overview

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:

  1. Data Cleaning & Preprocessing: Handle missing values, encode categorical variables, scale features.
  2. Exploratory Data Analysis (EDA): Visualize patterns and relationships between features and target variable.
  3. Modeling: Train multiple regression models including:
    • Linear Regression
    • Polynomial Regression
    • Random Forest Regressor
    • Support Vector Regressor (SVR)
    • XGBoost Regressor
  4. Model Evaluation: Compare models using R², RMSE, and MAE metrics.
  5. Deployment: Build a Streamlit app for interactive predictions.

Dataset

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.


Technologies Used

  • Python 3.9+
  • Pandas, NumPy
  • Matplotlib, Seaborn
  • Scikit-learn
  • XGBoost
  • Streamlit

Installation

  1. Clone this repository:
git clone https://github.com/Dharmendra-07/Health-Insurance-Cost-Predictor.git
cd health-insurance-predictor
  1. Create a virtual environment (optional but recommended):
python3 -m venv venv
source venv/bin/activate   # On Mac/Linux
venv\Scripts\activate      # On Windows
  1. Install required packages:
pip3 install -r requirements.txt

Usage

1. Train Models

Run the Jupyter notebook to explore data, train models, and evaluate their performance:

jupyter notebook

2. Run Streamlit App

Start the interactive web app:

python3 -m streamlit run streamlit_app.py

Open the displayed URL in your browser to interact with the predictor.


Modeling

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.


Evaluation

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.


Deployment

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.py

License

This project is open-source and available under the MIT License.

About

Demonstrates how to predict health insurance costs using Python and machine learning. It covers the full data science workflow: data cleaning, exploration, model training, evaluation, and deployment. The best model achieves an R² score of 84%.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages