Table of Contents

Class SplineTransformer<T>

Namespace
AiDotNet.Preprocessing.FeatureGeneration
Assembly
AiDotNet.dll

Generates B-spline basis functions for features.

public class SplineTransformer<T> : TransformerBase<T, Matrix<T>, Matrix<T>>, IDataTransformer<T, Matrix<T>, Matrix<T>>

Type Parameters

T

The numeric type for calculations (e.g., float, double).

Inheritance
TransformerBase<T, Matrix<T>, Matrix<T>>
SplineTransformer<T>
Implements
IDataTransformer<T, Matrix<T>, Matrix<T>>
Inherited Members

Remarks

SplineTransformer creates B-spline basis functions from input features. B-splines are piecewise polynomials that provide a flexible way to model non-linear relationships while maintaining smoothness.

The knots can be placed uniformly across the feature range or at quantile positions to ensure roughly equal numbers of samples between knots.

For Beginners: B-splines let your model capture curved (non-linear) patterns: - Linear models only find straight-line relationships - Splines create multiple smooth curves that join at "knots" - Each input feature becomes multiple features representing different curve segments

Example: Age effect on income might be curved (rises until 50, then plateaus). Splines capture this without needing polynomial features.

Constructors

SplineTransformer(int, int, SplineKnotStrategy, bool, SplineExtrapolation, int[]?)

Creates a new instance of SplineTransformer<T>.

public SplineTransformer(int nKnots = 5, int degree = 3, SplineKnotStrategy knotStrategy = SplineKnotStrategy.Uniform, bool includeIntercept = true, SplineExtrapolation extrapolation = SplineExtrapolation.Constant, int[]? columnIndices = null)

Parameters

nKnots int

Number of internal knots. Defaults to 5.

degree int

Degree of the spline (1=linear, 2=quadratic, 3=cubic). Defaults to 3.

knotStrategy SplineKnotStrategy

Strategy for placing knots. Defaults to Uniform.

includeIntercept bool

Whether to include the intercept (first basis function). Defaults to true.

extrapolation SplineExtrapolation

How to handle values outside the knot range. Defaults to Constant.

columnIndices int[]

The column indices to transform, or null for all columns.

Properties

Degree

Gets the degree of the spline.

public int Degree { get; }

Property Value

int

Extrapolation

Gets the extrapolation strategy.

public SplineExtrapolation Extrapolation { get; }

Property Value

SplineExtrapolation

IncludeIntercept

Gets whether the intercept term is included.

public bool IncludeIntercept { get; }

Property Value

bool

KnotStrategy

Gets the knot placement strategy.

public SplineKnotStrategy KnotStrategy { get; }

Property Value

SplineKnotStrategy

Knots

Gets the fitted knots for each feature.

public double[][]? Knots { get; }

Property Value

double[][]

NKnots

Gets the number of internal knots.

public int NKnots { get; }

Property Value

int

SupportsInverseTransform

Gets whether this transformer supports inverse transformation.

public override bool SupportsInverseTransform { get; }

Property Value

bool

Methods

FitCore(Matrix<T>)

Computes the knot positions for each feature.

protected override void FitCore(Matrix<T> data)

Parameters

data Matrix<T>

The training data matrix.

GetFeatureNamesOut(string[]?)

Gets the output feature names after transformation.

public override string[] GetFeatureNamesOut(string[]? inputFeatureNames = null)

Parameters

inputFeatureNames string[]

Returns

string[]

InverseTransformCore(Matrix<T>)

Inverse transformation is not supported for spline basis functions.

protected override Matrix<T> InverseTransformCore(Matrix<T> data)

Parameters

data Matrix<T>

Returns

Matrix<T>

TransformCore(Matrix<T>)

Transforms the data by computing B-spline basis values.

protected override Matrix<T> TransformCore(Matrix<T> data)

Parameters

data Matrix<T>

The data to transform.

Returns

Matrix<T>

The B-spline basis features.