Diabetes Risk Prediction
The Diabetes Risk Prediction system is a tool designed to assess an individual's likelihood of developing diabetes based on various health metrics and lifestyle factors. By analyzing data such as age, blood glucose levels, BMI, and other factors, the system provides personalized risk assessments and recommendations for prevention.
This project is organized into several parts:
-
Data Processing & Visualization
The data is sourced from data/diabetes.csv and preprocessed insrc/train_model.py. A bar chart visualizing the diabetes outcome distribution is generated and saved to static/chart.png, then rendered in the templates/index.html file. -
Machine Learning Model
A RandomForestClassifier is trained using scaled features, and both the model and scaler are saved as src/model/rf_model.pkl and src/model/scaler.pkl respectively. -
API Service
The FastAPI based API is implemented inapi/main.py. This renders the result visualization and serves static files. To run the API, simply launch the provided FastAPI server. -
Command-Line Prediction
Thesrc/predict.pyscript allows for console-based predictions where a user inputs health parameters and the system outputs whether the patient is predicted as diabetic or not.
-
Clone the Repository
git clone <repository-url> cd Diabetes-risk-prediction
-
Set Up a Virtual Environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies
Make sure you have the required packages installed. For example, install dependencies such as
pandas,scikit-learn,joblib,fastapi,uvicorn, andmatplotlib:pip install pandas scikit-learn joblib fastapi uvicorn matplotlib
-
Data Preparation & Model Training
Run the training script to preprocess data, train the model, and generate the visualization:
python src/train_model.py
This script reads data from data/diabetes.csv, scales the features, splits the dataset, trains a Random Forest model, prints the model accuracy, and saves both the model and scaler in the src/model directory. It also generates and saves a chart in static/chart.png.
-
Running the API
Launch the FastAPI application:
uvicorn api.main:app --reload
Then open your browser at http://127.0.0.1:8000 to view the visualization rendered by templates/index.html.
-
Making Predictions from the Command Line
Run the prediction script to provide patient data and receive a risk prediction:
python src/predict.py
Follow the prompts to input patient data. The script will output whether the patient is predicted as diabetic or not.
- Data file: data/diabetes.csv
- Visualization: Saved as static/chart.png and rendered in templates/index.html
- API Entry Point:
api/main.py - Model Training and Prediction:
src/train_model.pyandsrc/predict.py
Happy Coding!