model_selection   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 49
dl 0
loc 78
rs 10
c 0
b 0
f 0
wmc 9

9 Functions

Rating   Name   Duplication   Size   Complexity  
A model() 0 6 1
A DecisionTreeRegressor_f() 0 2 1
A SVR_f() 0 2 1
A MLPRegressor_f() 0 2 1
A ExtraTreesRegressor_f() 0 2 1
A GradientBoostingRegressor_f() 0 2 1
A RandomForestRegressor_f() 0 2 1
A GaussianProcessRegressor_f() 0 2 1
A KNeighborsRegressor_f() 0 2 1
1
from sklearn.model_selection import cross_val_score
2
3
from sklearn.svm import SVR
4
from sklearn.neighbors import KNeighborsRegressor
5
from sklearn.gaussian_process import GaussianProcessRegressor
6
from sklearn.tree import DecisionTreeRegressor
7
from sklearn.ensemble import (
8
    GradientBoostingRegressor,
9
    RandomForestRegressor,
10
    ExtraTreesRegressor,
11
)
12
from sklearn.neural_network import MLPRegressor
13
14
from sklearn.datasets import load_diabetes
15
from hyperactive import Hyperactive
16
17
data = load_diabetes()
18
X, y = data.data, data.target
19
20
21
def model(opt):
22
    model_class = opt["regressor"]()
23
    model = model_class()
24
    scores = cross_val_score(model, X, y, cv=5)
25
26
    return scores.mean()
27
28
29
def SVR_f():
30
    return SVR
31
32
33
def KNeighborsRegressor_f():
34
    return KNeighborsRegressor
35
36
37
def GaussianProcessRegressor_f():
38
    return GaussianProcessRegressor
39
40
41
def DecisionTreeRegressor_f():
42
    return DecisionTreeRegressor
43
44
45
def GradientBoostingRegressor_f():
46
    return GradientBoostingRegressor
47
48
49
def RandomForestRegressor_f():
50
    return RandomForestRegressor
51
52
53
def ExtraTreesRegressor_f():
54
    return ExtraTreesRegressor
55
56
57
def MLPRegressor_f():
58
    return MLPRegressor
59
60
61
search_space = {
62
    "regressor": [
63
        SVR_f,
64
        KNeighborsRegressor_f,
65
        GaussianProcessRegressor_f,
66
        DecisionTreeRegressor_f,
67
        GradientBoostingRegressor_f,
68
        RandomForestRegressor_f,
69
        ExtraTreesRegressor_f,
70
        MLPRegressor_f,
71
    ],
72
}
73
74
75
hyper = Hyperactive()
76
hyper.add_search(model, search_space, n_iter=50)
77
hyper.run()
78