A full-stack machine learning web application for predicting the likelihood of diabetes and heart disease.
- Introduction
- Key Features
- Tech Stack
- Project Structure
- Getting Started
- Usage
- API Endpoints
- Model Training
- Troubleshooting
- Contributors
- License
HAI (Health AI) helps users assess their risk for common health conditions by leveraging the power of machine learning. By inputting key health metrics, users receive real-time predictions for Diabetes and Heart Disease. The application features a clean, interactive frontend built with React and a robust backend API powered by Flask, serving pre-trained models.
Note: Replace the link above with a real screenshot of your application's UI.
- π Dual-Disease Prediction: Assesses risk for both diabetes and heart disease.
- π§ ML-Powered: Utilizes models trained on real-world clinical datasets for accurate predictions.
- βοΈ Interactive UI: Modern, responsive user interface built with React.
- π Fast & Scalable API: Backend powered by Flask to serve model predictions efficiently.
- π¦ Pre-packaged Models: Comes with serialized
.pkl
models and scalers, ready for immediate use.
Component | Technology/Library |
---|---|
Frontend | React , JavaScript , HTML/CSS |
Backend | Flask , Python |
ML / Data | Scikit-learn , Pandas , NumPy , Seaborn , Matplotlib |
Environment | venv , npm |
The project repository is organized as follows:
HAI/
βββ π Flask_heart.py # Flask backend for Heart Disease prediction
βββ π Flask_diabetes.py # Flask backend for Diabetes prediction
β
βββ π diabetes_prediction.ipynb # Jupyter Notebook for Diabetes model training
βββ π heart_disease_prediction.ipynb # Jupyter Notebook for Heart Disease model training
β
βββ π¦ best_model_d.pkl # Serialized model for Diabetes
βββ π¦ scaler_D.pkl # Serialized scaler for Diabetes
βββ π¦ model.pkl # Serialized model for Heart Disease
βββ π¦ scaler.pkl # Serialized scaler for Heart Disease
β
βββ π diabetes.csv # Dataset for Diabetes model
βββ π framingham.csv # Dataset for Heart Disease model
β
βββ π requirements.txt # Python dependencies
βββ π README.md # This file
β
βββ π frontend/ # (Not included in this repo) React frontend code
Follow these steps to set up and run the project locally.
- Git
- Python (3.8 or newer)
- Node.js and npm (for the frontend)
-
Clone the repository:
git clone https://github.com/your-username/HAI.git cd HAI
-
Create and activate a virtual environment:
# For macOS/Linux python3 -m venv venv source venv/bin/activate # For Windows python -m venv venv venv\Scripts\activate
-
Install Python dependencies:
pip install -r requirements.txt
Tip: If
requirements.txt
is missing, generate it viapip freeze > requirements.txt
after installing the packages listed in the old README. -
Run the Flask server: Choose which prediction server you want to run.
# To run the diabetes prediction server python Flask_diabetes.py # To run the heart disease prediction server python Flask_heart.py
The API will be available at
http://127.0.0.1:5000
.
Note: The frontend code is not included in this repository snapshot. These are general instructions.
-
Navigate to the frontend directory:
cd frontend
-
Install npm dependencies:
npm install
-
Start the React development server:
npm start
The application UI will be available at
http://localhost:3000
. Ensure the frontend is configured to send API requests to the correct Flask URL (http://127.0.0.1:5000
).
- Open your web browser and navigate to
http://localhost:3000
. - Select either the "Diabetes Prediction" or "Heart Disease Prediction" form.
- Fill in the required health parameters.
- Click the "Predict" button.
- View the prediction result returned from the backend model.
- Endpoint:
/predict/diabetes
- Method:
POST
- Description: Submits user data to predict the likelihood of diabetes.
- Request Body (JSON):
{ "Pregnancies": 2, "Glucose": 120, "BloodPressure": 70, "SkinThickness": 20, "Insulin": 79, "BMI": 25.6, "DiabetesPedigreeFunction": 0.3 }
- Success Response (JSON):
{ "prediction": "The person is likely to be Diabetic.", "prediction_value": 1 }
- Endpoint:
/predict/heart
- Method:
POST
- Description: Submits user data to predict the likelihood of heart disease.
- Request Body (JSON):
{ "age": 54, "sex": 1, "cp": 0, "trestbps": 130, "chol": 250, "fbs": 0, "restecg": 1, "thalach": 187, "exang": 0, "oldpeak": 1.0, "slope": 2, "ca": 0, "thal": 2 }
- Success Response (JSON):
{ "prediction": "The person is likely to have Heart Disease.", "prediction_value": 1 }
The machine learning models were trained using the following configurations:
Prediction Target | Notebook | Dataset | Models Tested | Saved Files |
---|---|---|---|---|
π©Ί Diabetes | diabetes_prediction.ipynb |
diabetes.csv |
KNN, SVC, Decision Tree, Random Forest, Gradient Boosting | best_model_d.pkl , scaler_D.pkl |
β€οΈ Heart Disease | heart_disease_prediction.ipynb |
framingham.csv |
KNN, SVC, Decision Tree, Random Forest, Gradient Boosting | model.pkl , scaler.pkl |
To retrain the models, open the corresponding Jupyter Notebook, modify the code as needed, and run the cells to generate new .pkl
files.
- CORS Errors: If the React frontend cannot connect to the Flask API, ensure CORS is enabled in your Flask app.
from flask_cors import CORS # Add this after initializing your app CORS(app)
- Model Not Found (
FileNotFoundError
): Make sure all.pkl
model and scaler files are located in the same directory as your Flask script. - Dependency Issues: Ensure you are using the correct virtual environment (
source venv/bin/activate
) and that all packages inrequirements.txt
are installed.
- ADAMFUTUR - Development, Model Training, Integration
We welcome contributions! Please feel free to fork the repository, make improvements, and submit a pull request.
This project is licensed under the MIT License. See the LICENSE
file for more details.