Table of Contents

Class InteractionFeatures<T>

Namespace
AiDotNet.Preprocessing.FeatureGeneration
Assembly
AiDotNet.dll

Generates pairwise interaction features between input features.

public class InteractionFeatures<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>>
InteractionFeatures<T>
Implements
IDataTransformer<T, Matrix<T>, Matrix<T>>
Inherited Members

Remarks

InteractionFeatures creates new features by multiplying pairs of existing features. Unlike PolynomialFeatures with degree=2, this only produces interaction terms, not squared terms.

For features [a, b, c], this produces: [ab, ac, bc]

For Beginners: Interaction features capture combined effects: - If both "age" and "income" matter together (not just separately) - Creating age × income might help the model - This is simpler than full polynomial features (no squared terms)

Constructors

InteractionFeatures(bool, InteractionType, int[]?)

Creates a new instance of InteractionFeatures<T>.

public InteractionFeatures(bool includeOriginal = true, InteractionType interactionType = InteractionType.Pairwise, int[]? columnIndices = null)

Parameters

includeOriginal bool

Whether to include original features in output. Defaults to true.

interactionType InteractionType

Type of interactions to generate. Defaults to Pairwise.

columnIndices int[]

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

Properties

IncludeOriginal

Gets whether original features are included in output.

public bool IncludeOriginal { get; }

Property Value

bool

InteractionPairs

Gets the interaction pairs (feature indices).

public List<(int, int)>? InteractionPairs { get; }

Property Value

List<(int, int)>

InteractionType

Gets the type of interactions generated.

public InteractionType InteractionType { get; }

Property Value

InteractionType

NOutputFeatures

Gets the number of output features.

public int NOutputFeatures { get; }

Property Value

int

SupportsInverseTransform

Gets whether this transformer supports inverse transformation.

public override bool SupportsInverseTransform { get; }

Property Value

bool

Methods

FitCore(Matrix<T>)

Fits the transformer by computing interaction pairs.

protected override void FitCore(Matrix<T> data)

Parameters

data Matrix<T>

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.

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

Parameters

data Matrix<T>

Returns

Matrix<T>

TransformCore(Matrix<T>)

Transforms data by generating interaction features.

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

Parameters

data Matrix<T>

Returns

Matrix<T>