|
1
|
|
|
import GPy |
|
2
|
|
|
from sklearn.gaussian_process import GaussianProcessRegressor |
|
3
|
|
|
from sklearn.gaussian_process.kernels import Matern |
|
4
|
|
|
|
|
5
|
|
|
from sklearn.model_selection import cross_val_score |
|
6
|
|
|
from sklearn.ensemble import GradientBoostingClassifier |
|
7
|
|
|
from sklearn.datasets import load_breast_cancer |
|
8
|
|
|
from hyperactive import Hyperactive |
|
9
|
|
|
|
|
10
|
|
|
data = load_breast_cancer() |
|
11
|
|
|
X, y = data.data, data.target |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
def model(para, X, y): |
|
15
|
|
|
gbc = GradientBoostingClassifier( |
|
16
|
|
|
n_estimators=para["n_estimators"], |
|
17
|
|
|
max_depth=para["max_depth"], |
|
18
|
|
|
min_samples_split=para["min_samples_split"], |
|
19
|
|
|
) |
|
20
|
|
|
scores = cross_val_score(gbc, X, y, cv=3) |
|
21
|
|
|
|
|
22
|
|
|
return scores.mean() |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
search_config = { |
|
26
|
|
|
model: { |
|
27
|
|
|
"n_estimators": range(10, 100, 10), |
|
28
|
|
|
"max_depth": range(2, 12), |
|
29
|
|
|
"min_samples_split": range(2, 12), |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
class GPR0: |
|
34
|
|
|
def __init__(self): |
|
35
|
|
|
self.kernel = GPy.kern.RBF(input_dim=1, variance=1., lengthscale=1.) |
|
36
|
|
|
|
|
37
|
|
|
def fit(self, X, y): |
|
38
|
|
|
self.m = GPy.models.GPRegression(X, y, self.kernel) |
|
39
|
|
|
self.m.optimize(messages=True) |
|
40
|
|
|
|
|
41
|
|
|
def predict(self, X): |
|
42
|
|
|
return self.m.predict(X) |
|
43
|
|
|
|
|
44
|
|
|
class GPR1: |
|
45
|
|
|
def __init__(self): |
|
46
|
|
|
self.gpr = GaussianProcessRegressor( |
|
47
|
|
|
kernel=Matern(nu=2.5), normalize_y=True, n_restarts_optimizer=10 |
|
48
|
|
|
) |
|
49
|
|
|
|
|
50
|
|
|
def fit(self, X, y): |
|
51
|
|
|
self.gpr.fit(X, y) |
|
52
|
|
|
|
|
53
|
|
|
def predict(self, X): |
|
54
|
|
|
return self.gpr.predict(X, return_std=True) |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
opt = Hyperactive(X, y) |
|
58
|
|
|
opt.search(search_config, n_iter=30, optimizer="Bayesian") |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
bayes_opt = {"Bayesian": {"gpr": GPR0()}} |
|
62
|
|
|
opt = Hyperactive(X, y) |
|
63
|
|
|
opt.search(search_config, n_iter=30, optimizer=bayes_opt) |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
bayes_opt = {"Bayesian": {"gpr": GPR1()}} |
|
67
|
|
|
opt = Hyperactive(X, y) |
|
68
|
|
|
opt.search(search_config, n_iter=30, optimizer=bayes_opt) |
|
69
|
|
|
|