本文整理汇总了Python中sklearn.gaussian_process.kernels.DotProduct方法的典型用法代码示例。如果您正苦于以下问题:Python kernels.DotProduct方法的具体用法?Python kernels.DotProduct怎么用?Python kernels.DotProduct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.gaussian_process.kernels
的用法示例。
在下文中一共展示了kernels.DotProduct方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_gpr_correct_error_message
# 需要导入模块: from sklearn.gaussian_process import kernels [as 别名]
# 或者: from sklearn.gaussian_process.kernels import DotProduct [as 别名]
def test_gpr_correct_error_message():
X = np.arange(12).reshape(6, -1)
y = np.ones(6)
kernel = DotProduct()
gpr = GaussianProcessRegressor(kernel=kernel, alpha=0.0)
assert_raise_message(np.linalg.LinAlgError,
"The kernel, %s, is not returning a "
"positive definite matrix. Try gradually increasing "
"the 'alpha' parameter of your "
"GaussianProcessRegressor estimator."
% kernel, gpr.fit, X, y)
示例2: test_learning
# 需要导入模块: from sklearn.gaussian_process import kernels [as 别名]
# 或者: from sklearn.gaussian_process.kernels import DotProduct [as 别名]
def test_learning(self):
"""General testing for catkit.learn"""
with FingerprintDB(data_path) as fp:
X = fp.get_fingerprints(params=np.arange(20) + 1)
y = fp.get_fingerprints(params=['Ef']).T[0]
X0, X1, y0, y1 = train_test_split(X, y, test_size=0.6, shuffle=True)
kernel = DotProduct() + WhiteKernel()
gp = GaussianProcessRegressor(
kernel=kernel, optimizer=optimizer,
n_restarts_optimizer=0, alpha=0)
gp.fit(X0, y0)
# This is an ugly way to define default properties
# The 3rd argument is for a certain number of global
# optimization steps using the basinhopping algorithm
optimizer.__defaults__ = (True, 'L-BFGS-B', 3)
gp = GaussianProcessRegressor(
kernel=kernel, optimizer=optimizer,
n_restarts_optimizer=0, alpha=0)
gp.fit(X0, y0)
samples = online_learning(
X, y, [0, 1, 2], factors=[1, 1], nsteps=3, plot=True)
test_array = np.array([0, 1, 2, 24, 15, 23])
np.testing.assert_allclose(samples, test_array)
示例3: test_gp_regression_learner
# 需要导入模块: from sklearn.gaussian_process import kernels [as 别名]
# 或者: from sklearn.gaussian_process.kernels import DotProduct [as 别名]
def test_gp_regression_learner():
df_train = pd.DataFrame({
'id': ["id1", "id2", "id3", "id4"],
'x1': [10.0, 13.0, 10.0, 13.0],
"x2": [0, 1, 1, 0],
'y': [2.3, 4.0, 100.0, -3.9]
})
df_test = pd.DataFrame({
'id': ["id4", "id4", "id5", "id6"],
'x1': [12.0, 1000.0, -4.0, 0.0],
"x2": [1, 1, 0, 1],
'y': [1.3, -4.0, 0.0, 49]
})
from sklearn.gaussian_process.kernels import RBF, WhiteKernel, DotProduct
kernel = RBF() + WhiteKernel() + DotProduct()
learner = gp_regression_learner(features=["x1", "x2"],
target="y",
kernel=kernel,
alpha=0.1,
extra_variance="fit",
return_std=True,
extra_params=None,
prediction_column="prediction")
predict_fn, pred_train, log = learner(df_train)
pred_test = predict_fn(df_test)
expected_col_train = df_train.columns.tolist() + ["prediction", "prediction_std"]
expected_col_test = df_test.columns.tolist() + ["prediction", "prediction_std"]
assert Counter(expected_col_train) == Counter(pred_train.columns.tolist())
assert Counter(expected_col_test) == Counter(pred_test.columns.tolist())
assert (pred_test.columns == pred_train.columns).all()
assert "prediction" in pred_test.columns
示例4: online_learning
# 需要导入模块: from sklearn.gaussian_process import kernels [as 别名]
# 或者: from sklearn.gaussian_process.kernels import DotProduct [as 别名]
def online_learning(X, y, samples, factors=[1.0, 1.0], nsteps=40, plot=False):
"""A simple utility for performing online learning. The main
components required are a regression method and a scoring
technique.
Currently, the scoring methodology and regressor are baked in.
These need to be made modular.
Minimum 3 samples are required for 3 fold cross validation.
"""
ids = np.arange(len(y))
kernel = DotProduct() + WhiteKernel()
regressor = GaussianProcessRegressor(
kernel=kernel, n_restarts_optimizer=5, alpha=0)
step = 0
while step < nsteps:
X0 = X[samples]
y0 = y[samples]
regressor.fit(X0, y0)
yp, ys = regressor.predict(X, return_std=True)
# Provides some form of normalization.
# Multiples denote relative importance
yp_scale = preprocessing.scale(yp) * factors[0]
ys_scale = preprocessing.scale(ys) * factors[1]
score = ys_scale - yp_scale
srt = np.argsort(score)[::-1]
for s in srt:
if s not in samples:
samples = np.concatenate([samples, [s]])
break
if plot:
mae = np.round(mean_absolute_error(yp, y), 3)
n = len(samples)
fig, ax = plt.subplots(figsize=(6, 4))
ax.plot(ids, y, 'o', zorder=0)
ax.errorbar(ids, yp, yerr=ys, fmt='o', zorder=1)
ax.plot(samples, y[samples], 'o', zorder=3)
xlim = ax.get_xlim()
ylim = ax.get_ylim()
ax.text(xlim[0] / 9.0, ylim[0] / 9.0, mae)
plt.tight_layout()
plt.savefig('./online-learning-RBF-{}.png'.format(n))
plt.close()
step += 1
return samples