Diff of /flask/model.py [000000] .. [1a09bc]

Switch to unified view

a b/flask/model.py
1
#!/usr/bin/env python
2
# coding: utf-8
3
4
# # Description:                                                                                                                   
5
# 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.
6
# 
7
# Attributes:
8
# 1. Glucose Level
9
# 2. BMI
10
# 3. Blood pressure
11
# 4. Pregnancies
12
# 5. Skin thickness
13
# 6. Insulin
14
# 7. Diabetes pedigree function
15
# 8. Age
16
# 9. Outcome
17
18
# # Step 0: Import libraries and Dataset
19
20
# In[1]:
21
22
23
import pandas as pd
24
import numpy as np
25
import matplotlib.pyplot as plt
26
import seaborn as sns
27
28
import warnings
29
warnings.filterwarnings('ignore')
30
31
import pickle
32
33
# In[2]:
34
35
36
dataset = pd.read_csv('diabetes.csv')
37
38
39
40
# # Step 3: Data Preprocessing
41
42
# In[13]:
43
44
45
dataset_X = dataset.iloc[:,[1, 4, 5, 7]].values
46
dataset_Y = dataset.iloc[:,8].values
47
48
49
# In[14]:
50
51
52
dataset_X
53
54
55
# In[15]:
56
57
58
from sklearn.preprocessing import MinMaxScaler
59
sc = MinMaxScaler(feature_range = (0,1))
60
dataset_scaled = sc.fit_transform(dataset_X)
61
62
63
# In[16]:
64
65
66
dataset_scaled = pd.DataFrame(dataset_scaled)
67
68
69
# In[17]:
70
71
72
X = dataset_scaled
73
Y = dataset_Y
74
75
76
# In[18]:
77
78
79
X
80
81
82
# In[19]:
83
84
85
Y
86
87
88
# In[20]:
89
90
91
from sklearn.model_selection import train_test_split
92
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size = 0.20, random_state = 42, stratify = dataset['Outcome'] )
93
94
95
# # Step 4: Data Modelling
96
97
# In[25]:
98
99
100
from sklearn.svm import SVC
101
svc = SVC(kernel = 'linear', random_state = 42)
102
svc.fit(X_train, Y_train)
103
104
105
# In[26]:
106
107
108
svc.score(X_test, Y_test)
109
110
111
# In[27]:
112
113
114
Y_pred = svc.predict(X_test)
115
116
117
118
119
120
pickle.dump(svc, open('model.pkl','wb'))
121
model = pickle.load(open('model.pkl','rb'))
122
#print(model.predict(sc.transform(np.array([[86, 66, 26.6, 31]]))))
123
124