-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiabetes.py
241 lines (102 loc) · 2.58 KB
/
Diabetes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import pandas as pd
import numpy as np
import seaborn as sns
from sklearn.preprocessing import StandardScaler
import matplotlib.pyplot as plt
# In[2]:
df=pd.read_csv('diabetes.csv')
df.head()
# In[3]:
#How big is the data
#Count number of rows and columns
df.shape
# In[4]:
#what is the data type of columns
df.info()
# In[5]:
#Are there any missing value
df.isnull().sum()
# In[6]:
##How does the data look mathematically
#getting statistical data
df.describe()
# In[7]:
#Are the any duplicated values
df.duplicated().sum()
# In[8]:
#count the number of diabetic patients
#0----> Non-Diabetic
#1----> Diabetic
df['Outcome'].value_counts()
# In[9]:
df.groupby('Outcome').mean()
# In[10]:
sns.countplot(df['Outcome'],label='count')
# In[11]:
plt.figure(figsize=(10,10))
sns.heatmap(df.iloc[:,1:7].corr(),annot=True,fmt='.0%')
# In[12]:
#separating data and labels
X=df.drop(columns='Outcome',axis=1)
Y=df['Outcome']
# In[13]:
print(X)
# In[14]:
print(Y)
# In[15]:
#Data Standarization
# In[16]:
scaler=StandardScaler()
# In[17]:
scaler.fit(X)
# In[18]:
standardized_data=scaler.transform(X)
# In[19]:
print(standardized_data)
# In[20]:
X=standardized_data
Y=df['Outcome']
# In[21]:
print(X,Y)
# In[22]:
from sklearn.model_selection import train_test_split
X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=0.2,stratify=Y,random_state=2)
# In[23]:
print(X.shape,X_train.shape,X_test.shape)
# In[24]:
#Training the model
# In[25]:
from sklearn import svm
clf=svm.SVC(kernel='linear')
# In[26]:
clf.fit(X_train,Y_train)
# In[27]:
from sklearn.metrics import accuracy_score
# In[28]:
#accuracy on the training data
X_train_predicition=clf.predict(X_train)
training_data_accuracy=accuracy_score(X_train_predicition,Y_train)
# In[29]:
print('Accuracy score of the training data',training_data_accuracy*100)
# In[30]:
#accuracy on the test data
X_test_predicition=clf.predict(X_test)
test_data_accuracy=accuracy_score(X_test_predicition,Y_test)
# In[31]:
print('Accuracy score of the test data',test_data_accuracy*100)
# # Making a predicitve system
# In[37]:
input_data=(4,110,92,0,0,37.6,0.191,30)
#changing the input data to numpy array
input_data_as_numpy_array=np.asarray(input_data)
#reshape the arrayas we are predicting for one instance
input_data_reshaped=input_data_as_numpy_array.reshape(1,-1)
#standarize the input data
std_data=scaler.transform(input_data_reshaped)
print(std_data)
prediction=clf.predict(std_data)
print(prediction)
# In[ ]: