├── Diabetes Predictor - Deployment.py ├── Procfile ├── README.md ├── Resource ├── final.JPG ├── heroku.png ├── interface.JPG ├── numpy.png └── pandas.jpeg ├── app.py ├── diabetes-prediction-rfc-model.pkl ├── requirements.txt ├── static ├── diabetes.webp └── no-diabetes.webp └── templates ├── index.html └── result.html /Diabetes Predictor - Deployment.py: -------------------------------------------------------------------------------- 1 | # Importing essential libraries 2 | import numpy as np 3 | import pandas as pd 4 | import pickle 5 | 6 | # Loading the dataset 7 | df = pd.read_csv('kaggle_diabetes.csv') 8 | 9 | # Renaming DiabetesPedigreeFunction as DPF 10 | df = df.rename(columns={'DiabetesPedigreeFunction':'DPF'}) 11 | 12 | # Replacing the 0 values from ['Glucose','BloodPressure','SkinThickness','Insulin','BMI'] by NaN 13 | df_copy = df.copy(deep=True) 14 | df_copy[['Glucose','BloodPressure','SkinThickness','Insulin','BMI']] = df_copy[['Glucose','BloodPressure','SkinThickness','Insulin','BMI']].replace(0,np.NaN) 15 | 16 | # Replacing NaN value by mean, median depending upon distribution 17 | df_copy['Glucose'].fillna(df_copy['Glucose'].mean(), inplace=True) 18 | df_copy['BloodPressure'].fillna(df_copy['BloodPressure'].mean(), inplace=True) 19 | df_copy['SkinThickness'].fillna(df_copy['SkinThickness'].median(), inplace=True) 20 | df_copy['Insulin'].fillna(df_copy['Insulin'].median(), inplace=True) 21 | df_copy['BMI'].fillna(df_copy['BMI'].median(), inplace=True) 22 | 23 | # Model Building 24 | from sklearn.model_selection import train_test_split 25 | X = df.drop(columns='Outcome') 26 | y = df['Outcome'] 27 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=0) 28 | 29 | # Creating Random Forest Model 30 | from sklearn.ensemble import RandomForestClassifier 31 | classifier = RandomForestClassifier(n_estimators=20) 32 | classifier.fit(X_train, y_train) 33 | 34 | # Creating a pickle file for the classifier 35 | filename = 'diabetes-prediction-rfc-model.pkl' 36 | pickle.dump(classifier, open(filename, 'wb')) -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: gunicorn app:app 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## End-to-End Diabetes Prediction Application using Machine Learning (MINI Project) 2 | 3 | 4 | ### Table of Content 5 | * [Overview](#overview) 6 | * [Motivation](#motivation) 7 | * [Demo](#demo) 8 | * [Learning Objective](#Learning-Objective) 9 | * [Technical Aspect](#technical-aspect) 10 | * [Technologies Used](#technologies-used) 11 | * [To Do](#to-do) 12 | * [Installation](#installation) 13 | * [Run](#run) 14 | * [Bug / Feature Request](#bug---feature-request) 15 | * [Team](#team) 16 | * [License](#license) 17 | * [Credits](#credits) 18 | 19 | 20 | ### Overview 21 | In this project, the objective is to predict whether the person has Diabetes or not based on various features suach as 22 | - Pregnancies 23 | - Insulin Level 24 | - Age 25 | - BMI. 26 | The data set that has used in this project has taken from the [kaggle](https://www.kaggle.com/) . "This dataset is originally from the National Institute of Diabetes and Digestive and Kidney Diseases. The objective of the dataset is to diagnostically predict whether or not a patient has diabetes, based on certain diagnostic measurements included in the dataset. Several constraints were placed on the selection of these instances from a larger database. In particular, all patients here are females at least 21 years old of Pima Indian heritage." and used a simple [random forest classifier](https://en.wikipedia.org/wiki/Random_forest). 27 | 28 | 29 | ### Motivation 30 | The motivation was to experiment with end to end machine learning project and get some idea about deployment platform like [Heroku](https://g.co/kgs/yvsR77) and offcourse this " 31 | Diabetes is an increasingly growing health issue due to our inactive lifestyle. If it is detected in time then through proper medical treatment, adverse effects can be prevented. To help in early detection, technology can be used very reliably and efficiently. Using machine learning we have built a predictive model that can predict whether the patient is diabetes positive or not.". 32 | This is also sort of fun to work on a project like this which could be beneficial for the society. 33 | 34 | ### Demo 35 | [Visit this link for live demo](https://mldiabete.herokuapp.com/) 36 | 37 | ### Learning Objective 38 | The following points were the objective of the project . If you are looking for all the following points in this repo then i have not covered all in this repo. I'm working on blog about this mini project and I'll update the link of blog about all the points in details later . (The main intention was to create an end-to-end ML project.) 39 | - Data gathering 40 | - Descriptive Analysis 41 | - Data Visualizations 42 | - Data Preprocessing 43 | - Data Modelling 44 | - Model Evaluation 45 | - Model Deployment 46 | 47 | ### Technical Aspect 48 | 49 | - Training a machine learning model using scikit-learn. 50 | - Building and hosting a Flask web app on Heroku. 51 | - A user has to put details like Number of Pregnancies, Insulin Level, Age, BMI etc . 52 | - Once it get all the fields information , the prediction is displayed on a new page . 53 | ### Technologies Used 54 | ![](https://forthebadge.com/images/badges/made-with-python.svg) 55 | 56 | [](https://github.com/scikit-learn/) 57 | 58 | 59 | 60 | 61 | 62 | ### Bug / Feature Request 63 | If you find a bug (the website couldn't handle the query and / or gave undesired results), kindly open an issue [here](https://github.com/ditikrushna/End-to-End-Diabetes-Prediction-Application-Using-Machine-Learning/issues) by including your search query and the expected result. 64 | 65 | If you'd like to request a new function, feel free to do so by opening an issue [here](https://github.com/ditikrushna/End-to-End-Diabetes-Prediction-Application-Using-Machine-Learning/issues/new). Please include sample queries and their corresponding results. 66 | 67 | 68 | ### Installation 69 | - Clone this repository and unzip it. 70 | - After downloading, cd into the flask directory. 71 | - Begin a new virtual environment with Python 3 and activate it. 72 | - Install the required packages using pip install -r requirements.txt 73 | - Execute the command: python app.py 74 | 75 | ### Team 76 | [![Ditikrushna Giri](https://ditikrushna.me/images/diti.jpg)](https://ditikrushna.me/) | 77 | -| 78 | [Ditikrushan Giri](https://ditikrushna.me/) |) 79 | 80 | 81 | ### Credits 82 | - Took inspiration from [Krish Naik](https://github.com/krishnaik06) Who is a youtuber he makes contents on Data science [his youtube channel link](https://www.youtube.com/channel/UCNU_lfiiWBdtULKOw6X0Dig) 83 | - Icons by [Icons8](https://icons8.com/) 84 | 85 | ### Note: 86 | - Webapp can handle concurrency upto some extent but can be scaled. 87 | 88 | -------------------------------------------------------------------------------- /Resource/final.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ditikrushna/End-to-End-Diabetes-Prediction-Application-Using-Machine-Learning/cdf37007eeb92d66ccb0900fa5ed355391e8deb4/Resource/final.JPG -------------------------------------------------------------------------------- /Resource/heroku.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ditikrushna/End-to-End-Diabetes-Prediction-Application-Using-Machine-Learning/cdf37007eeb92d66ccb0900fa5ed355391e8deb4/Resource/heroku.png -------------------------------------------------------------------------------- /Resource/interface.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ditikrushna/End-to-End-Diabetes-Prediction-Application-Using-Machine-Learning/cdf37007eeb92d66ccb0900fa5ed355391e8deb4/Resource/interface.JPG -------------------------------------------------------------------------------- /Resource/numpy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ditikrushna/End-to-End-Diabetes-Prediction-Application-Using-Machine-Learning/cdf37007eeb92d66ccb0900fa5ed355391e8deb4/Resource/numpy.png -------------------------------------------------------------------------------- /Resource/pandas.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ditikrushna/End-to-End-Diabetes-Prediction-Application-Using-Machine-Learning/cdf37007eeb92d66ccb0900fa5ed355391e8deb4/Resource/pandas.jpeg -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | # Importing essential libraries 2 | from flask import Flask, render_template, request 3 | import pickle 4 | import numpy as np 5 | 6 | # Load the Random Forest CLassifier model 7 | filename = 'diabetes-prediction-rfc-model.pkl' 8 | classifier = pickle.load(open(filename, 'rb')) 9 | 10 | app = Flask(__name__) 11 | 12 | @app.route('/') 13 | def home(): 14 | return render_template('index.html') 15 | 16 | @app.route('/predict', methods=['POST']) 17 | def predict(): 18 | if request.method == 'POST': 19 | preg = int(request.form['pregnancies']) 20 | glucose = int(request.form['glucose']) 21 | bp = int(request.form['bloodpressure']) 22 | st = int(request.form['skinthickness']) 23 | insulin = int(request.form['insulin']) 24 | bmi = float(request.form['bmi']) 25 | dpf = float(request.form['dpf']) 26 | age = int(request.form['age']) 27 | 28 | data = np.array([[preg, glucose, bp, st, insulin, bmi, dpf, age]]) 29 | my_prediction = classifier.predict(data) 30 | 31 | return render_template('result.html', prediction=my_prediction) 32 | 33 | if __name__ == '__main__': 34 | app.run(debug=True) -------------------------------------------------------------------------------- /diabetes-prediction-rfc-model.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ditikrushna/End-to-End-Diabetes-Prediction-Application-Using-Machine-Learning/cdf37007eeb92d66ccb0900fa5ed355391e8deb4/diabetes-prediction-rfc-model.pkl -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==2.3.2 2 | gunicorn==19.9.0 3 | itsdangerous==1.1.0 4 | Jinja2==2.11.3 5 | MarkupSafe==1.1.1 6 | Werkzeug==2.2.3 7 | numpy>=1.9.2 8 | scipy>=0.15.1 9 | scikit-learn>=0.18 10 | matplotlib>=1.4.3 11 | pandas>=0.19 12 | 13 | -------------------------------------------------------------------------------- /static/diabetes.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ditikrushna/End-to-End-Diabetes-Prediction-Application-Using-Machine-Learning/cdf37007eeb92d66ccb0900fa5ed355391e8deb4/static/diabetes.webp -------------------------------------------------------------------------------- /static/no-diabetes.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ditikrushna/End-to-End-Diabetes-Prediction-Application-Using-Machine-Learning/cdf37007eeb92d66ccb0900fa5ed355391e8deb4/static/no-diabetes.webp -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Diabetes Predictor 7 | 8 | 9 | 10 | 11 | 12 | 13 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 |
85 |

Diabetes Predictor

86 | 87 | 88 | 89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 | 99 |
100 |
101 |
102 | {{ prediction_text }} 103 | 104 | 105 | 106 | Made with ❤️ By Ditikrushan Giri 107 | 108 |
109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /templates/result.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Diabetes Predictor 7 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
51 | {% if prediction==1 %} 52 |

Prediction: Opps! You have DIABETES.

53 | Diabetes Image 54 | {% elif prediction==0 %} 55 |

Prediction: Wow ! You DON'T have diabetes.

56 | Not Diabetes Image 57 | {% endif %} 58 |
59 | 60 | 61 | 62 | 63 | 64 | --------------------------------------------------------------------------------