Table of Contents

Class IterativeImputer<T>

Namespace
AiDotNet.Preprocessing.Imputers
Assembly
AiDotNet.dll

Iterative imputer using the MICE algorithm (Multiple Imputation by Chained Equations).

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

Remarks

IterativeImputer imputes missing values by modeling each feature with missing values as a function of other features, iterating multiple times until convergence.

The algorithm: 1. Initial imputation (mean/median for each feature) 2. For each feature with missing values: - Train a regression model using other features as predictors - Predict missing values using the trained model 3. Repeat step 2 for multiple iterations until convergence

For Beginners: MICE creates multiple "guesses" for missing values by learning relationships between features. If taller people tend to be heavier, MICE can use height to predict missing weight values more accurately than simply using the average weight.

Constructors

IterativeImputer(int, double, IterativeImputerEstimator, IterativeImputerInitialStrategy, int, int[]?)

Creates a new instance of IterativeImputer<T>.

public IterativeImputer(int maxIterations = 10, double tolerance = 0.001, IterativeImputerEstimator estimator = IterativeImputerEstimator.BayesianRidge, IterativeImputerInitialStrategy initialStrategy = IterativeImputerInitialStrategy.Mean, int randomState = 0, int[]? columnIndices = null)

Parameters

maxIterations int

Maximum number of imputation iterations. Defaults to 10.

tolerance double

Convergence tolerance. Defaults to 1e-3.

estimator IterativeImputerEstimator

The estimator to use for imputation. Defaults to BayesianRidge.

initialStrategy IterativeImputerInitialStrategy

Initial imputation strategy. Defaults to Mean.

randomState int

Random seed for reproducibility. Defaults to 0.

columnIndices int[]

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

Properties

Estimator

Gets the estimator type used for imputation.

public IterativeImputerEstimator Estimator { get; }

Property Value

IterativeImputerEstimator

InitialStrategy

Gets the initial imputation strategy.

public IterativeImputerInitialStrategy InitialStrategy { get; }

Property Value

IterativeImputerInitialStrategy

MaxIterations

Gets the maximum number of iterations.

public int MaxIterations { get; }

Property Value

int

SupportsInverseTransform

Gets whether this transformer supports inverse transformation.

public override bool SupportsInverseTransform { get; }

Property Value

bool

Tolerance

Gets the convergence tolerance.

public double Tolerance { get; }

Property Value

double

Methods

FitCore(Matrix<T>)

Fits the imputer by learning the relationships between features.

protected override void FitCore(Matrix<T> data)

Parameters

data Matrix<T>

The training data with missing values (NaN).

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 the data by imputing missing values.

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

Parameters

data Matrix<T>

The data to transform.

Returns

Matrix<T>

The data with missing values imputed.