sklearn_preprocessing   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 3

3 Functions

Rating   Name   Duplication   Size   Complexity  
A none() 0 2 1
A pca() 0 4 1
A model() 0 13 1
1
import numpy as np
2
from sklearn.datasets import load_breast_cancer
3
from sklearn.model_selection import cross_val_score
4
from sklearn.decomposition import PCA
5
from sklearn.feature_selection import SelectKBest, f_classif
6
from sklearn.ensemble import GradientBoostingClassifier
7
from hyperactive import Hyperactive
8
9
data = load_breast_cancer()
10
X, y = data.data, data.target
11
12
13
def model(opt):
14
    model = GradientBoostingClassifier(
15
        n_estimators=opt["n_estimators"],
16
        max_depth=opt["max_depth"],
17
    )
18
19
    X_pca = opt["decomposition"](X, opt)
20
    X_mod = np.hstack((X, X_pca))
21
22
    X_best = SelectKBest(f_classif, k=opt["k"]).fit_transform(X_mod, y)
23
    scores = cross_val_score(model, X_best, y, cv=3)
24
25
    return scores.mean()
26
27
28
def pca(X_, opt):
29
    X_ = PCA(n_components=opt["n_components"]).fit_transform(X_)
30
31
    return X_
32
33
34
def none(X_, opt):
35
    return X_
36
37
38
search_space = {
39
    "decomposition": [pca, none],
40
    "k": list(range(2, 30)),
41
    "n_components": list(range(1, 11)),
42
    "n_estimators": list(range(10, 100, 3)),
43
    "max_depth": list(range(2, 12)),
44
}
45
46
47
hyper = Hyperactive()
48
hyper.add_search(model, search_space, n_iter=20)
49
hyper.run()
50