# rohan6162/medical-insurance-cost-prediction architecture

> Architecture diagram of the GitHub repository rohan6162/medical-insurance-cost-prediction, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rohan6162/medical-insurance-cost-prediction
- Repository: https://github.com/rohan6162/medical-insurance-cost-prediction

## Overview

This repository is a medical-insurance charge estimation project: it explores and preprocesses a dataset, trains and compares regressors, analyzes feature importance, and serves estimates through Streamlit. The main user workflow is entering personal and lifestyle details in the app, which encodes them into the model’s feature columns and predicts charges with the saved Random Forest. Source excerpts support the analysis, training, artifact, and prediction links; README documents the broader workflow and reported comparison results.

Main entry points: [`data/insurance.csv`](https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/data/insurance.csv) (Insurance dataset), [`models/random_forest_model.pkl`](https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/models/random_forest_model.pkl) (Saved Random Forest), [`save_model.py`](https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/save_model.py) (Random Forest training), [`feature_importance.py`](https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/feature_importance.py) (Feature importance)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data exploration"]
  node_dataset["Insurance dataset<br/>[insurance.csv]"]
  node_data_profile["Dataset profiling<br/>[data_analysis.py]"]
  node_encoding["Feature encoding<br/>[preprocess.py]"]
  node_eda["Exploratory plots<br/>[eda.py]"]
end

subgraph group_modeling["Model development"]
  node_model_training["Regressor evaluation<br/>[train_models.py]"]
  node_saved_training["Random Forest training<br/>[save_model.py]"]
  node_model_artifact["Saved Random Forest"]
  node_feature_names["Feature order<br/>[feature_names.pkl]"]
end

subgraph group_insights["Model insights"]
  node_importance["Feature importance"]
  node_importance_results["Importance results"]
  node_comparison_plots["Comparison plots"]
end

subgraph group_serving["Prediction app"]
  node_app["Streamlit prediction<br/>[app.py]"]
  node_prediction_helper["Prediction helper<br/>[predict.py]"]
end

node_user(("Insurance applicant"))

node_data_profile -->|"reads"| node_dataset
node_encoding -->|"reads"| node_dataset
node_eda -->|"plots"| node_dataset
node_model_training -->|"trains on"| node_dataset
node_saved_training -->|"trains on"| node_dataset
node_saved_training -->|"saves model"| node_model_artifact
node_saved_training -->|"saves columns"| node_feature_names
node_importance -->|"reads"| node_dataset
node_importance -->|"loads"| node_model_artifact
node_importance -->|"writes"| node_importance_results
node_comparison_plots -.->|"compares metrics"| node_dataset
node_user -->|"enters details"| node_app
node_app -->|"predicts with"| node_model_artifact
node_app -->|"orders columns"| node_feature_names
node_prediction_helper -->|"predicts with"| node_model_artifact
node_prediction_helper -->|"orders columns"| node_feature_names

click node_dataset "https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/data/insurance.csv"
click node_data_profile "https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/data_analysis.py"
click node_encoding "https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/preprocess.py"
click node_eda "https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/eda.py"
click node_model_training "https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/train_models.py"
click node_saved_training "https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/save_model.py"
click node_model_artifact "https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/models/random_forest_model.pkl"
click node_feature_names "https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/models/feature_names.pkl"
click node_importance "https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/feature_importance.py"
click node_importance_results "https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/models/feature_importance.csv"
click node_comparison_plots "https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/model_comparison.py"
click node_app "https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/app.py"
click node_prediction_helper "https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/predict.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_dataset,node_data_profile,node_encoding,node_eda toneBlue
class node_model_training,node_saved_training,node_model_artifact,node_feature_names toneAmber
class node_importance,node_importance_results,node_comparison_plots toneMint
class node_app,node_prediction_helper toneRose
class node_user toneIndigo
```

## Components

### Data exploration

- [Insurance dataset](https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/data/insurance.csv): `data/insurance.csv`
- [Dataset profiling](https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/data_analysis.py): `data_analysis.py`
- [Feature encoding](https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/preprocess.py): `preprocess.py`
- [Exploratory plots](https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/eda.py): `eda.py`

### Model development

- [Regressor evaluation](https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/train_models.py): `train_models.py`
- [Random Forest training](https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/save_model.py): `save_model.py`
- [Saved Random Forest](https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/models/random_forest_model.pkl): `models/random_forest_model.pkl`
- [Feature order](https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/models/feature_names.pkl): `models/feature_names.pkl`

### Model insights

- [Feature importance](https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/feature_importance.py): `feature_importance.py`
- [Importance results](https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/models/feature_importance.csv): `models/feature_importance.csv`
- [Comparison plots](https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/model_comparison.py): `model_comparison.py`

### Prediction app

- [Streamlit prediction](https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/app.py): `app.py`
- [Prediction helper](https://github.com/rohan6162/medical-insurance-cost-prediction/blob/main/predict.py): `predict.py`

### Other components

- **Insurance applicant**

## Connections

- Dataset profiling → Insurance dataset: reads (evidence: `data_analysis.py`)
- Feature encoding → Insurance dataset: reads (evidence: `preprocess.py`)
- Exploratory plots → Insurance dataset: plots (evidence: `eda.py`)
- Regressor evaluation → Insurance dataset: trains on (evidence: `train_models.py`)
- Random Forest training → Insurance dataset: trains on (evidence: `save_model.py`)
- Random Forest training → Saved Random Forest: saves model (evidence: `save_model.py`)
- Random Forest training → Feature order: saves columns (evidence: `save_model.py`)
- Feature importance → Insurance dataset: reads (evidence: `feature_importance.py`)
- Feature importance → Saved Random Forest: loads (evidence: `feature_importance.py`)
- Feature importance → Importance results: writes (evidence: `feature_importance.py`)
- Comparison plots → Insurance dataset: compares metrics
- Insurance applicant → Streamlit prediction: enters details (evidence: `app.py`)
- Streamlit prediction → Saved Random Forest: predicts with (evidence: `app.py`)
- Streamlit prediction → Feature order: orders columns (evidence: `app.py`)
- Prediction helper → Saved Random Forest: predicts with (evidence: `predict.py`)
- Prediction helper → Feature order: orders columns (evidence: `predict.py`)
