-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_hpsklearn.py
54 lines (44 loc) · 1.57 KB
/
run_hpsklearn.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
import time
import traceback
import hpsklearn
import humanfriendly
import hyperopt
import sklearn
from benchmark import OpenMLBenchmark
max_evals = 325
run_timeout = 60 # in minutes
def main(bm: OpenMLBenchmark):
start = time.time()
X_train = bm.X_train
y_train = bm.y_train
X_test = bm.X_test
y_test = bm.y_test
estimator = hpsklearn.HyperoptEstimator(
preprocessing=hpsklearn.components.any_preprocessing('pp'),
classifier=hpsklearn.components.any_classifier('clf'),
algo=hyperopt.tpe.suggest,
trial_timeout=run_timeout,
max_evals=max_evals,
seed=int(start)
)
estimator.fit(X_train, y_train)
predictions = estimator.predict(X_test)
print('Misclassification rate', 1 - sklearn.metrics.accuracy_score(y_test, predictions))
print('Duration', humanfriendly.format_timespan(time.time() - start))
if __name__ == '__main__':
for i in range(1):
print('#######\nIteration {}\n#######'.format(i))
print('Max Evals: ', max_evals)
print('Run Timeout: ', run_timeout)
task_ids = [15, 23, 24, 29, 3021, 41, 2079, 3543, 3560, 3561,
3904, 3946, 9955, 9985, 7592, 14969, 14968, 14967, 125920, 146606]
for task in task_ids:
print('Starting task {}'.format(task))
bm = OpenMLBenchmark(task)
try:
main(bm)
except Exception as e:
if isinstance(e, KeyboardInterrupt):
raise e
traceback.print_exc()
print('Misclassification rate', 1)