himalaya.kernel_ridge.KernelRidgeCV

class himalaya.kernel_ridge.KernelRidgeCV(alphas=[0.1, 1], kernel='linear', kernel_params=None, solver='eigenvalues', solver_params=None, fit_intercept=False, cv=5, Y_in_cpu=False, force_cpu=False, warn=True)[source]

Kernel ridge regression with efficient cross-validation over alpha.

Parameters
alphasarray of shape (n_alphas, )

List of L2 regularization parameter to try.

kernelstr or callable, default=”linear”

Kernel mapping. Available kernels are: ‘linear’, ‘polynomial, ‘poly’, ‘rbf’, ‘sigmoid’, ‘cosine’, or ‘precomputed’. Set to ‘precomputed’ in order to pass a precomputed kernel matrix to the estimator methods instead of samples. A callable should accept two arguments and the keyword arguments passed to this object as kernel_params, and should return a floating point number.

kernel_paramsdict or None

Additional parameters for the kernel function. See more details in the docstring of the function: KernelRidgeCV.ALL_KERNELS[kernel]

solverstr

Algorithm used during the fit, “eigenvalues” only for now.

solver_paramsdict or None

Additional parameters for the solver. See more details in the docstring of the function: KernelRidgeCV.ALL_SOLVERS[solver]

fit_interceptboolean

Whether to fit an intercept. If False, X and Y must be zero-mean over samples.

cvint or scikit-learn splitter

Cross-validation splitter. If an int, KFold is used.

Y_in_cpubool

If True, keep the target values y in CPU memory (slower).

force_cpubool

If True, computations will be performed on CPU, ignoring the current backend. If False, use the current backend.

warnbool

If True, warn if the number of samples is larger than the number of features, and if the kernel is linear.

Examples

>>> from himalaya.ridge import KernelRidgeCV
>>> import numpy as np
>>> n_samples, n_features, n_targets = 10, 5, 3
>>> X = np.random.randn(n_samples, n_features)
>>> Y = np.random.randn(n_samples, n_targets)
>>> clf = KernelRidgeCV()
>>> clf.fit(X, Y)
KernelRidgeCV()
Attributes
dual_coef_array of shape (n_samples) or (n_samples, n_targets)

Representation of weight vectors in kernel space.

best_alphas_array of shape (n_targets, )

Selected best hyperparameter alphas.

cv_scores_array of shape (n_targets, )

Cross-validation scores averaged over splits, for the best alpha. By default, the scores are computed with l2_neg_loss (in ]-inf, 0]). The scoring function can be changed with solver_params[“score_func”].

X_fit_array of shape (n_samples, n_features)

Training data. If kernel == “precomputed” this is None.

n_features_in_int

Number of features (or number of samples if kernel == “precomputed”) used during the fit.

Methods

fit(X[, y, sample_weight])

Fit kernel ridge regression model

get_params([deep])

Get parameters for this estimator.

get_primal_coef([X_fit])

Returns the primal coefficients, assuming the kernel is linear.

predict(X)

Predict using the model.

score(X, y)

Return the coefficient of determination R^2 of the prediction.

set_params(**params)

Set the parameters of this estimator.