Total Complexity | 1 |
Total Lines | 36 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | from sklearn.model_selection import cross_val_score |
||
2 | from sklearn.ensemble import GradientBoostingClassifier |
||
3 | from sklearn.datasets import load_breast_cancer |
||
4 | from hyperactive import Hyperactive |
||
5 | |||
6 | import ray |
||
7 | |||
8 | data = load_breast_cancer() |
||
9 | X, y = data.data, data.target |
||
10 | |||
11 | |||
12 | def gbc_(para, X, y): |
||
13 | model = GradientBoostingClassifier( |
||
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(model, X, y) |
||
19 | |||
20 | return scores.mean() |
||
21 | |||
22 | |||
23 | search_config = { |
||
24 | gbc_: { |
||
25 | "n_estimators": range(1, 20, 1), |
||
26 | "max_depth": range(2, 12), |
||
27 | "min_samples_split": range(2, 12), |
||
28 | } |
||
29 | } |
||
30 | |||
31 | |||
32 | ray.init(num_cpus=4) |
||
33 | |||
34 | opt = Hyperactive(X, y) |
||
35 | opt.search(search_config, n_jobs=4) |
||
36 |