Passed
Push — master ( 51ad4e...734fb3 )
by Simon
02:30
created

mlxtend_example.model()   A

Complexity

Conditions 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 14
rs 9.95
c 0
b 0
f 0
cc 1
nop 3
1
from sklearn.datasets import load_breast_cancer
2
from sklearn.model_selection import cross_val_score
3
from mlxtend.classifier import EnsembleVoteClassifier
4
from sklearn.ensemble import GradientBoostingClassifier
5
from sklearn.neural_network import MLPClassifier
6
from sklearn.svm import SVC
7
from hyperactive import Hyperactive
8
9
data = load_breast_cancer()
10
X, y = data.data, data.target
11
12
13
def model(para, X, y):
14
    gbc = GradientBoostingClassifier(
15
        n_estimators=para["n_estimators"], max_depth=para["max_depth"]
16
    )
17
    mlp = MLPClassifier(hidden_layer_sizes=para["hidden_layer_sizes"])
18
    svc = SVC(gamma="auto", probability=True)
19
20
    eclf = EnsembleVoteClassifier(
21
        clfs=[gbc, mlp, svc], weights=[2, 1, 1], voting="soft"
22
    )
23
24
    scores = cross_val_score(eclf, X, y, cv=3)
25
26
    return scores.mean()
27
28
29
search_config = {
30
    model: {
31
        "n_estimators": range(10, 100, 10),
32
        "max_depth": range(2, 12),
33
        "hidden_layer_sizes": (range(10, 100, 10),),
34
    }
35
}
36
37
38
opt = Hyperactive(search_config, n_iter=30)
39
opt.search(X, y)
40