GPRegression
( GPy
) 和GaussianProcessRegressor
( )都scikit-learn
使用相似的初始值和相同的优化器 ( lbfgs
)。为什么结果差异很大?
#!pip -qq install pods
#!pip -qq install GPy
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import RBF, ConstantKernel as C
from sklearn.preprocessing import StandardScaler
import pods
data = pods.datasets.olympic_marathon_men()
X = StandardScaler().fit_transform(data['X'])
y = data['Y']
# scikit-learn
model = GaussianProcessRegressor(C()*RBF(), n_restarts_optimizer=20, random_state=0)
model.fit(X, y)
print(model.kernel_)
# GPy
from GPy.models import GPRegression
from GPy.kern import RBF as GPyRBF
model = GPRegression(X, y, GPyRBF(1))
model.optimize_restarts(20, verbose=0)
print(model.kern)
结果
2.89**2 * RBF(length_scale=0.173)
rbf. | value | constraints | priors
variance | 25.399509298957504 | +ve |
lengthscale | 4.279767394389103 | +ve |