@@ -47,13 +47,14 @@ class GaussianProcessRegressor(BaseEstimator, RegressorMixin):
4747
4848 alpha : float or array-like, optional (default: 1e-10)
4949 Value added to the diagonal of the kernel matrix during fitting.
50- Larger values correspond to increased noise level in the observations
51- and reduce potential numerical issue during fitting. If an array is
52- passed, it must have the same number of entries as the data used for
53- fitting and is used as datapoint-dependent noise level. Note that this
54- is equivalent to adding a WhiteKernel with c=alpha. Allowing to specify
55- the noise level directly as a parameter is mainly for convenience and
56- for consistency with Ridge.
50+ Larger values correspond to increased noise level in the observations.
51+ This can also prevent a potential numerical issue during fitting, by
52+ ensuring that the calculated values form a positive definite matrix.
53+ If an array is passed, it must have the same number of entries as the
54+ data used for fitting and is used as datapoint-dependent noise level.
55+ Note that this is equivalent to adding a WhiteKernel with c=alpha.
56+ Allowing to specify the noise level directly as a parameter is mainly
57+ for convenience and for consistency with Ridge.
5758
5859 optimizer : string or callable, optional (default: "fmin_l_bfgs_b")
5960 Can either be one of the internally supported optimizers for optimizing
@@ -242,9 +243,16 @@ def obj_func(theta, eval_gradient=True):
242243 # of actual query points
243244 K = self .kernel_ (self .X_train_ )
244245 K [np .diag_indices_from (K )] += self .alpha
245- self .L_ = cholesky (K , lower = True ) # Line 2
246+ try :
247+ self .L_ = cholesky (K , lower = True ) # Line 2
248+ except np .linalg .LinAlgError as exc :
249+ exc .args = ("The kernel, %s, is not returning a "
250+ "positive definite matrix. Try gradually "
251+ "increasing the 'alpha' parameter of your "
252+ "GaussianProcessRegressor estimator."
253+ % self .kernel_ ,) + exc .args
254+ raise
246255 self .alpha_ = cho_solve ((self .L_ , True ), self .y_train_ ) # Line 3
247-
248256 return self
249257
250258 def predict (self , X , return_std = False , return_cov = False ):
0 commit comments