Total Complexity | 1 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | from sklearn.datasets import load_boston |
||
2 | from sklearn.ensemble import GradientBoostingRegressor |
||
3 | from sklearn.model_selection import cross_val_score |
||
4 | |||
5 | from hyperactive import Hyperactive |
||
6 | |||
7 | |||
8 | def test_issue_29(): |
||
9 | data = load_boston() |
||
10 | X, y = data.data, data.target |
||
11 | |||
12 | def model(para): |
||
13 | gbr = GradientBoostingRegressor( |
||
14 | n_estimators=para["n_estimators"], |
||
15 | max_depth=para["max_depth"], |
||
16 | min_samples_split=para["min_samples_split"], |
||
17 | ) |
||
18 | scores = cross_val_score(gbr, X, y, cv=3) |
||
19 | |||
20 | print( |
||
21 | "Iteration:", |
||
22 | para.optimizer.nth_iter, |
||
23 | " Best score", |
||
24 | para.optimizer.best_score, |
||
25 | ) |
||
26 | |||
27 | return scores.mean() |
||
28 | |||
29 | search_space = { |
||
30 | "n_estimators": list(range(10, 150, 5)), |
||
31 | "max_depth": list(range(2, 12)), |
||
32 | "min_samples_split": list(range(2, 22)), |
||
33 | } |
||
34 | |||
35 | hyper = Hyperactive() |
||
36 | hyper.add_search(model, search_space, n_iter=20) |
||
37 | hyper.run() |
||
38 |