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