Total Complexity | 1 |
Total Lines | 27 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | from sklearn.model_selection import cross_val_score |
||
2 | from catboost import CatBoostClassifier |
||
3 | from sklearn.datasets import load_breast_cancer |
||
4 | from hyperactive import Hyperactive |
||
5 | |||
6 | data = load_breast_cancer() |
||
7 | X, y = data.data, data.target |
||
8 | |||
9 | |||
10 | def model(para, X_train, y_train): |
||
11 | model = CatBoostClassifier(depth=para["depth"], learning_rate=para["learning_rate"]) |
||
12 | scores = cross_val_score(model, X_train, y_train, cv=3) |
||
13 | |||
14 | return scores.mean(), model |
||
15 | |||
16 | |||
17 | # this defines the model and hyperparameter search space |
||
18 | search_config = { |
||
19 | model: {"depth": range(2, 22), "learning_rate": [1e-3, 1e-2, 1e-1, 0.5, 1.0]} |
||
20 | } |
||
21 | |||
22 | |||
23 | opt = Hyperactive(search_config, n_iter=100, n_jobs=2) |
||
24 | |||
25 | # search best hyperparameter for given data |
||
26 | opt.fit(X, y) |
||
27 |