Yash911 commited on
Commit
ab31d46
·
1 Parent(s): ca5244e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +178 -0
app.py ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """Diabetes.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/15IbzL0ARqBYPhh4fx4KN2rJ62USEmIO2
8
+
9
+ Importing the Dependencies
10
+ """
11
+
12
+ import numpy as np
13
+ import pandas as pd
14
+ from sklearn.preprocessing import StandardScaler
15
+ from sklearn.model_selection import train_test_split
16
+ from sklearn import svm
17
+ from sklearn.metrics import accuracy_score
18
+
19
+ """Data Collection and Analysis
20
+
21
+ PIMA Diabetes Dataset
22
+ """
23
+
24
+ # loading the diabetes dataset to a pandas DataFrame
25
+ diabetes_dataset = pd.read_csv('/content/diabetes.csv')
26
+
27
+ pd.read_csv?
28
+
29
+ # printing the first 5 rows of the dataset
30
+ diabetes_dataset.head()
31
+
32
+ # number of rows and Columns in this dataset
33
+ diabetes_dataset.shape
34
+
35
+ # getting the statistical measures of the data
36
+ diabetes_dataset.describe()
37
+
38
+ diabetes_dataset['Outcome'].value_counts()
39
+
40
+ """0 --> Non-Diabetic
41
+
42
+ 1 --> Diabetic
43
+ """
44
+
45
+ diabetes_dataset.groupby('Outcome').mean()
46
+
47
+ # separating the data and labels
48
+ X = diabetes_dataset.drop(columns = 'Outcome', axis=1)
49
+ Y = diabetes_dataset['Outcome']
50
+
51
+ print(X)
52
+
53
+ print(Y)
54
+
55
+ """Data Standardization"""
56
+
57
+ scaler = StandardScaler()
58
+
59
+ scaler.fit(X)
60
+
61
+ standardized_data = scaler.transform(X)
62
+
63
+ print(standardized_data)
64
+
65
+ X = standardized_data
66
+ Y = diabetes_dataset['Outcome']
67
+
68
+ print(X)
69
+ print(Y)
70
+
71
+ """Train Test Split"""
72
+
73
+ X_train, X_test, Y_train, Y_test = train_test_split(X,Y, test_size = 0.2, stratify=Y, random_state=2)
74
+
75
+ print(X.shape, X_train.shape, X_test.shape)
76
+
77
+ """Training the Model"""
78
+
79
+ classifier = svm.SVC(kernel='linear')
80
+
81
+ #training the support vector Machine Classifier
82
+ classifier.fit(X_train, Y_train)
83
+
84
+ """Model Evaluation
85
+
86
+ Accuracy Score
87
+ """
88
+
89
+ # accuracy score on the training data
90
+ X_train_prediction = classifier.predict(X_train)
91
+ training_data_accuracy = accuracy_score(X_train_prediction, Y_train)
92
+
93
+ print('Accuracy score of the training data : ', training_data_accuracy)
94
+
95
+ # accuracy score on the test data
96
+ X_test_prediction = classifier.predict(X_test)
97
+ test_data_accuracy = accuracy_score(X_test_prediction, Y_test)
98
+
99
+ print('Accuracy score of the test data : ', test_data_accuracy)
100
+
101
+ """Making a Predictive System"""
102
+
103
+ def predict(Pregnancies,Glucose,BloodPressure,SkinThickness,Insulin,BMI,DiabetesPedigreeFunction,Age):
104
+ #input_data = (5,166,72,19,175,25.8,0.587,51)
105
+ input_data = (Pregnancies,Glucose,BloodPressure,SkinThickness,Insulin,BMI,DiabetesPedigreeFunction,Age)
106
+
107
+
108
+ # changing the input_data to numpy array
109
+ input_data_as_numpy_array = np.asarray(input_data)
110
+
111
+ # reshape the array as we are predicting for one instance
112
+ input_data_reshaped = input_data_as_numpy_array.reshape(1,-1)
113
+
114
+ # standardize the input data
115
+ std_data = scaler.transform(input_data_reshaped)
116
+ print(std_data)
117
+
118
+ prediction = classifier.predict(std_data)
119
+ #print(prediction)
120
+
121
+ if (prediction[0] == 0):
122
+ print('The person is not diabetic')
123
+ else:
124
+ print('The person is diabetic')
125
+ return prediction
126
+
127
+ predict(4,136,64,20,175,25.6,0.597,50)
128
+
129
+ !pip install gradio
130
+
131
+ import gradio as gr
132
+
133
+
134
+ def dibetis_predict(Pregnancies,Glucose,BloodPressure,SkinThickness,Insulin,BMI,DiabetesPedigreeFunction,Age):
135
+ #input_data = (5,166,72,19,175,25.8,0.587,51)
136
+ input_data = (Pregnancies,Glucose,BloodPressure,SkinThickness,Insulin,BMI,DiabetesPedigreeFunction,Age)
137
+
138
+
139
+ # changing the input_data to numpy array
140
+ input_data_as_numpy_array = np.asarray(input_data)
141
+
142
+ # reshape the array as we are predicting for one instance
143
+ input_data_reshaped = input_data_as_numpy_array.reshape(1,-1)
144
+
145
+ # standardize the input data
146
+ std_data = scaler.transform(input_data_reshaped)
147
+ print(std_data)
148
+
149
+ prediction = classifier.predict(std_data)
150
+
151
+ if (prediction[0] == 0):
152
+ print('The person is not diabetic')
153
+ return 'The person is not diabetic'
154
+ else:
155
+ print('The person is diabetic')
156
+ return 'The person is diabetic'
157
+
158
+
159
+
160
+
161
+ demo = gr.Interface(
162
+ fn=dibetis_predict,
163
+ inputs = [
164
+ gr.Slider(1, 20, value=4, label="Pregnancies", info="Choose between 1 and 20"),
165
+ gr.Slider(1, 200, value=136, label="Glucose", info="Choose between 1 and 200"),
166
+ gr.Slider(1, 100, value=64, label="BloodPressure", info="Choose between 1 and 100"),
167
+ gr.Slider(1, 50, value=20, label="SkinThickness", info="Choose between 1 and 50"),
168
+ gr.Slider(1, 200, value=175, label="Insulin", info="Choose between 1 and 200"),
169
+ gr.Slider(1, 100, value=25.5, label="BMI", info="Choose between 1 and 100"),
170
+ gr.Slider(0, 1.0, value=0.549, label="DiabetesPedigreeFunction", info="Choose between 0.0 and 1.0"),
171
+ gr.Slider(1, 100, value=50, label="Age", info="Choose between 1 and 100"),
172
+ ],
173
+ outputs = "text",
174
+ )
175
+
176
+ if __name__ == "__main__":
177
+ demo.launch(share=True)
178
+