Skip to content

Abdulwahid7027/Medical-Cost-Prediction-Insurance-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🩺 Medical Cost Insurance Prediction Project

Welcome to the Medical Cost Insurance Prediction Project! This application predicts medical insurance costs using advanced machine learning models. Built with a React frontend and a Flask backend, it allows users to input personal details (age, BMI, smoker status, etc.) and receive accurate cost predictions. The project showcases a full-stack data science pipeline, from data preprocessing to model deployment, finalized on June 21, 2025.


πŸš€ Key Features

  • Predict insurance costs with a Hybrid Ensemble model (XGBoost, CatBoost, LightGBM) achieving RΒ²: 0.8871, RMSE: $4048.21
  • User-friendly React interface styled with Tailwind CSS
  • Robust Flask API serving ML predictions
  • Comprehensive documentation and Git workflow for collaboration

πŸ“– Project Overview

The project uses the insurance.csv dataset (1,338 records) with features like age, sex, bmi, children, smoker, and region to predict charges.
The backend processes data and runs ML models, while the frontend provides an interactive UI.

Ideal for:

  • Data science enthusiasts
  • Developers
  • Academic projects

πŸ› οΈ Tech Stack

  • Frontend: React, Tailwind CSS, JavaScript (CDN-hosted)
  • Backend: Python, Flask, Scikit-learn, XGBoost, CatBoost, LightGBM
  • Tools: Git, Node.js (for frontend dev), Python 3.8+, Conda/Pip, Vercel (for deployment)

πŸ“‚ Folder Structure

health-cost-insurance/
β”‚
β”œβ”€β”€ frontend/                   # React frontend code
β”‚   β”œβ”€β”€ public/
β”‚   β”‚   └── index.html
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.jsx
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   └── styles/
β”‚   β”œβ”€β”€ package.json
β”‚   └── vercel.json
β”‚
β”œβ”€β”€ backend/                    # Flask backend code
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   └── app.py
β”‚   β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ data/
β”‚   β”‚   └── insurance.csv
β”‚   β”œβ”€β”€ requirements.txt
β”‚   β”œβ”€β”€ utils/
β”‚   └── vercel.json
β”‚
β”œβ”€β”€ docs/
β”‚   └── Medical_Cost_Insurance_Prediction_Final_Documentation.md
β”‚
β”œβ”€β”€ .gitignore
└── README.md

βš™οΈ Setup Instructions

πŸ“Œ Prerequisites

  • Git, Node.js v16+, Python 3.8+, Conda (optional)
  • Vercel CLI (npm install -g vercel)
  • GitHub and Vercel accounts

1. Clone the Repository

git clone https://github.com/your-username/health-cost-insurance.git
cd health-cost-insurance

2. Set Up the Backend

cd backend
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt
python api/app.py

Runs at: http://localhost:5000


3. Set Up the Frontend

cd ../frontend
npm install
npm start

Runs at: http://localhost:3000


4. Access the Application

Open your browser at: http://localhost:3000

Input your details (age, BMI, etc.) to get a predicted insurance cost.


πŸ‘¨β€πŸ’» Git Workflow

βœ… Initialize & Push (if new repo)

git init
git add .
git commit -m "Initial commit: Project setup"
git remote add origin https://github.com/your-username/health-cost-insurance.git
git branch -M main
git push -u origin main

βœ… Typical Workflow

git pull origin main  # Get latest
# Edit files
git add .
git commit -m "Your message here"
git push origin main

βœ… Create Feature Branch

git checkout -b feature/your-feature
# Make changes
git add .
git commit -m "Add feature"
git push origin feature/your-feature

Open a Pull Request on GitHub to merge.


πŸš€ Deployment to Vercel

πŸ”Ή Backend (Flask)

  1. backend/requirements.txt must include:
flask==2.0.1
gunicorn
scikit-learn
xgboost
catboost
lightgbm
pandas
numpy
flask-cors
  1. backend/vercel.json:
{
  "version": 2,
  "builds": [
    {
      "src": "api/app.py",
      "use": "@vercel/python"
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "/api/app.py"
    }
  ]
}
  1. Push to GitHub:
cd backend
git add .
git commit -m "Configure Flask for Vercel"
git push origin main
  1. Deploy on Vercel:
  • Import GitHub repo
  • Set backend/ as root
  • Choose "Other" framework
  • Deploy & get backend URL

πŸ”Ή Frontend (React)

  1. frontend/vercel.json:
{
  "rewrites": [
    {
      "source": "/api/(.*)",
      "destination": "https://health-cost-insurance-backend.vercel.app/api/$1"
    }
  ]
}
  1. Update API URLs in App.jsx to use /api/

  2. Push changes:

cd frontend
git add .
git commit -m "Configure React for Vercel"
git push origin main
  1. Deploy on Vercel:
  • Import GitHub repo
  • Set frontend/ as root
  • Detects React, deploys automatically

πŸ§ͺ Post-Deployment

  • Open frontend Vercel URL
  • Test predictions
  • Fix any errors via logs

πŸ“Š Model Performance

Model RΒ² RMSE ($)
XGBoost 0.8685 4517
Hybrid Ensemble 0.8871 4048.21

The Hybrid Ensemble combines XGBoost, CatBoost, and LightGBM to explain 88.71% of the variance with low prediction error.

See docs/Medical_Cost_Insurance_Prediction_Final_Documentation.md for full analysis.


🌟 Contributing

  1. Fork the repo
  2. Create a branch: git checkout -b feature/your-feature
  3. Commit: git commit -m "Add feature"
  4. Push: git push origin feature/your-feature
  5. Open a Pull Request

πŸ“ Documentation

  • Data preprocessing
  • Model training
  • Evaluation metrics
  • Visualizations

See: docs/Medical_Cost_Insurance_Prediction_Final_Documentation.md



πŸ™Œ Acknowledgments

  • Dataset: insurance.csv (public domain)
  • Libraries: Scikit-learn, XGBoost, CatBoost, LightGBM, React, Flask
  • Inspired by real-world healthcare cost prediction problems

πŸ“¬ Contact

Feel free to open an issue or contribute. Happy coding! πŸŽ‰