Passed
Push — master ( ef01f2...fd3757 )
by Simon
01:46 queued 10s
created

Scatter-initialization.model()   A

Complexity

Conditions 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 1
nop 3
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
data = load_breast_cancer()
7
X, y = data.data, data.target
8
9
10
def model(para, X, y):
11
    gbc = GradientBoostingClassifier(
12
        n_estimators=para["n_estimators"],
13
        max_depth=para["max_depth"],
14
        min_samples_split=para["min_samples_split"],
15
    )
16
    scores = cross_val_score(gbc, X, y, cv=3)
17
18
    return scores.mean()
19
20
21
search_config = {
22
    model: {
23
        "n_estimators": range(10, 200, 10),
24
        "max_depth": range(2, 12),
25
        "min_samples_split": range(2, 12),
26
    }
27
}
28
29
# Without scatter initialization
30
opt = Hyperactive(X, y)
31
opt.search(
32
    search_config,
33
    optimizer="HillClimbing",
34
    n_iter=10,
35
    random_state=0,
36
    init_config=False,
37
)
38
39
init_config = {"scatter_init": 10}
40
41
# With scatter initialization
42
opt = Hyperactive(X, y)
43
opt.search(
44
    search_config,
45
    optimizer="HillClimbing",
46
    n_iter=10,
47
    random_state=0,
48
    init_config=init_config,
49
)
50