Completed
Push — master ( b9a0a2...54ed88 )
by Simon
05:27
created

catboost_classification.model()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nop 3
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