KernelRidgeRegression<T>

Models & Types · AiDotNet.Regression

Implements Kernel Ridge Regression, a powerful nonlinear regression technique that combines ridge regression with the kernel trick to capture complex nonlinear relationships.

Inheritance: NonLinearRegressionBase<T> → KernelRidgeRegression<T>

For Beginners

Kernel Ridge Regression is like using a special lens that helps see complex patterns in your data.

Regular linear models can only fit straight lines to data, but many real-world relationships aren’t straight. Kernel Ridge Regression solves this by:

  • Using “kernels” to transform your data into a format where complex relationships become simpler
  • Finding patterns in this transformed space
  • Adding “ridge” regularization to prevent the model from becoming too complex or overfitting

Think of it like this: If you tried to separate red and blue dots on a sheet of paper with a single line, sometimes it’s impossible. But if you could lift some dots off the page (into 3D space), you might be able to separate them with a flat plane. Kernels do something similar - they transform your data so that complex patterns become easier to find.

This technique is particularly good for:

  • Medium-sized datasets with complex relationships
  • Problems where the relationship between inputs and outputs is highly nonlinear
  • When you need both good prediction accuracy and the ability to adjust how much the model fits to noise

How It Works

Kernel Ridge Regression extends linear ridge regression by applying the “kernel trick” to implicitly map the input features to a higher-dimensional space without explicitly computing the transformation. This allows the model to capture complex nonlinear relationships while still maintaining the computational efficiency of ridge regression. The regularization parameter (lambda) helps prevent overfitting by penalizing large coefficients.

Example

using AiDotNet;
using AiDotNet.Data.Loaders;
using AiDotNet.Regression;
using AiDotNet.Tensors.LinearAlgebra;

double[][] features =
{
    new[] { 1.0, 2.0 }, new[] { 2.0, 3.0 }, new[] { 3.0, 4.0 },
    new[] { 4.0, 5.0 }, new[] { 5.0, 6.0 }, new[] { 6.0, 7.0 }
};
double[] targets = { 3.0, 5.0, 7.0, 9.0, 11.0, 13.0 };

var result = await new AiModelBuilder<double, Matrix<double>, Vector<double>>()
    .ConfigureModel(new KernelRidgeRegression<double>())
    .ConfigureDataLoader(DataLoaders.FromArrays(features, targets))
    .BuildAsync();

Console.WriteLine("Trained KernelRidgeRegression.");

Constructors

Constructor Summary
KernelRidgeRegression() Initializes a new instance with default settings.
KernelRidgeRegression(KernelRidgeRegressionOptions options, IRegularization<T, Matrix<T>, Vector<T>> regularization) Initializes a new instance of the KernelRidgeRegression class.

Properties

Property Summary
bool SupportsParameterInitialization { get; } KRR doesn’t benefit from optimizer parameter injection.

Methods

Method Summary
ModelMetadata<T> GetModelMetadata() Gets metadata about the Kernel Ridge Regression model and its configuration.