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
TThe numeric type for calculations (e.g., float, double).
- Inheritance
-
InteractionFeatures<T>
- Implements
- 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
includeOriginalboolWhether to include original features in output. Defaults to true.
interactionTypeInteractionTypeType of interactions to generate. Defaults to Pairwise.
columnIndicesint[]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
InteractionPairs
Gets the interaction pairs (feature indices).
public List<(int, int)>? InteractionPairs { get; }
Property Value
InteractionType
Gets the type of interactions generated.
public InteractionType InteractionType { get; }
Property Value
NOutputFeatures
Gets the number of output features.
public int NOutputFeatures { get; }
Property Value
SupportsInverseTransform
Gets whether this transformer supports inverse transformation.
public override bool SupportsInverseTransform { get; }
Property Value
Methods
FitCore(Matrix<T>)
Fits the transformer by computing interaction pairs.
protected override void FitCore(Matrix<T> data)
Parameters
dataMatrix<T>
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.
protected override Matrix<T> InverseTransformCore(Matrix<T> data)
Parameters
dataMatrix<T>
Returns
- Matrix<T>
TransformCore(Matrix<T>)
Transforms data by generating interaction features.
protected override Matrix<T> TransformCore(Matrix<T> data)
Parameters
dataMatrix<T>
Returns
- Matrix<T>