Kernel ridge regression (KRR) is a nonparametric regression method that applies ridge regression in a high-dimensional feature space defined implicitly by a kernel function, which lets it fit smooth nonlinear relationships while keeping a closed-form solution. In machine learning, and in artificial intelligence more broadly, it is a standard kernel method that sits between linear models and Gaussian processes.
The method minimizes squared error plus an L2 penalty on the function’s norm in a reproducing kernel Hilbert space. By the representer theorem, the optimal function is a weighted sum of kernels centered on the training points, so training reduces to solving one linear system of size n by n, where n is the number of training samples.
How kernel ridge regression works
Kernel ridge regression works by replacing every inner product in ordinary ridge regression with a kernel evaluation k(x, x’). The training data produce an n by n Gram matrix K, whose entries measure similarity between every pair of training points.
The dual coefficients are obtained from alpha = (K + lambda I)^-1 y, where lambda is the regularization strength and y is the vector of targets. A prediction for a new point x is then f(x) = sum_i alpha_i k(x_i, x), a weighted combination of similarities to all training samples. Adding lambda to the diagonal makes the matrix well conditioned and controls how closely the function follows the data.
Because the feature map is never computed explicitly, KRR can use kernels whose feature spaces are infinite-dimensional, such as the Gaussian radial basis function. This is the same kernel trick used by support vector machines and kernel PCA.
The table below lists the main elements of the model and their roles.
| Element | Notation | Role |
|---|---|---|
| Kernel function | k(x, x’) | Defines similarity and the function class |
| Gram matrix | K, size n by n | Pairwise similarities of training points |
| Regularization parameter | lambda | Balances fit against smoothness |
| Dual coefficients | alpha | Weights of each training point |
| Prediction | f(x) = k(x)^T alpha | Weighted sum of kernel similarities |
Choosing kernels and hyperparameters
The choice of kernel determines which functions KRR can represent, and the hyperparameters determine how flexible that representation is. The radial basis function kernel is the common default because it can approximate any continuous function given enough data.
| Kernel | Key parameter | Suitable for |
|---|---|---|
| Linear | None | Equivalent to ordinary ridge regression |
| Polynomial | Degree, offset | Feature interactions of known order |
| Gaussian RBF | Length scale or gamma | Smooth general nonlinear functions |
| Laplacian | Gamma | Functions with sharper local changes |
| Matern | Smoothness nu, length scale | Physical and spatial data |
Two hyperparameters usually matter most: lambda and the kernel width. A small lambda with a narrow kernel memorizes noise, while a large lambda with a wide kernel produces an almost flat function. Both are normally tuned together with k-fold cross-validation on a logarithmic grid, for example lambda from 1e-6 to 10. KRR also offers an efficient leave-one-out estimate computed from the same matrix inverse, which makes tuning cheaper than with many other models.
Because RBF and similar kernels depend on distances, feature scaling is essential. Unscaled inputs let one feature with a large numeric range dominate the similarity measure.
How KRR relates to neighboring methods
Kernel ridge regression shares its mathematical core with several better-known methods and differs from them mostly in loss function and interpretation. The predictive mean of a Gaussian process with noise variance equal to lambda is identical to the KRR prediction, but the Gaussian process also provides uncertainty estimates.
| Method | Loss function | Solution | Main difference |
|---|---|---|---|
| Kernel ridge regression | Squared error | Closed form | Dense coefficients, fast to tune |
| Ridge regression | Squared error | Closed form | Linear in the original features |
| Support vector regression | Epsilon-insensitive | Quadratic program | Sparse support vectors, robust to outliers |
| Gaussian process regression | Gaussian likelihood | Closed form | Adds predictive variance |
| Gradient boosting | Configurable | Iterative trees | Scales to large tabular data |
Compared with support vector regression, KRR usually trains faster on medium datasets because it needs one linear solve rather than an optimization, but it predicts more slowly, since every training point contributes to every prediction.
Computational cost and scaling
The main practical constraint of KRR is its cubic training cost in the number of samples. Solving the n by n system takes on the order of n cubed operations and storing the Gram matrix requires n squared memory, so exact KRR becomes impractical beyond roughly tens of thousands of samples on a typical workstation.
Several approximations reduce this cost while keeping most of the accuracy, as the following table shows.
| Strategy | Idea | Approximate cost |
|---|---|---|
| Exact solve | Cholesky factorization of K plus lambda I | n cubed time, n squared memory |
| Nystrom approximation | Low-rank kernel from m landmark points | n times m squared |
| Random Fourier features | Explicit random feature map | n times D squared |
| Iterative solvers | Conjugate gradient with preconditioning | Several passes over K |
| Divide and conquer | Average models trained on data subsets | Depends on partition count |
Limitations and common mistakes
Beyond cost, KRR has several practical weaknesses that experienced practitioners plan for. The squared loss makes it sensitive to outliers, the model is hard to interpret beyond inspecting kernel similarities, and the plain version gives no uncertainty estimate.
- Skipping feature scaling, which distorts distance-based kernels.
- Tuning lambda and kernel width separately instead of jointly.
- Extrapolating far from the training data, where RBF predictions decay toward the mean.
- Ignoring numerical conditioning when lambda is very small, which causes unstable coefficients.
In plain words
Kernel ridge regression predicts a number for a new case by looking at similar past cases. Each past case gets a weight. The prediction is a weighted mix of what happened before.
A kernel is simply a rule for measuring how similar two cases are. The ridge part keeps the weights modest. This stops the model from chasing every random bump in the data. The result is a smooth curve that follows the real pattern, even when that pattern is curved rather than straight.
A real-world example
A materials research group wants to predict the formation energy of new alloys from a set of composition and structure descriptors. Each laboratory or simulation result is expensive, so the team has only about 3,000 labeled compounds. They standardize the descriptors, choose a Gaussian RBF kernel, and tune lambda and the kernel width with five-fold cross-validation on a logarithmic grid.
Training takes a few seconds, and the tuned model predicts formation energy with errors small enough to rank candidate alloys before running costly simulations. The researchers use the model to screen thousands of hypothetical compositions and send only the most promising few dozen to full simulation. The screening step cuts simulation time substantially, and because the data set is small, the cubic cost of exact KRR never becomes a problem.