Medical Insurance Cost Prediction
End-to-end regression pipeline predicting annual medical charges at R² 0.90, served through an interactive Streamlit app.
Test R²
Test RMSE
Records modelled
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
Architecture
The end-to-end flow from raw data to a shipped result.
Explore
EDA on 1,337 records
Preprocess
Scale + one-hot in a Pipeline
Tune
4 models, CV + GridSearch
Deploy
Streamlit prediction app