jakevdp / PythonDataScienceHandbook

Python Data Science Handbook: full text in Jupyter Notebooks
http://jakevdp.github.io/PythonDataScienceHandbook
MIT License
43.12k stars 17.91k forks source link

error in 4.5.2 Continuous Errors #326

Open Mr-Z-W-J opened 2 years ago

Mr-Z-W-J commented 2 years ago

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) # 2sigma ~ 95% confidence region

Mr-Z-W-J commented 2 years ago

How can I compute the MSE ?

andrewxu13 commented 2 years ago

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 # 2sigma ~ 95% confidence region