All projects
Machine Learning2026

Medical Insurance Cost Prediction

End-to-end regression pipeline predicting annual medical charges at R² 0.90, served through an interactive Streamlit app.

PythonScikit-learnHistGradientBoostingStreamlitPandas
0

Test R²

$0

Test RMSE

0

Records modelled

0

Models compared

Overview

A complete supervised-regression project that predicts an individual's annual medical insurance charge from six demographic and lifestyle features. It spans the full lifecycle — EDA, a scikit-learn preprocessing + model Pipeline, cross-validated comparison of four algorithms, GridSearch tuning of a HistGradientBoosting model, held-out evaluation, model persistence, and a deployed Streamlit app with a live smoker 'what-if' counterfactual.

Features

  • Single scikit-learn Pipeline (preprocessing + model) — zero train/serve skew
  • Four models compared with 5-fold cross-validation
  • HistGradientBoosting tuned via GridSearchCV
  • Reached test R² 0.897 (RMSE ≈ $4.4k) on a held-out set
  • Permutation importance + smoker counterfactual for interpretability
  • Interactive Streamlit app with real-time predictions

Challenges

  • Linear baselines plateaued at R² ≈ 0.73 — capturing the smoker × BMI interaction needed a tree ensemble.
  • Preventing data leakage by fitting all preprocessing inside cross-validation folds.
  • Serving raw records safely by bundling preprocessing into the persisted pipeline.

Results

Choosing a model family that captures interactions lifted performance from R² ≈ 0.73 (linear) to 0.897 with tuned HistGradientBoosting. Permutation importance confirmed smoking as the dominant cost driver, and the Streamlit app makes that tangible through a real-time smoker counterfactual.

Screenshots

Streamlit predictor UI
Streamlit predictor UI
Predicted vs. actual charges
Predicted vs. actual charges
Permutation feature importance
Permutation feature importance
How it works

Architecture

The end-to-end flow from raw data to a shipped result.

01

Explore

EDA on 1,337 records

02

Preprocess

Scale + one-hot in a Pipeline

03

Tune

4 models, CV + GridSearch

04

Deploy

Streamlit prediction app

Keep exploring

Other projects