A Machine Learning regression project that predicts estimated insurance charges based on customer information.
The project compares multiple regression algorithms and uses the best-performing model to build an interactive Streamlit web application.
π Live Application:
https://ayyan-insurance-charges-prediction.streamlit.app
This project demonstrates an end-to-end Machine Learning workflow for insurance charges prediction.
The following customer information is used for prediction:
- Age
- Sex
- BMI
- Number of Children
- Smoking Status
- Region
Multiple regression algorithms were trained and evaluated to determine the best model for the prediction task.
The final model was integrated into a Streamlit frontend and deployed online.
- Linear Regression
- Decision Tree Regressor
- K-Nearest Neighbors Regressor
- Random Forest Regressor
| Model | RΒ² Score | Adjusted RΒ² | MAE | RMSE |
|---|---|---|---|---|
| Linear Regression | 0.802517 | 0.792410 | 4338.923817 | 6024.004673 |
| Decision Tree | 0.797372 | 0.787001 | 2743.403351 | 6101.977336 |
| KNN | 0.561290 | 0.538837 | 5532.465446 | 8978.616749 |
| Random Forest | 0.882175 | 0.876145 | 2588.687357 | 4653.061926 |
The Random Forest Regressor achieved the best overall performance.
- RΒ² Score: 0.882175
- Adjusted RΒ²: 0.876145
- MAE: 2588.687357
- RMSE: 4653.061926
Random Forest achieved the highest RΒ² and Adjusted RΒ² scores while also achieving the lowest MAE and RMSE.
Therefore, Random Forest was selected as the final model for deployment.
Dataset
β
Data Cleaning
β
Exploratory Data Analysis
β
Feature Engineering
β
Categorical Encoding
β
Train / Test Split
β
Feature Scaling
β
Model Training
β
Model Evaluation
β
Model Comparison
β
Best Model Selection
β
Model Serialization
β
Streamlit Frontend
β
Deployment
Insurance_charges_Prediction/
β
βββ pickles/
β βββ model.pkl
β βββ scalar.pkl
β βββ columns.pkl
β βββ columns_to_scale.pkl
β
βββ app.py
βββ insurance.ipynb
βββ insurance.csv
βββ README.md
βββ requirements.txt
βββ .gitattributes
The Streamlit application provides an interactive interface for estimating insurance charges.
Users can enter:
- Age
- Sex
- BMI
- Number of Children
- Smoking Status
- Region
After submitting the information, the trained Random Forest model generates an estimated insurance charge.
- Modern dark-themed interface
- Responsive design
- Mobile-friendly layout
- Interactive input fields
- Random Forest regression prediction
- Estimated insurance charges
- Premium prediction result dialog
- Deployed Streamlit application
RΒ² measures how much of the variation in the target variable is explained by the model.
Higher values indicate better performance.
Adjusted RΒ² accounts for the number of predictors used by the model.
Higher values indicate better performance.
MAE measures the average absolute difference between actual and predicted values.
Lower values indicate better performance.
RMSE measures the square root of the average squared prediction error and gives greater importance to larger errors.
Lower values indicate better performance.
The model comparison shows that:
- Linear Regression provides a strong baseline.
- Decision Tree achieves relatively low MAE but has a higher RMSE than Random Forest.
- KNN performs significantly worse on this dataset.
- Random Forest provides the strongest overall performance.
The Random Forest model achieves an RΒ² score of approximately 0.88, meaning it explains a large portion of the variation in insurance charges.
The application is deployed using Streamlit Community Cloud.
π Live Application:
https://ayyan-insurance-charges-prediction.streamlit.app
The trained model and preprocessing artifacts are included with the project so the Streamlit application can load them during deployment.
The large model.pkl file is managed using Git Large File Storage (Git LFS).
git clone https://github.com/code-with-ayyan/Insurance_charges_Prediction.gitcd Insurance_charges_Predictionpython -m venv venvLinux:
source venv/bin/activateWindows:
venv\Scripts\activatepip install -r requirements.txtstreamlit run app.py- Python
- NumPy
- Pandas
- Scikit-learn
- Joblib
- Streamlit
- Matplotlib
- Seaborn
The trained model and preprocessing components are saved using Joblib.
pickles/
βββ model.pkl
βββ scalar.pkl
βββ columns.pkl
βββ columns_to_scale.pkl
model.pklβ trained Random Forest regression modelscalar.pklβ fitted feature scalercolumns.pklβ model feature columnscolumns_to_scale.pklβ columns requiring scaling before prediction
The frontend is designed to work across:
- Desktop
- Laptop
- Tablet
- Mobile
The interface automatically adapts to smaller screen sizes for a better user experience.
The predicted value is a machine-learning estimate and should not be considered an official insurance quote.
Actual insurance charges may vary depending on the insurance provider, policy, coverage, location, customer profile, and other factors.
This project is intended for educational and demonstration purposes.
This project helped in understanding:
- Regression problems
- Feature preprocessing
- Categorical encoding
- Feature scaling
- Train-test splitting
- Regression model comparison
- Evaluation metrics
- Random Forest Regression
- Model serialization
- Streamlit application development
- Machine Learning deployment
Ayyan Ahmed
Machine Learning & AI Student
Building and understanding Machine Learning algorithms from fundamentals to deployment.