本文整理汇总了Python中sklearn.gaussian_process.kernels.WhiteKernel方法的典型用法代码示例。如果您正苦于以下问题:Python kernels.WhiteKernel方法的具体用法?Python kernels.WhiteKernel怎么用?Python kernels.WhiteKernel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.gaussian_process.kernels
的用法示例。
在下文中一共展示了kernels.WhiteKernel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_learning
# 需要导入模块: from sklearn.gaussian_process import kernels [as 别名]
# 或者: from sklearn.gaussian_process.kernels import WhiteKernel [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)
示例2: test_gp_regression_learner
# 需要导入模块: from sklearn.gaussian_process import kernels [as 别名]
# 或者: from sklearn.gaussian_process.kernels import WhiteKernel [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
示例3: create_gaussian_process
# 需要导入模块: from sklearn.gaussian_process import kernels [as 别名]
# 或者: from sklearn.gaussian_process.kernels import WhiteKernel [as 别名]
def create_gaussian_process(self):
'''
Create the initial Gaussian process.
'''
if self.cost_has_noise:
gp_kernel = skk.RBF(length_scale=self.length_scale) + skk.WhiteKernel(noise_level=self.noise_level)
else:
gp_kernel = skk.RBF(length_scale=self.length_scale)
if self.update_hyperparameters:
self.gaussian_process = skg.GaussianProcessRegressor(kernel=gp_kernel,n_restarts_optimizer=self.hyperparameter_searches)
else:
self.gaussian_process = skg.GaussianProcessRegressor(kernel=gp_kernel,optimizer=None)
示例4: gaussian_emulator
# 需要导入模块: from sklearn.gaussian_process import kernels [as 别名]
# 或者: from sklearn.gaussian_process.kernels import WhiteKernel [as 别名]
def gaussian_emulator(locator, config):
"""
Thi is a Gaussian process linear emulator. It is used to create a surrogate model of CEA whose
output is either rmse or cvrmse
for more details on the work behind this please check:
Rysanek A., Fonseca A., Schlueter, A. Bayesian calibration of Dyanmic building Energy Models. Applied Energy 2017.
:param locator: pointer to location of CEA files
:param samples: matrix m x n with samples simulated from CEA. m are the number of input variables [0,1]
:param cv_rmse: array with results of cv_rmse after running n samples.
:param building_name: name of building whose calibration process is being acted upon
:return:
file with database of emulator stored in locator.get_calibration_cvrmse_file(building_name)
"""
# INITIALIZE TIMER
t0 = time.clock()
# Local variables
building_name = config.single_calibration.building
building_load = config.single_calibration.load
with open(locator.get_calibration_problem(building_name, building_load),'r') as input_file:
problem = pickle.load(input_file)
samples_norm = problem["samples_norm"]
target = problem["cv_rmse"]
# Kernel with parameters given in GPML book for the gaussian surrogate models. The hyperparameters are optimized so you can get anything here.
k1 = 5**2 * RBF(length_scale=1e-5) # long term smooth rising trend RBF: radio basis functions (you can have many, this is one).
k2 = 5**2 * RBF(length_scale=0.000415) * ExpSineSquared(length_scale=3.51e-5, periodicity=0.000199) # seasonal component
# medium term irregularity
k3 = 316**2 * RationalQuadratic(length_scale=3.54, alpha=1e+05)
k4 = 316**2 * RBF(length_scale=4.82) + WhiteKernel(noise_level=0.43) # noise terms
kernel = k1 + k2 + k3 + k4
# give the data to the regressor.
gp = GaussianProcessRegressor(kernel=kernel, alpha=1e-7, normalize_y=True, n_restarts_optimizer=2)
gp.fit(samples_norm, target) # then fit the gp to your observations and the minmax. It takes 30 min - 1 h.
# this is the result
joblib.dump(gp, locator.get_calibration_gaussian_emulator(building_name, building_load))
time_elapsed = time.clock() - t0
print('done - time elapsed: %d.2f seconds' % time_elapsed)
开发者ID:architecture-building-systems,项目名称:CityEnergyAnalyst,代码行数:46,代码来源:calibration_gaussian_emulator.py
示例5: online_learning
# 需要导入模块: from sklearn.gaussian_process import kernels [as 别名]
# 或者: from sklearn.gaussian_process.kernels import WhiteKernel [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