/
set_bakeoff_classifier.py
361 lines (317 loc) · 11.9 KB
/
set_bakeoff_classifier.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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
"""Classifiers used in the publication."""
__author__ = ["TonyBagnall", "MatthewMiddlehurst"]
from tsml_eval.utils.functions import str_in_nested_list
bakeoff_classifiers = [
# distance based
["KNeighborsTimeSeriesClassifier", "dtw", "1nn-dtw"],
"ShapeDTW",
["GRAILClassifier", "grail"],
# feature based
["Catch22Classifier", "catch22"],
["FreshPRINCEClassifier", "freshprince"],
["TSFreshClassifier", "tsfresh"],
["SignatureClassifier", "signatures"],
# shapelet based
["ShapeletTransformClassifier", "stc", "stc-2hour"],
["RDSTClassifier", "rdst"],
["RandomShapeletForestClassifier", "randomshapeletforest", "rsf"],
["MrSQMClassifier", "mrsqm"],
# interval based
["RSTSFClassifier", "rstsf", "r-stsf"],
["RandomIntervalSpectralEnsembleClassifier", "rise"],
["TimeSeriesForestClassifier", "tsf"],
["CanonicalIntervalForestClassifier", "cif"],
["SupervisedTimeSeriesForest", "stsf"],
["drcif", "DrCIFClassifier"],
["quant", "QUANTClassifier"],
# dictionary based
["BOSSEnsemble", "boss"],
["ContractableBOSS", "cboss"],
["TemporalDictionaryEnsemble", "tde"],
["WEASEL", "weasel v1", "weasel v1.0"],
["weasel_v2", "weasel v2", "weasel v2.0", "weasel-dilation", "weasel-d"],
# convolution based
["RocketClassifier", "rocket"],
["minirocket", "mini-rocket"],
["multirocket", "multi-rocket"],
["arsenalclassifier", "Arsenal"],
"HYDRA",
["mr-hydra", "multirockethydra", "multirocket-hydra"],
# deep learning
["CNNClassifier", "cnn"],
["ResNetClassifier", "resnet"],
["InceptionTimeClassifier", "inceptiontime"],
["h-inceptiontimeclassifier", "h-inceptiontime"],
["LITETimeClassifier", "litetime"],
# hybrid
["HIVECOTEV1", "hc1"],
["HIVECOTEV2", "hc2"],
["RIST", "RISTClassifier"],
]
def _set_bakeoff_classifier(
classifier_name,
random_state=None,
n_jobs=1,
**kwargs,
):
c = classifier_name.lower()
if not str_in_nested_list(bakeoff_classifiers, c):
raise ValueError(f"UNKNOWN CLASSIFIER: {c} in _set_bakeoff_classifier")
if c == "kneighborstimeseriesclassifier" or c == "dtw" or c == "1nn-dtw":
from aeon.classification.distance_based import KNeighborsTimeSeriesClassifier
return KNeighborsTimeSeriesClassifier(
distance="dtw", n_neighbors=1, n_jobs=n_jobs, **kwargs
)
elif c == "shapedtw":
from aeon.classification.distance_based import ShapeDTW
return ShapeDTW(
**kwargs,
)
elif c == "grailclassifier" or c == "grail":
from tsml.distance_based import GRAILClassifier
return GRAILClassifier(**kwargs)
elif c == "catch22classifier" or c == "catch22":
from aeon.classification.feature_based import Catch22Classifier
from sklearn.ensemble import RandomForestClassifier
return Catch22Classifier(
estimator=RandomForestClassifier(n_estimators=500),
catch24=False,
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "freshprinceclassifier" or c == "freshprince":
from aeon.classification.feature_based import FreshPRINCEClassifier
return FreshPRINCEClassifier(random_state=random_state, n_jobs=n_jobs, **kwargs)
elif c == "tsfreshclassifier" or c == "tsfresh":
from aeon.classification.feature_based import TSFreshClassifier
return TSFreshClassifier(random_state=random_state, n_jobs=n_jobs, **kwargs)
elif c == "signatureclassifier" or c == "signatures":
from aeon.classification.feature_based import SignatureClassifier
return SignatureClassifier(
random_state=random_state,
**kwargs,
)
elif c == "shapelettransformclassifier" or c == "stc" or c == "stc-2hour":
from aeon.classification.shapelet_based import ShapeletTransformClassifier
return ShapeletTransformClassifier(
n_shapelet_samples=10000,
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "rdstclassifier" or c == "rdst":
from aeon.classification.shapelet_based import RDSTClassifier
return RDSTClassifier(
random_state=random_state,
**kwargs,
)
elif (
c == "randomshapeletforestclassifier"
or c == "randomshapeletforest"
or c == "rsf"
):
from tsml.shapelet_based import RandomShapeletForestClassifier
return RandomShapeletForestClassifier(
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "mrsqmclassifier" or c == "mrsqm":
from aeon.classification.shapelet_based import MrSQMClassifier
return MrSQMClassifier(
random_state=random_state,
**kwargs,
)
elif c == c == "rstsfclassifier" or c == "rstsf" or c == "r-stsf":
from tsml.interval_based import RSTSFClassifier
return RSTSFClassifier(
n_estimators=500,
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "randomintervalspectralensembleclassifier" or c == "rise":
from aeon.classification.interval_based import (
RandomIntervalSpectralEnsembleClassifier,
)
return RandomIntervalSpectralEnsembleClassifier(
n_estimators=500,
min_interval_length=16,
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "timeseriesforestclassifier" or c == "tsf":
from aeon.classification.interval_based import TimeSeriesForestClassifier
return TimeSeriesForestClassifier(
n_estimators=500,
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "canonicalintervalforestclassifier" or c == "cif":
from aeon.classification.interval_based import CanonicalIntervalForestClassifier
return CanonicalIntervalForestClassifier(
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "supervisedtimeseriesforest" or c == "stsf":
from aeon.classification.interval_based import SupervisedTimeSeriesForest
return SupervisedTimeSeriesForest(
n_estimators=500,
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "drcif" or c == "drcifclassifier":
from aeon.classification.interval_based import DrCIFClassifier
return DrCIFClassifier(
n_estimators=500,
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "quantclassifier" or c == "quant":
from tsml_eval.estimators.classification.interval_based.quant import (
QuantClassifier,
)
return QuantClassifier(random_state=random_state, **kwargs)
elif c == "bossensemble" or c == "boss":
from aeon.classification.dictionary_based import BOSSEnsemble
return BOSSEnsemble(
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "contractableboss" or c == "cboss":
from aeon.classification.dictionary_based import ContractableBOSS
return ContractableBOSS(
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "temporaldictionaryensemble" or c == "tde":
from aeon.classification.dictionary_based import TemporalDictionaryEnsemble
return TemporalDictionaryEnsemble(
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "weasel" or c == "weasel v1" or c == "weasel v1.0":
from aeon.classification.dictionary_based import WEASEL
return WEASEL(
random_state=random_state,
n_jobs=n_jobs,
support_probabilities=True,
**kwargs,
)
elif (
c == "weasel_v2"
or c == "weasel v2"
or c == "weasel v2.0"
or c == "weasel-dilation"
or c == "weasel-d"
):
from aeon.classification.dictionary_based import WEASEL_V2
return WEASEL_V2(
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "rocketclassifier" or c == "rocket":
from aeon.classification.convolution_based import RocketClassifier
return RocketClassifier(
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "minirocket" or c == "mini-rocket":
from aeon.classification.convolution_based import RocketClassifier
return RocketClassifier(
rocket_transform="minirocket",
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "multirocket" or c == "multi-rocket":
from aeon.classification.convolution_based import RocketClassifier
return RocketClassifier(
rocket_transform="multirocket",
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "arsenalclassifier" or c == "arsenal":
from aeon.classification.convolution_based import Arsenal
return Arsenal(
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "hydra":
from tsml_eval.estimators.classification.convolution_based.hydra import HYDRA
return HYDRA(
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "mr-hydra" or c == "multirockethydra" or c == "multirocket-hydra":
from tsml_eval.estimators.classification.convolution_based.hydra import (
MultiRocketHydra,
)
return MultiRocketHydra(
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "cnnclassifier" or c == "cnn":
from aeon.classification.deep_learning import CNNClassifier
return CNNClassifier(
random_state=random_state,
**kwargs,
)
elif c == "resnetclassifier" or c == "resnet":
from aeon.classification.deep_learning import ResNetClassifier
return ResNetClassifier(
random_state=random_state,
**kwargs,
)
elif c == "inceptiontimeclassifier" or c == "inceptiontime":
from aeon.classification.deep_learning import InceptionTimeClassifier
return InceptionTimeClassifier(
random_state=random_state,
**kwargs,
)
elif c == "h-inceptiontimeclassifier" or c == "h-inceptiontime":
from aeon.classification.deep_learning import InceptionTimeClassifier
return InceptionTimeClassifier(
use_custom_filters=True, random_state=random_state, **kwargs
)
elif c == "litetimeclassifier" or c == "litetime":
from aeon.classification.deep_learning import LITETimeClassifier
return LITETimeClassifier(random_state=random_state, **kwargs)
elif c == "hivecotev1" or c == "hc1":
from aeon.classification.hybrid import HIVECOTEV1
return HIVECOTEV1(
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "hivecotev2" or c == "hc2":
from aeon.classification.hybrid import HIVECOTEV2
return HIVECOTEV2(
random_state=random_state,
n_jobs=n_jobs,
**kwargs,
)
elif c == "ristclassifier" or c == "rist":
from sklearn.ensemble import ExtraTreesClassifier
from tsml.hybrid import RISTClassifier
return RISTClassifier(
random_state=random_state,
n_jobs=n_jobs,
estimator=ExtraTreesClassifier(n_estimators=500, criterion="entropy"),
**kwargs,
)