1
|
|
|
from sklearn.model_selection import cross_val_score |
2
|
|
|
from sklearn.ensemble import GradientBoostingRegressor |
3
|
|
|
from sklearn.datasets import load_boston |
4
|
|
|
|
5
|
|
|
from hyperactive import Hyperactive |
6
|
|
|
|
7
|
|
|
# import the ProgressBoard |
8
|
|
|
from hyperactive.dashboards import ProgressBoard |
9
|
|
|
|
10
|
|
|
data = load_boston() |
11
|
|
|
X, y = data.data, data.target |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
def model(opt): |
15
|
|
|
gbr = GradientBoostingRegressor( |
16
|
|
|
n_estimators=opt["n_estimators"], |
17
|
|
|
max_depth=opt["max_depth"], |
18
|
|
|
min_samples_split=opt["min_samples_split"], |
19
|
|
|
) |
20
|
|
|
scores = cross_val_score(gbr, X, y, cv=3) |
21
|
|
|
|
22
|
|
|
return scores.mean() |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
search_space = { |
26
|
|
|
"n_estimators": list(range(50, 150, 5)), |
27
|
|
|
"max_depth": list(range(2, 12)), |
28
|
|
|
"min_samples_split": list(range(2, 22)), |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
# create an instance of the ProgressBoard |
32
|
|
|
progress_board = ProgressBoard() |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
hyper = Hyperactive() |
36
|
|
|
|
37
|
|
|
hyper.add_search( |
38
|
|
|
model, |
39
|
|
|
search_space, |
40
|
|
|
n_iter=120, |
41
|
|
|
n_jobs=2, # the progress board works seamlessly with multiprocessing |
42
|
|
|
progress_board=progress_board, # pass the instance of the ProgressBoard to .add_search(...) |
43
|
|
|
) |
44
|
|
|
|
45
|
|
|
# a terminal will open, which opens a dashboard in your browser |
46
|
|
|
hyper.run() |
47
|
|
|
|