-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
256 lines (235 loc) · 6.04 KB
/
test.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# -*- coding: utf-8 -*-
"""
Testing
"""
from sklearn.datasets import load_digits, load_iris
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import StratifiedKFold
from sklearn.metrics import accuracy_score
import time
"""
Base Estimator & Datasets
"""
base_estimator = DecisionTreeClassifier()
datasets = [
("DIGITS", load_digits),
("IRIS", load_iris)
]
"""
Algorithms
"""
import imblMulticlass as imb
algos = [
("ROSboost", imb.ROSboost()),
("SMOTEboost", imb.SMOTEBoost()),
("RUSboost", imb.RUSBoost()),
("TLboost", imb.TLboost())
]
for tag, load in datasets:
dataset = load()
X = dataset.data
Y = dataset.target
for nclf, clf in algos:
print '=='*25
print "Class order {} for dataset {}\n".format(nclf, tag)
SKFold = StratifiedKFold(n_splits = 5, random_state = 1)
i = 1
for train_idx, test_idx in SKFold.split(X,Y):
x_train, y_train = X[train_idx, :], Y[train_idx]
x_test, y_test = X[test_idx, :], Y[test_idx]
"""
Training
"""
tt = time.time()
clf.fit(x_train, y_train)
tt = time.time() - tt
"""
Validation
"""
ct = time.time()
y_pred = clf.predict(x_test)
ct = time.time() - ct
acc = accuracy_score(y_test, y_pred)
print "Fold{}".format(i)
print "\tAcc:{}" .format(acc)
print "\tTraining Time:{}".format(tt)
print "\tClassification Time:{}".format(ct)
i = i+1
'''
==================================================
Class order ROSboost for dataset DIGITS
Fold1
Acc:0.285714285714
Training Time:0.568933963776
Classification Time:0.0115168094635
Fold2
Acc:0.273480662983
Training Time:0.565816879272
Classification Time:0.0114288330078
Fold3
Acc:0.284122562674
Training Time:0.546090126038
Classification Time:0.0114500522614
Fold4
Acc:0.21568627451
Training Time:0.560751914978
Classification Time:0.0113260746002
Fold5
Acc:0.278873239437
Training Time:0.569422006607
Classification Time:0.0113909244537
==================================================
Class order SMOTEboost for dataset DIGITS
Fold1
Acc:0.285714285714
Training Time:0.479490995407
Classification Time:0.011430978775
Fold2
Acc:0.273480662983
Training Time:0.483418941498
Classification Time:0.0114471912384
Fold3
Acc:0.284122562674
Training Time:0.483948945999
Classification Time:0.0114450454712
Fold4
Acc:0.212885154062
Training Time:0.491546154022
Classification Time:0.0112841129303
Fold5
Acc:0.278873239437
Training Time:0.494383096695
Classification Time:0.0114181041718
==================================================
Class order RUSboost for dataset DIGITS
Fold1
Acc:0.46978021978
Training Time:0.558105945587
Classification Time:0.0118148326874
Fold2
Acc:0.370165745856
Training Time:0.518282175064
Classification Time:0.0117061138153
Fold3
Acc:0.364902506964
Training Time:0.554261922836
Classification Time:0.0118181705475
Fold4
Acc:0.260504201681
Training Time:0.512488126755
Classification Time:0.0116209983826
Fold5
Acc:0.287323943662
Training Time:0.558358192444
Classification Time:0.0118429660797
==================================================
Class order TLboost for dataset DIGITS
Fold1
Acc:0.200549450549
Training Time:13.9705519676
Classification Time:0.0116279125214
Fold2
Acc:0.201657458564
Training Time:14.0244500637
Classification Time:0.0115950107574
Fold3
Acc:0.194986072423
Training Time:14.0095899105
Classification Time:0.0116629600525
Fold4
Acc:0.193277310924
Training Time:13.9878702164
Classification Time:0.0114889144897
Fold5
Acc:0.197183098592
Training Time:14.0124120712
Classification Time:0.0115299224854
==================================================
Class order ROSboost for dataset IRIS
Fold1
Acc:0.966666666667
Training Time:0.216493844986
Classification Time:0.00423216819763
Fold2
Acc:0.933333333333
Training Time:0.215262889862
Classification Time:0.00423812866211
Fold3
Acc:0.9
Training Time:0.215595960617
Classification Time:0.0042188167572
Fold4
Acc:0.933333333333
Training Time:0.215348958969
Classification Time:0.00424098968506
Fold5
Acc:1.0
Training Time:0.215986967087
Classification Time:0.00422787666321
==================================================
Class order SMOTEboost for dataset IRIS
Fold1
Acc:0.966666666667
Training Time:0.239869117737
Classification Time:0.00423192977905
Fold2
Acc:0.933333333333
Training Time:0.242223024368
Classification Time:0.00428509712219
Fold3
Acc:0.9
Training Time:0.244747161865
Classification Time:0.00425291061401
Fold4
Acc:0.933333333333
Training Time:0.247266054153
Classification Time:0.00423002243042
Fold5
Acc:1.0
Training Time:0.252019882202
Classification Time:0.00422120094299
==================================================
Class order RUSboost for dataset IRIS
Fold1
Acc:0.666666666667
Training Time:0.229157924652
Classification Time:0.00421500205994
Fold2
Acc:0.666666666667
Training Time:0.230819940567
Classification Time:0.00425505638123
Fold3
Acc:0.666666666667
Training Time:0.229274988174
Classification Time:0.00422215461731
Fold4
Acc:0.666666666667
Training Time:0.231146097183
Classification Time:0.00420689582825
Fold5
Acc:0.666666666667
Training Time:0.229363918304
Classification Time:0.0042040348053
==================================================
Class order TLboost for dataset IRIS
Fold1
Acc:0.666666666667
Training Time:0.290214776993
Classification Time:0.00428891181946
Fold2
Acc:0.666666666667
Training Time:0.326241016388
Classification Time:0.00421905517578
Fold3
Acc:0.666666666667
Training Time:0.288220882416
Classification Time:0.00421786308289
Fold4
Acc:0.666666666667
Training Time:0.288480043411
Classification Time:0.00422501564026
Fold5
Acc:0.666666666667
Training Time:0.289098978043
Classification Time:0.00422716140747
'''