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
TThe numeric type for calculations (e.g., float, double).
- Inheritance
-
SplineTransformer<T>
- Implements
- 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
nKnotsintNumber of internal knots. Defaults to 5.
degreeintDegree of the spline (1=linear, 2=quadratic, 3=cubic). Defaults to 3.
knotStrategySplineKnotStrategyStrategy for placing knots. Defaults to Uniform.
includeInterceptboolWhether to include the intercept (first basis function). Defaults to true.
extrapolationSplineExtrapolationHow to handle values outside the knot range. Defaults to Constant.
columnIndicesint[]The column indices to transform, or null for all columns.
Properties
Degree
Gets the degree of the spline.
public int Degree { get; }
Property Value
Extrapolation
Gets the extrapolation strategy.
public SplineExtrapolation Extrapolation { get; }
Property Value
IncludeIntercept
Gets whether the intercept term is included.
public bool IncludeIntercept { get; }
Property Value
KnotStrategy
Gets the knot placement strategy.
public SplineKnotStrategy KnotStrategy { get; }
Property Value
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
SupportsInverseTransform
Gets whether this transformer supports inverse transformation.
public override bool SupportsInverseTransform { get; }
Property Value
Methods
FitCore(Matrix<T>)
Computes the knot positions for each feature.
protected override void FitCore(Matrix<T> data)
Parameters
dataMatrix<T>The training data matrix.
GetFeatureNamesOut(string[]?)
Gets the output feature names after transformation.
public override string[] GetFeatureNamesOut(string[]? inputFeatureNames = null)
Parameters
inputFeatureNamesstring[]
Returns
- string[]
InverseTransformCore(Matrix<T>)
Inverse transformation is not supported for spline basis functions.
protected override Matrix<T> InverseTransformCore(Matrix<T> data)
Parameters
dataMatrix<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
dataMatrix<T>The data to transform.
Returns
- Matrix<T>
The B-spline basis features.