An end-to-end machine learning project that predicts individual medical insurance charges using Linear Regression and statistical analysis.
The project covers data preprocessing, missing-value treatment, outlier analysis, statistical testing, feature engineering, model training, evaluation, and deployment using Streamlit.
Medical insurance charges can vary depending on factors such as age, BMI, smoking status, number of children, and other demographic characteristics.
This project develops a machine learning system to predict individual medical insurance charges based on available demographic and health-related features.
The project follows an end-to-end machine learning workflow, starting from data preprocessing and statistical analysis and continuing through model training, evaluation, and deployment.
- Data cleaning and preprocessing
- Missing-value treatment
- Distribution and skewness analysis
- Outlier detection and treatment using IQR
- Correlation analysis
- Multicollinearity analysis using VIF
- Statistical hypothesis testing using T-Test and ANOVA
- Feature engineering and encoding
- Feature scaling
- Linear Regression model training
- Model evaluation
- Bias-variance analysis
- Model saving using Joblib
- Interactive prediction using Streamlit
The project uses an insurance dataset containing demographic and health-related attributes that influence individual medical insurance charges.
The target variable is:
- Charges — Individual medical insurance cost
The input features are used to analyze relationships with insurance charges and build the prediction model.
The project follows the following workflow:
The dataset is first inspected and cleaned to prepare it for machine learning.
This includes:
- Identifying missing values
- Handling missing values using appropriate statistical methods
- Checking data distributions
- Analyzing skewness in numerical features
Missing values are handled based on the characteristics of the data.
- Mean or median imputation is used for numerical features
- Mode imputation is used for categorical features
- Median imputation is preferred for skewed numerical distributions
Outliers are analyzed using box plots and the Interquartile Range (IQR) method.
The identified outliers are evaluated and treated to improve the quality of the dataset before model training.
Statistical techniques are used to understand relationships between features and insurance charges.
The analysis includes:
- Correlation analysis
- Correlation matrix
- Variance Inflation Factor (VIF)
- T-Test
- ANOVA
These techniques help identify significant features and analyze multicollinearity among predictors.
After preprocessing and feature engineering, the dataset is prepared for machine learning.
The workflow includes:
- Encoding categorical variables
- Splitting the dataset into training and testing sets
- Scaling numerical features
- Training a Linear Regression model
- Saving the trained model for later predictions
Linear Regression is used to model the relationship between the input features and medical insurance charges.
The trained model learns from the training data and predicts insurance charges for previously unseen input data.
The model performance is evaluated using multiple regression metrics:
- R² Score — Measures how well the model explains the variation in the target variable.
- Mean Absolute Error (MAE) — Measures the average absolute difference between predicted and actual charges.
- Mean Squared Error (MSE) — Measures the average squared prediction error.
- Root Mean Squared Error (RMSE) — Measures the square root of MSE and indicates the typical magnitude of prediction errors.
The project also includes bias-variance analysis to assess the model's ability to generalize beyond the training data.
The trained machine learning model is saved using Joblib and integrated into a Streamlit application.
The Streamlit application provides an interactive interface where users can enter insurance-related information and receive a predicted insurance cost.
The application:
- Accepts user input through an interactive interface
- Applies the same preprocessing and feature scaling used during training
- Loads the saved Linear Regression model
- Generates an insurance cost prediction
- Displays the predicted result to the user
This allows the trained machine learning model to be used through a simple web-based interface.
- Python
- Pandas
- NumPy
- Matplotlib
- Seaborn
- Scikit-learn
- SciPy
- Streamlit
- Joblib
- GitHub
Insurance-Charges/
│
├── app.py.py
├── linear_regression_model.joblib
├── scaler.pkl
├── requirements.txt
└── runtime.txt
- End-to-end machine learning workflow
- Statistical analysis before model development
- Missing-value and outlier treatment
- Feature selection and multicollinearity analysis
- Linear Regression for insurance cost prediction
- Multiple regression evaluation metrics
- Bias-variance analysis
- Model persistence using Joblib
- Interactive Streamlit application
- Practical application of Data Science concepts
This project is developed for educational and demonstration purposes.
The predicted insurance cost is an estimated output from a machine learning model and should not be considered a guaranteed real-world insurance quotation or financial advice.