PythonDataScienceHandbook icon indicating copy to clipboard operation
PythonDataScienceHandbook copied to clipboard

error in 4.5.2 Continuous Errors

Open Mr-Z-W-J opened this issue 3 years ago • 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

Mr-Z-W-J avatar Mar 05 '22 05:03 Mr-Z-W-J

How can I compute the MSE ?

Mr-Z-W-J avatar Mar 05 '22 05:03 Mr-Z-W-J

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

andrewxu13 avatar Mar 31 '22 01:03 andrewxu13