jakevdp/PythonDataScienceHandbook

error in 4.5.2 Continuous Errors

Mr-Z-W-J opened this issue · 2 comments

from sklearn.gaussian_process import GaussianProcess

model = lambda x: x * np.sin(x)
xdata = np.array([1, 3, 5, 6, 8])
ydata = model(xdata)

gp = GaussianProcess(corr='cubic', theta0=1e-2, thetaL=1e-4, thetaU=1E-1,
random_start=100)

gp.fit(xdata[:, np.newaxis], ydata)

xfit = np.linspace(0, 10, 1000)
yfit, MSE = gp.predict(xfit[:, np.newaxis], eval_MSE=True)
dyfit = 2 * np.sqrt(MSE) # 2*sigma ~ 95% confidence region

How can I compute the MSE ?

The GaussianProcess has been deprecated. You should try using the GaussianProcessregressor

from sklearn.gaussian_process import GaussianProcessRegressor

define the model and draw some data

model = lambda x: x * np.sin(x)
xdata = np.array([1, 3, 5, 6, 8])
ydata = model(xdata)

Compute the Gaussian process fit

gp = GaussianProcessRegressor()
gp.fit(xdata[:, np.newaxis], ydata)

xfit = np.linspace(0, 10, 1000)
yfit, dyfit_ori = gp.predict(xfit[:, np.newaxis],return_std=True)
dyfit = 2 * dyfit_ori # 2*sigma ~ 95% confidence region