本文整理汇总了Python中sklearn.gaussian_process.kernels.ConstantKernel方法的典型用法代码示例。如果您正苦于以下问题:Python kernels.ConstantKernel方法的具体用法?Python kernels.ConstantKernel怎么用?Python kernels.ConstantKernel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.gaussian_process.kernels
的用法示例。
在下文中一共展示了kernels.ConstantKernel方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_random_starts
# 需要导入模块: from sklearn.gaussian_process import kernels [as 别名]
# 或者: from sklearn.gaussian_process.kernels import ConstantKernel [as 别名]
def test_random_starts():
# Test that an increasing number of random-starts of GP fitting only
# increases the log marginal likelihood of the chosen theta.
n_samples, n_features = 25, 2
rng = np.random.RandomState(0)
X = rng.randn(n_samples, n_features) * 2 - 1
y = (np.sin(X).sum(axis=1) + np.sin(3 * X).sum(axis=1)) > 0
kernel = C(1.0, (1e-2, 1e2)) \
* RBF(length_scale=[1e-3] * n_features,
length_scale_bounds=[(1e-4, 1e+2)] * n_features)
last_lml = -np.inf
for n_restarts_optimizer in range(5):
gp = GaussianProcessClassifier(
kernel=kernel, n_restarts_optimizer=n_restarts_optimizer,
random_state=0).fit(X, y)
lml = gp.log_marginal_likelihood(gp.kernel_.theta)
assert_greater(lml, last_lml - np.finfo(np.float32).eps)
last_lml = lml
示例2: __init__
# 需要导入模块: from sklearn.gaussian_process import kernels [as 别名]
# 或者: from sklearn.gaussian_process.kernels import ConstantKernel [as 别名]
def __init__(self, **kwargs):
super(GPR, self).__init__(**kwargs)
self.name = "GPR"
self.detail = "Gaussian Process Regression"
self.is_high_order = True
self.has_point_forecasting = True
self.has_interval_forecasting = True
self.has_probability_forecasting = True
self.uod_clip = False
self.benchmark_only = True
self.min_order = 1
self.alpha = kwargs.get("alpha", 0.05)
self.data = None
self.lscale = kwargs.get('length_scale', 1)
self.kernel = ConstantKernel(1.0) * RBF(length_scale=self.lscale)
self.model = GaussianProcessRegressor(kernel=self.kernel, alpha=.05,
n_restarts_optimizer=10,
normalize_y=False)
#self.model_fit = None
示例3: GP_regression
# 需要导入模块: from sklearn.gaussian_process import kernels [as 别名]
# 或者: from sklearn.gaussian_process.kernels import ConstantKernel [as 别名]
def GP_regression(tr_x,tr_y,test_x):
A = np.ones((len(tr_x),2))
A[:,0] = tr_x[:,0]
p = np.matmul(np.linalg.pinv(A),tr_y)
mean_tr_y = np.matmul(A,p)
A = np.ones((len(test_x),2))
A[:,0] = test_x[:,0]
mean_test_y = np.matmul(A,p)
kernel = ConstantKernel(100,(1e-5, 1e5))*RBF(1, (1e-5, 1e5))+RBF(1, (1e-5, 1e5))
gp = GaussianProcessRegressor(kernel=kernel, alpha=1, n_restarts_optimizer=9)
gp.fit(tr_x, tr_y-mean_tr_y)
test_y, sigma = gp.predict(test_x, return_std=True)
test_y = test_y+mean_test_y
#import pdb; pdb.set_trace()
return test_y
示例4: __init__
# 需要导入模块: from sklearn.gaussian_process import kernels [as 别名]
# 或者: from sklearn.gaussian_process.kernels import ConstantKernel [as 别名]
def __init__(self, space):
self.space = space
self.k = kernels.ConstantKernel() * kernels.RBF()