Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Scikit learn Scikit learn KernelRidge

From Leeroopedia


Knowledge Sources
Domains Machine Learning, Regression
Last Updated 2026-02-08 15:00 GMT

Overview

Concrete tool for performing kernel ridge regression combining ridge regression with the kernel trick, provided by scikit-learn.

Description

The KernelRidge class combines ridge regression (linear least squares with L2-norm regularization) with the kernel trick. It learns a linear function in the kernel-induced feature space, which corresponds to a non-linear function in the original space for non-linear kernels. Unlike SVR, KRR uses squared error loss and can be solved in closed form. It supports multi-variate regression when y is a 2D array.

Usage

Use this estimator when you need non-linear regression with a closed-form solution. It is typically faster than SVR for medium-sized datasets but produces a non-sparse model, making it slower at prediction time.

Code Reference

Source Location

Signature

class KernelRidge(MultiOutputMixin, RegressorMixin, BaseEstimator):
    def __init__(
        self,
        alpha=1.0,
        *,
        kernel="linear",
        gamma=None,
        degree=3,
        coef0=1,
    ):

Import

from sklearn.kernel_ridge import KernelRidge

I/O Contract

Inputs

Name Type Required Description
alpha float or array-like No Regularization strength (default 1.0)
kernel str or callable No Kernel mapping: 'linear', 'poly', 'rbf', etc. (default 'linear')
gamma float or None No Kernel coefficient for rbf, laplacian, polynomial, sigmoid (default None)
degree int No Degree of the polynomial kernel (default 3)
coef0 float No Independent term in polynomial and sigmoid kernels (default 1)

Outputs

Name Type Description
dual_coef_ ndarray of shape (n_samples,) or (n_samples, n_targets) Representation of weight vector in kernel space
X_fit_ ndarray of shape (n_samples, n_features) Training data used in fitting

Usage Examples

Basic Usage

from sklearn.kernel_ridge import KernelRidge
import numpy as np

X = np.array([[1, 1], [2, 2], [3, 3]])
y = np.array([1, 2, 3])
krr = KernelRidge(alpha=1.0, kernel="rbf", gamma=0.1)
krr.fit(X, y)
print(krr.predict([[1.5, 1.5]]))

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment