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.
Constructors
new KernelRidge()
new KernelRidge(
opts?):KernelRidge
Parameters
| Parameter | 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. |
opts.coef0? | number | Zero coefficient for polynomial and sigmoid kernels. Ignored by other kernels. |
opts.degree? | number | Degree of the polynomial kernel. Ignored by other kernels. |
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. |
opts.kernel_params? | any | Additional parameters (keyword arguments) for kernel function passed as callable object. |
Returns KernelRidge
Defined in generated/kernel_ridge/KernelRidge.ts:29
Properties
| Property | Type | Default value | Defined in |
|---|---|---|---|
_isDisposed | boolean | false | generated/kernel_ridge/KernelRidge.ts:27 |
_isInitialized | boolean | false | generated/kernel_ridge/KernelRidge.ts:26 |
_py | PythonBridge | undefined | generated/kernel_ridge/KernelRidge.ts:25 |
id | string | undefined | generated/kernel_ridge/KernelRidge.ts:22 |
opts | any | undefined | generated/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
| Parameter | Type |
|---|---|
pythonBridge | PythonBridge |
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
| Parameter | Type | Description |
|---|---|---|
opts | object | - |
opts.sample_weight? | number | ArrayLike | Individual weights for each sample, ignored if undefined is passed. |
opts.X? | ArrayLike | Training data. If kernel == “precomputed” this is instead a precomputed kernel matrix, of shape (n_samples, n_samples). |
opts.y? | ArrayLike | Target 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
| Parameter | Type | Description |
|---|---|---|
opts | object | - |
opts.routing? | any | A 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
| Parameter | Type |
|---|---|
py | PythonBridge |
Returns Promise<void>
Defined in generated/kernel_ridge/KernelRidge.ts:85
predict()
predict(
opts):Promise<ArrayLike>
Predict using the kernel ridge model.
Parameters
| Parameter | 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: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
| Parameter | Type | Description |
|---|---|---|
opts | object | - |
opts.sample_weight? | ArrayLike | Sample 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? | ArrayLike | True 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
| Parameter | 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: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
| Parameter | 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:335