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 (opens in a new tab)
Constructors
constructor()
Signature
new KernelRidge(opts?: object): KernelRidge;
Parameters
Name | Type | Description |
---|---|---|
opts? | object | - |
opts.alpha? | number | ArrayLike | Regularization 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. Default Value 1 |
opts.coef0? | number | Zero coefficient for polynomial and sigmoid kernels. Ignored by other kernels. Default Value 1 |
opts.degree? | number | Degree of the polynomial kernel. Ignored by other kernels. Default Value 3 |
opts.gamma? | number | Gamma 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? | string | Kernel 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. Default Value 'linear' |
opts.kernel_params? | any | Additional parameters (keyword arguments) for kernel function passed as callable object. |
Returns
Defined in: generated/kernel_ridge/KernelRidge.ts:29 (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/kernel_ridge/KernelRidge.ts:131 (opens in a new tab)
fit()
Fit Kernel Ridge regression model.
Signature
fit(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | Training data. If kernel == “precomputed” this is instead a precomputed kernel matrix, of shape (n_samples, n_samples). |
opts.sample_weight? | number | ArrayLike | Individual weights for each sample, ignored if undefined is passed. |
opts.y? | ArrayLike | Target values. |
Returns
Promise
<any
>
Defined in: generated/kernel_ridge/KernelRidge.ts:148 (opens in a new tab)
get_metadata_routing()
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Signature
get_metadata_routing(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.routing? | any | A MetadataRequest encapsulating routing information. |
Returns
Promise
<any
>
Defined in: generated/kernel_ridge/KernelRidge.ts:197 (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
Name | Type |
---|---|
py | PythonBridge |
Returns
Promise
<void
>
Defined in: generated/kernel_ridge/KernelRidge.ts:85 (opens in a new tab)
predict()
Predict using the kernel ridge model.
Signature
predict(opts: object): Promise<ArrayLike>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | Samples. 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:232 (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
Name | Type | Description |
---|---|---|
opts | object | - |
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? | ArrayLike | Sample weights. |
opts.y? | ArrayLike | True values for X . |
Returns
Promise
<number
>
Defined in: generated/kernel_ridge/KernelRidge.ts:267 (opens in a new tab)
set_fit_request()
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:
Signature
set_fit_request(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight? | string | boolean | Metadata routing for sample\_weight parameter in fit . |
Returns
Promise
<any
>
Defined in: generated/kernel_ridge/KernelRidge.ts:318 (opens in a new tab)
set_score_request()
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:
Signature
set_score_request(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight? | string | boolean | Metadata routing for sample\_weight parameter in score . |
Returns
Promise
<any
>
Defined in: generated/kernel_ridge/KernelRidge.ts:355 (opens in a new tab)
Properties
_isDisposed
boolean
=false
Defined in: generated/kernel_ridge/KernelRidge.ts:27 (opens in a new tab)
_isInitialized
boolean
=false
Defined in: generated/kernel_ridge/KernelRidge.ts:26 (opens in a new tab)
_py
PythonBridge
Defined in: generated/kernel_ridge/KernelRidge.ts:25 (opens in a new tab)
id
string
Defined in: generated/kernel_ridge/KernelRidge.ts:22 (opens in a new tab)
opts
any
Defined in: generated/kernel_ridge/KernelRidge.ts:23 (opens in a new tab)
Accessors
X_fit_
Training data, which is also required for prediction. If kernel == “precomputed” this is instead the precomputed training matrix, of shape (n_samples, n_samples).
Signature
X_fit_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/kernel_ridge/KernelRidge.ts:413 (opens in a new tab)
dual_coef_
Representation of weight vector(s) in kernel space
Signature
dual_coef_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/kernel_ridge/KernelRidge.ts:388 (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/kernel_ridge/KernelRidge.ts:461 (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/kernel_ridge/KernelRidge.ts:436 (opens in a new tab)
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/kernel_ridge/KernelRidge.ts:72 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/kernel_ridge/KernelRidge.ts:76 (opens in a new tab)