Documentation
Classes
GaussianProcessRegressor

GaussianProcessRegressor

Gaussian process regression (GPR).

The implementation is based on Algorithm 2.1 of [RW2006].

In addition to standard scikit-learn estimator API, GaussianProcessRegressor:

Python Reference (opens in a new tab)

Constructors

constructor()

Signature

new GaussianProcessRegressor(opts?: object): GaussianProcessRegressor;

Parameters

NameTypeDescription
opts?object-
opts.alpha?number | ArrayLikeValue added to the diagonal of the kernel matrix during fitting. This can prevent a potential numerical issue during fitting, by ensuring that the calculated values form a positive definite matrix. It can also be interpreted as the variance of additional Gaussian measurement noise on the training observations. Note that this is different from using a WhiteKernel. If an array is passed, it must have the same number of entries as the data used for fitting and is used as datapoint-dependent noise level. Allowing to specify the noise level directly as a parameter is mainly for convenience and for consistency with Ridge. Default Value 1e-10
opts.copy_X_train?booleanIf true, a persistent copy of the training data is stored in the object. Otherwise, just a reference to the training data is stored, which might cause predictions to change if the data is modified externally. Default Value true
opts.kernel?anyThe kernel specifying the covariance function of the GP. If undefined is passed, the kernel ConstantKernel(1.0, constant\_value\_bounds="fixed") \* RBF(1.0, length\_scale\_bounds="fixed") is used as default. Note that the kernel hyperparameters are optimized during fitting unless the bounds are marked as “fixed”.
opts.n_restarts_optimizer?numberThe number of restarts of the optimizer for finding the kernel’s parameters which maximize the log-marginal likelihood. The first run of the optimizer is performed from the kernel’s initial parameters, the remaining ones (if any) from thetas sampled log-uniform randomly from the space of allowed theta-values. If greater than 0, all bounds must be finite. Note that n\_restarts\_optimizer \== 0 implies that one run is performed. Default Value 0
opts.normalize_y?booleanWhether or not to normalize the target values y by removing the mean and scaling to unit-variance. This is recommended for cases where zero-mean, unit-variance priors are used. Note that, in this implementation, the normalisation is reversed before the GP predictions are reported. Default Value false
opts.optimizer?"fmin_l_bfgs_b"Can either be one of the internally supported optimizers for optimizing the kernel’s parameters, specified by a string, or an externally defined optimizer passed as a callable. If a callable is passed, it must have the signature: Default Value 'fmin_l_bfgs_b'
opts.random_state?numberDetermines random number generation used to initialize the centers. Pass an int for reproducible results across multiple function calls. See Glossary.

Returns

GaussianProcessRegressor

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:25 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:23 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:22 (opens in a new tab)

_py

PythonBridge

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:21 (opens in a new tab)

id

string

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:18 (opens in a new tab)

opts

any

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:19 (opens in a new tab)

Accessors

L_

Lower-triangular Cholesky decomposition of the kernel in X\_train\_.

Signature

L_(): Promise<ArrayLike[]>;

Returns

Promise<ArrayLike[]>

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:497 (opens in a new tab)

X_train_

Feature vectors or other representations of training data (also required for prediction).

Signature

X_train_(): Promise<ArrayLike[]>;

Returns

Promise<ArrayLike[]>

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:416 (opens in a new tab)

alpha_

Dual coefficients of training data points in kernel space.

Signature

alpha_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:524 (opens in a new tab)

feature_names_in_

Names of features seen during fit. Defined only when X has feature names that are all strings.

Signature

feature_names_in_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:605 (opens in a new tab)

kernel_

The kernel used for prediction. The structure of the kernel is the same as the one passed as parameter but with optimized hyperparameters.

Signature

kernel_(): Promise<any>;

Returns

Promise<any>

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:470 (opens in a new tab)

log_marginal_likelihood_value_

The log-marginal-likelihood of self.kernel\_.theta.

Signature

log_marginal_likelihood_value_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:551 (opens in a new tab)

n_features_in_

Number of features seen during fit.

Signature

n_features_in_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:578 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:75 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:79 (opens in a new tab)

y_train_

Target values in training data (also required for prediction).

Signature

y_train_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:443 (opens in a new tab)

Methods

dispose()

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Signature

dispose(): Promise<void>;

Returns

Promise<void>

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:142 (opens in a new tab)

fit()

Fit Gaussian process regression model.

Signature

fit(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]Feature vectors or other representations of training data.
opts.y?ArrayLikeTarget values.

Returns

Promise<any>

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:159 (opens in a new tab)

init()

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Signature

init(py: PythonBridge): Promise<void>;

Parameters

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:88 (opens in a new tab)

log_marginal_likelihood()

Return log-marginal likelihood of theta for training data.

Signature

log_marginal_likelihood(opts: object): Promise<number>;

Parameters

NameTypeDescription
optsobject-
opts.clone_kernel?booleanIf true, the kernel attribute is copied. If false, the kernel attribute is modified, but may result in a performance improvement. Default Value true
opts.eval_gradient?booleanIf true, the gradient of the log-marginal likelihood with respect to the kernel hyperparameters at position theta is returned additionally. If true, theta must not be undefined. Default Value false
opts.theta?anyKernel hyperparameters for which the log-marginal likelihood is evaluated. If undefined, the precomputed log_marginal_likelihood of self.kernel\_.theta is returned.

Returns

Promise<number>

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:201 (opens in a new tab)

predict()

Predict using the Gaussian process regression model.

We can also predict based on an unfitted model by using the GP prior. In addition to the mean of the predictive distribution, optionally also returns its standard deviation (return\_std=True) or covariance (return\_cov=True). Note that at most one of the two can be requested.

Signature

predict(opts: object): Promise<ArrayLike>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]Query points where the GP is evaluated.
opts.return_cov?booleanIf true, the covariance of the joint predictive distribution at the query points is returned along with the mean. Default Value false
opts.return_std?booleanIf true, the standard-deviation of the predictive distribution at the query points is returned along with the mean. Default Value false

Returns

Promise<ArrayLike>

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:257 (opens in a new tab)

sample_y()

Draw samples from Gaussian process and evaluate at X.

Signature

sample_y(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]Query points where the GP is evaluated.
opts.n_samples?numberNumber of samples drawn from the Gaussian process per query point. Default Value 1
opts.random_state?numberDetermines random number generation to randomly draw samples. Pass an int for reproducible results across multiple function calls. See Glossary. Default Value 0

Returns

Promise<any>

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:310 (opens in a new tab)

score()

Return the coefficient of determination of the prediction.

The coefficient of determination \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y\_true \- y\_pred)\*\* 2).sum() and \(v\) is the total sum of squares ((y\_true \- y\_true.mean()) \*\* 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.

Signature

score(opts: object): Promise<number>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n\_samples, n\_samples\_fitted), where n\_samples\_fitted is the number of samples used in the fitting for the estimator.
opts.sample_weight?ArrayLikeSample weights.
opts.y?ArrayLikeTrue values for X.

Returns

Promise<number>

Defined in: generated/gaussian_process/GaussianProcessRegressor.ts:365 (opens in a new tab)