‘ from sklearn.gaussian_process import GaussianProcess’ error
ImportError: cannot import name 'gaussianprocess'
need change to 'from sklearn import gaussian_process'
I think you mean the example in section 04.03 Error Bar.
If your sklearn version is newer than .20, then sklearn.gaussian_process does not have class GaussianProcess because it has been deprecated since version .18.
Old GaussianProcess should be replaced by GaussianProcessRegressor.
FYI: https://stackoverflow.com/questions/41535569/scikit-learn-gaussianprocessregressor-vs-gaussianprocess-why-was-gaussianproces
For reference, I put a code using GaussianProcessRegressor in the following.
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
This issue is also useful.
https://github.com/jakevdp/PythonDataScienceHandbook/issues/165
@chijan-nh Thanks, it workd!
Hi,
A layman's question: why do you need to change the shape of xdata: xdata[:, np.newaxis]?
In another word, why the gp requires input in that shape when a one dimensional array/list would suffice in my opinion?
Thanks for your explanation in advance!
@chijan-nh Thanks 😊
Hi,
A layman's question: why do you need to change the shape of
xdata: xdata[:, np.newaxis]? In another word, why thegprequires input in that shape when a one dimensional array/list would suffice in my opinion? Thanks for your explanation in advance!
SciKit-Learn algorithms require arrays in the form (n_samples, n_features). xdata[:np.newaxis] transforms xdata from a one-dimensional array to a two-dimensional array of the formate (n_samples, n_features).