Skip to content

Commit f79a8ab

Browse files
committed
diabetes disease prediction
1 parent b0e44c6 commit f79a8ab

File tree

22 files changed

+2947
-0
lines changed

22 files changed

+2947
-0
lines changed

MachineLearning Projects/Diabetes-disease-Prediction/Dataset/diabetes.csv

Lines changed: 769 additions & 0 deletions
Large diffs are not rendered by default.
Binary file not shown.
Binary file not shown.

MachineLearning Projects/Diabetes-disease-Prediction/Notebook/Logistic_Regression.ipynb

Lines changed: 1257 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Disease prediction
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
from wsgiref import simple_server
2+
from flask import Flask, request, app,render_template
3+
from flask import Response
4+
from flask_cors import CORS
5+
import pickle
6+
import bz2
7+
import datetime
8+
import numpy as np
9+
import pandas as pd
10+
from flask import Flask, request, jsonify
11+
# from pymongo import MongoClient
12+
# from pymongo.server_api import ServerApi
13+
14+
15+
app = Flask(__name__)
16+
CORS(app)
17+
app.config['DEBUG'] = True
18+
19+
scalarobject=bz2.BZ2File("Model/standardScalar.pkl", "rb")
20+
scaler=pickle.load(scalarobject)
21+
modelforpred = bz2.BZ2File("Model/modelForPrediction.pkl", "rb")
22+
model = pickle.load(modelforpred)
23+
24+
## Mongo db connection
25+
# uri = "mongodb+srv://adityajai243:db2023@cluster0.buez9p5.mongodb.net/?retryWrites=true&w=majority"
26+
27+
28+
# # Create a new client and connect to the server
29+
# client = MongoClient(uri, server_api=ServerApi('1'))
30+
31+
# # Send a ping to confirm a successful connection
32+
# try:
33+
# client.admin.command('ping')
34+
# print("Pinged your deployment. You successfully connected to MongoDB!")
35+
# except Exception as e:
36+
# print(e)
37+
38+
# # Define the database and collection
39+
# db = client['Patient'] # Database name
40+
# collection = db['patient-login'] # Collection name
41+
42+
43+
##Route for checking backend connection
44+
45+
46+
## Route for homepage
47+
48+
@app.route('/',methods=['GET','POST'])
49+
def index():
50+
return render_template('index.html')
51+
52+
## Route for patient Registration
53+
@app.route('/add-patients',methods=['GET','POST'])
54+
def reg():
55+
return render_template('patient-registration.html')
56+
57+
58+
## Route for Single data point prediction
59+
@app.route('/diabetes',methods=['GET','POST'])
60+
def predict_datapoint():
61+
result=""
62+
current_datetime = datetime.datetime.now()
63+
f_datetime = current_datetime.strftime('%d-%m-%Y %I:%M %p')
64+
65+
if request.method=='POST':
66+
name=request.form.get("name")
67+
Age = int(request.form.get('Age'))
68+
gender = request.form.get('gender')
69+
if gender=='Male':
70+
Pregnancies=0
71+
pregnancy='No'
72+
if gender =='Female':
73+
Pregnancies=int(request.form.get("Pregnancies"))
74+
pregnancy=request.form.get("pregnancy")
75+
76+
Glucose = float(request.form.get('Glucose'))
77+
BloodPressure = float(request.form.get('BloodPressure'))
78+
SkinThickness = float(request.form.get('SkinThickness'))
79+
Insulin = float(request.form.get('Insulin'))
80+
BMI = float(request.form.get('BMI'))
81+
DiabetesPedigreeFunction = float(request.form.get('DiabetesPedigreeFunction'))
82+
83+
#classification
84+
if Glucose > 200 and Insulin < 10:
85+
classification = 'Type 1 Diabetes'
86+
elif Glucose > 126 and Insulin >= 10:
87+
classification = 'Type 2 Diabetes'
88+
elif Glucose > 92:
89+
classification = 'Gestational Diabetes'
90+
else:
91+
classification = 'Unclassified Diabetes'
92+
93+
new_data=scaler.transform([[Pregnancies,Glucose,BloodPressure,SkinThickness,Insulin,BMI,DiabetesPedigreeFunction,Age]])
94+
predict=model.predict(new_data)
95+
96+
if predict[0] ==1 :
97+
result = 'Diabetic'
98+
else:
99+
result ='Non-Diabetic'
100+
101+
return render_template('diabetes.html',result=result,name=name,Age=Age,BMI=BMI,Pregnancies=Pregnancies,Glucose=Glucose,BloodPressure=BloodPressure,Insulin=Insulin,DiabetesPedigreeFunction=DiabetesPedigreeFunction,SkinThickness=SkinThickness,gender=gender,Pregnancy=pregnancy,datetime=f_datetime,type=classification)
102+
103+
else:
104+
return render_template('home.html')
105+
106+
107+
if __name__=="__main__":
108+
app.run(host="0.0.0.0")
109+
app.debug(True)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"Pregnancies":6,
3+
"Glucose":148,
4+
"BloodPressure":72,
5+
"SkinThickness":35,
6+
"Insulin":0,
7+
"BMI":33.6,
8+
"DiabetesPedigreeFunction":0.62,
9+
"Age":59
10+
11+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
certifi==2019.11.28
2+
Click==7.0
3+
Flask==1.1.1
4+
Flask-Cors==3.0.8
5+
gunicorn==20.0.4
6+
itsdangerous==1.1.0
7+
Jinja2==2.10.3
8+
joblib==0.14.1
9+
MarkupSafe==1.1.1
10+
numpy==1.18.0
11+
pandas==0.25.3
12+
python-dateutil==2.8.1
13+
pytz==2019.3
14+
scikit-learn==0.22
15+
scipy==1.4.1
16+
six==1.13.0
17+
Werkzeug==0.16.0
18+
wincertstore==0.2
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
body{
2+
overflow-x: hidden;
3+
}
4+
.report{
5+
display: flex;
6+
justify-content: space-between;
7+
border: 1px solid black;
8+
background-color: #f0f0f0;
9+
padding: 20px;
10+
}
11+
.left, .right {
12+
padding: 20px;
13+
}
14+
.left {
15+
width: 48%;
16+
background-color: #fff;
17+
border: 1px solid #ccc;
18+
border-radius: 5px;
19+
}
20+
.right {
21+
width: 48%;
22+
background-color: #fff;
23+
border: 1px solid #ccc;
24+
border-radius: 5px;
25+
}
26+
27+
28+
h3 {
29+
font-size: 24px;
30+
text-decoration: underline;
31+
margin-bottom: 15px;
32+
}
33+
p {
34+
font-size: 16px;
35+
margin-bottom: 10px;
36+
}
37+
38+
.print:last-child {
39+
display: flex;
40+
justify-content: center;
41+
margin-top: 20px;
42+
}
43+
44+
button{
45+
margin: 1rem;
46+
padding: 0.5rem;
47+
width: 30%;
48+
border: 1px solid black;
49+
background-color: #fff;
50+
cursor: pointer;
51+
}
52+
53+
button:hover{
54+
background-color: #000;
55+
color: #fff;
56+
}
57+
58+
.positive{
59+
color: green;
60+
}
61+
.ideal{
62+
color: #DBA800;
63+
}
64+
.negative{
65+
color: red;
66+
}
67+
68+
.end p{
69+
font-size: 16px;
70+
text-align: center;
71+
}
72+
73+
.diabetes {
74+
background-color: #FFA0A0;
75+
border-radius: 20px;
76+
padding: 20px;
77+
margin: 20px ;
78+
width:auto;
79+
}
80+
81+
.diabetes blockquote {
82+
font-size: 18px;
83+
font-style: italic;
84+
margin: 20px 0;
85+
}
86+
87+
.diabetes ul {
88+
list-style: disc;
89+
padding-left: 20px;
90+
}
91+
92+
.diabetes li {
93+
font-size: 16px;
94+
}
95+
96+
.non-diabetic {
97+
background-color: #A0FFA0;
98+
border-radius: 20px;
99+
padding: 20px;
100+
margin: 20px ;
101+
width:auto;
102+
}
103+
104+
.non-diabetic blockquote {
105+
font-size: 18px;
106+
font-style: italic;
107+
margin: 20px 0;
108+
}
109+
110+
.non-diabetic ul {
111+
list-style: disc;
112+
padding-left: 20px;
113+
}
114+
115+
.non-diabetic li {
116+
font-size: 16px;
117+
}
118+
.print{
119+
align-items: center;
120+
justify-content: center;
121+
}
122+
.date{
123+
margin-left: 1px;
124+
padding:2px;
125+
}
126+
127+
table {
128+
width: 100%;
129+
border:1px solid #000;
130+
/* border-collapse: collapse; */
131+
margin: 20px auto;
132+
}
133+
th, td {
134+
border: 1px solid #000;
135+
padding: 10px;
136+
text-align: left;
137+
}
138+
th {
139+
background-color: #333;
140+
color: #fff;
141+
}
142+
tr:nth-child(even) {
143+
background-color: #f2f2f2;
144+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
body {
2+
font-family: Arial, sans-serif;
3+
/* background-image: linear-gradient(
4+
to left top,
5+
#04b4c4,
6+
#04b4c4,
7+
#a8eb12,
8+
#a8eb12
9+
); */
10+
min-height: 100vh;
11+
background-size: cover;
12+
}
13+
14+
.container {
15+
max-width: 400px;
16+
margin: 200px auto;
17+
padding: 20px;
18+
border: 1px solid #ccc;
19+
border-radius: 5px;
20+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
21+
}
22+
23+
.form-group {
24+
margin-bottom: 15px;
25+
}
26+
27+
label {
28+
display: block;
29+
font-weight: bold;
30+
margin-bottom: 5px;
31+
}
32+
33+
input {
34+
width: 70%;
35+
padding: 10px;
36+
border: 1px solid #ccc;
37+
border-radius: 5px;
38+
font-size: 16px;
39+
}
40+
41+
button {
42+
background-color: #007bff;
43+
color: #fff;
44+
padding: 10px 20px;
45+
border: none;
46+
border-radius: 5px;
47+
cursor: pointer;
48+
}
49+
50+
#error-message {
51+
color: red;
52+
margin-top: 10px;
53+
}

0 commit comments

Comments
 (0)