Class: KernelRidge

Kernel ridge regression.

Kernel ridge regression (KRR) combines ridge regression (linear least squares with l2-norm regularization) with the kernel trick. It thus learns a linear function in the space induced by the respective kernel and the data. For non-linear kernels, this corresponds to a non-linear function in the original space.

The form of the model learned by KRR is identical to support vector regression (SVR). However, different loss functions are used: KRR uses squared error loss while support vector regression uses epsilon-insensitive loss, both combined with l2 regularization. In contrast to SVR, fitting a KRR model can be done in closed-form and is typically faster for medium-sized datasets. On the other hand, the learned model is non-sparse and thus slower than SVR, which learns a sparse model for epsilon > 0, at prediction-time.

This estimator has built-in support for multi-variate regression (i.e., when y is a 2d-array of shape [n_samples, n_targets]).

Read more in the User Guide.

Python Reference

Constructors

new KernelRidge()

new KernelRidge(opts?): KernelRidge

Parameters

ParameterTypeDescription
opts?object-
opts.alpha?number | ArrayLikeRegularization strength; must be a positive float. Regularization improves the conditioning of the problem and reduces the variance of the estimates. Larger values specify stronger regularization. Alpha corresponds to 1 / (2C) in other linear models such as LogisticRegression or LinearSVC. If an array is passed, penalties are assumed to be specific to the targets. Hence they must correspond in number. See Ridge regression and classification for formula.
opts.coef0?numberZero coefficient for polynomial and sigmoid kernels. Ignored by other kernels.
opts.degree?numberDegree of the polynomial kernel. Ignored by other kernels.
opts.gamma?numberGamma parameter for the RBF, laplacian, polynomial, exponential chi2 and sigmoid kernels. Interpretation of the default value is left to the kernel; see the documentation for sklearn.metrics.pairwise. Ignored by other kernels.
opts.kernel?stringKernel mapping used internally. This parameter is directly passed to pairwise_kernels. If kernel is a string, it must be one of the metrics in pairwise.PAIRWISE_KERNEL_FUNCTIONS or “precomputed”. If kernel is “precomputed”, X is assumed to be a kernel matrix. Alternatively, if kernel is a callable function, it is called on each pair of instances (rows) and the resulting value recorded. The callable should take two rows from X as input and return the corresponding kernel value as a single number. This means that callables from sklearn.metrics.pairwise are not allowed, as they operate on matrices, not single samples. Use the string identifying the kernel instead.
opts.kernel_params?anyAdditional parameters (keyword arguments) for kernel function passed as callable object.

Returns KernelRidge

Defined in generated/kernel_ridge/KernelRidge.ts:29

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/kernel_ridge/KernelRidge.ts:27
_isInitializedbooleanfalsegenerated/kernel_ridge/KernelRidge.ts:26
_pyPythonBridgeundefinedgenerated/kernel_ridge/KernelRidge.ts:25
idstringundefinedgenerated/kernel_ridge/KernelRidge.ts:22
optsanyundefinedgenerated/kernel_ridge/KernelRidge.ts:23

Accessors

dual_coef_

Get Signature

get dual_coef_(): Promise<ArrayLike>

Representation of weight vector(s) in kernel space

Returns Promise<ArrayLike>

Defined in generated/kernel_ridge/KernelRidge.ts:367


feature_names_in_

Get Signature

get feature_names_in_(): Promise<ArrayLike>

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

Returns Promise<ArrayLike>

Defined in generated/kernel_ridge/KernelRidge.ts:440


n_features_in_

Get Signature

get n_features_in_(): Promise<number>

Number of features seen during fit.

Returns Promise<number>

Defined in generated/kernel_ridge/KernelRidge.ts:415


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/kernel_ridge/KernelRidge.ts:72


X_fit_

Get Signature

get X_fit_(): Promise<ArrayLike>

Training data, which is also required for prediction. If kernel == “precomputed” this is instead the precomputed training matrix, of shape (n_samples, n_samples).

Returns Promise<ArrayLike>

Defined in generated/kernel_ridge/KernelRidge.ts:392

Methods

dispose()

dispose(): Promise<void>

Disposes of the underlying Python resources.

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

Returns Promise<void>

Defined in generated/kernel_ridge/KernelRidge.ts:124


fit()

fit(opts): Promise<any>

Fit Kernel Ridge regression model.

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?number | ArrayLikeIndividual weights for each sample, ignored if undefined is passed.
opts.X?ArrayLikeTraining data. If kernel == “precomputed” this is instead a precomputed kernel matrix, of shape (n_samples, n_samples).
opts.y?ArrayLikeTarget values.

Returns Promise<any>

Defined in generated/kernel_ridge/KernelRidge.ts:141


get_metadata_routing()

get_metadata_routing(opts): Promise<any>

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Parameters

ParameterTypeDescription
optsobject-
opts.routing?anyA MetadataRequest encapsulating routing information.

Returns Promise<any>

Defined in generated/kernel_ridge/KernelRidge.ts:185


init()

init(py): Promise<void>

Initializes the underlying Python resources.

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

Parameters

ParameterType
pyPythonBridge

Returns Promise<void>

Defined in generated/kernel_ridge/KernelRidge.ts:85


predict()

predict(opts): Promise<ArrayLike>

Predict using the kernel ridge model.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeSamples. If kernel == “precomputed” this is instead a precomputed kernel matrix, shape = [n_samples, n_samples_fitted], where n_samples_fitted is the number of samples used in the fitting for this estimator.

Returns Promise<ArrayLike>

Defined in generated/kernel_ridge/KernelRidge.ts:219


score()

score(opts): Promise<number>

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.

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?ArrayLikeSample weights.
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.y?ArrayLikeTrue values for X.

Returns Promise<number>

Defined in generated/kernel_ridge/KernelRidge.ts:253


set_fit_request()

set_fit_request(opts): Promise<any>

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample_weight parameter in fit.

Returns Promise<any>

Defined in generated/kernel_ridge/KernelRidge.ts:299


set_score_request()

set_score_request(opts): Promise<any>

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample_weight parameter in score.

Returns Promise<any>

Defined in generated/kernel_ridge/KernelRidge.ts:335