GaussianProcessRegressor#

class GaussianProcessRegressor(*, kernel: Literal['rbf', 'matern32', 'matern52'] | AbstractKernel = 'matern52', mean_function: Literal['zero', 'constant', 'linear'] | AbstractMeanFunction = 'constant', learned_noise: Literal['constant', 'heteroscedastic'] | None = 'constant', noise_column: str | None = None, iterations: int = 2000)[source]#

skgp’s GPRegressor as a scikit-learn estimator: an exact Gaussian process regression model, with skgp’s settings.

The inputs come from X and the target from y, so there are no features or target; and no schema, because a Pipeline has changed the data before it gets here. Every other setting is a GPRegressor’s, checked at fit:

  • kernel: "matern52" (the default), "matern32", "rbf" or a GPJax kernel. Its length scales are in the units of the columns of X.

  • mean_function: what the curve is far from the training data: "constant" (the default), "zero", "linear" or a GPJax mean function.

  • learned_noise: "constant" (the default), "heteroscedastic", or None, which needs a noise_column.

  • noise_column: the column of X that holds each row’s known noise, as a standard deviation in the target’s units, or None (the default). It is not an input. For an array, name it as its column is named: "x3" for the fourth.

  • iterations: the most iterations the fit may take, 2,000 by default.

After fit: fitted_ is the fitted skgp model (print(estimator.fitted_), estimator.fitted_.to_json()), n_features_in_ is the number of columns of X, and feature_names_in_ their names when X named them.

Expand for references to skgp.sklearn.GaussianProcessRegressor

Using skgp with scikit-learn / Switching from scikit-learn’s Gaussian processes

fit(X: Any, y: Any) → Self#

Fit to the inputs X and the target y, and return this estimator, fitted.

X is a Polars or pandas dataframe, whose columns keep their names, or a numeric array, whose columns are called x0, x1, …; y holds one number per row. The skgp model checks the data and the settings, and raises ValueError naming what is wrong. The fitted skgp model is fitted_.

Expand for references to skgp.sklearn.GaussianProcessRegressor.fit

Using skgp with scikit-learn / Switching from scikit-learn’s Gaussian processes

predict(X: Any, return_std: bool = False, return_cov: bool = False, include_noise: bool = True) → Any#

The predicted mean of each row of X, in the target’s units, as a numpy array; with return_std=True also the standard deviation of each row, and with return_cov=True the covariance between the rows instead, as scikit-learn’s GaussianProcessRegressor.predict gives them.

Unlike scikit-learn’s, the spread is of a new observation, measurement noise included, unless include_noise=False, which gives the spread of the underlying curve. X has the columns it had at fit, as scikit-learn requires, so a model with known noise has its noise_column there even for the curve alone, whose prediction does not use it.

Expand for references to skgp.sklearn.GaussianProcessRegressor.predict

Using skgp with scikit-learn / Switching from scikit-learn’s Gaussian processes

sample_y(X: Any, n_samples: int = 1, random_state: int = 0, include_noise: bool = True) → ndarray#

Random samples of the prediction at the rows of X: a numpy array of a row for each row and a column for each sample, as scikit-learn’s sample_y gives (see skgp.Prediction.sample). Each sample includes measurement noise unless include_noise=False. random_state is a whole number.

Expand for references to skgp.sklearn.GaussianProcessRegressor.sample_y

Using skgp with scikit-learn / Switching from scikit-learn’s Gaussian processes

score(X: Any, y: Any, sample_weight: None = None) → float#

The mean CRPS of the predictions of y at the rows X, with its sign flipped, so that higher is better (see neg_crps). It is what cross_val_score and GridSearchCV use when given no scoring, in place of the R² scikit-learn’s regressors give. Rows cannot be weighted.