-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsigmoid.py
More file actions
162 lines (70 loc) · 2.03 KB
/
sigmoid.py
File metadata and controls
162 lines (70 loc) · 2.03 KB
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
#!/usr/bin/env python
# coding: utf-8
# In[26]:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.ensemble import RandomForestClassifier
from sklearn.svm import SVC
from sklearn import svm
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import confusion_matrix, classification_report
from sklearn.preprocessing import StandardScaler, LabelEncoder
from sklearn.model_selection import train_test_split
get_ipython().run_line_magic('matplotlib', 'inline')
# In[2]:
wine = pd.read_csv('winequality-red.csv', sep=';')
# In[3]:
wine.head()
# In[4]:
wine.info()
# In[5]:
bins = (2,6.5,8)
group_names = ['bad', 'good']
wine['quality'] = pd.cut(wine['quality'], bins = bins, labels = group_names)
wine['quality'].unique()
# In[6]:
label_quality = LabelEncoder()
# In[7]:
wine['quality'] = label_quality.fit_transform(wine['quality'])
# In[11]:
wine.head(10)
# In[12]:
wine['quality'].value_counts()
# In[13]:
sns.countplot(wine['quality'])
# In[14]:
X = wine.drop('quality', axis = 1)
y = wine['quality']
# In[16]:
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 42)
# In[17]:
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
# In[19]:
#random forest classifier
# In[21]:
rfc = RandomForestClassifier(n_estimators=200)
rfc.fit(X_train, y_train)
pred_rfc = rfc.predict(X_test)
# In[24]:
print(classification_report(y_test, pred_rfc))
print(confusion_matrix(y_test, pred_rfc))
# In[27]:
clf=svm.SVC()
clf.fit(X_train,y_train)
pred_clf = clf.predict(X_test)
# In[30]:
print(classification_report(y_test, pred_clf))
print(confusion_matrix(y_test, pred_clf))
# In[31]:
mlpc=MLPClassifier(hidden_layer_sizes=(11,11,11),max_iter=500)
mlpc.fit(X_train, y_train)
pred_mlpc = mlpc.predict(X_test)
# In[32]:
print(classification_report(y_test, pred_mlpc))
print(confusion_matrix(y_test, pred_mlpc))
# In[33]:
from sklearn.metrics import accuracy_score
# In[ ]: