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
TThe numeric type for calculations (e.g., float, double).
- Inheritance
-
IterativeImputer<T>
- Implements
- 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
maxIterationsintMaximum number of imputation iterations. Defaults to 10.
tolerancedoubleConvergence tolerance. Defaults to 1e-3.
estimatorIterativeImputerEstimatorThe estimator to use for imputation. Defaults to BayesianRidge.
initialStrategyIterativeImputerInitialStrategyInitial imputation strategy. Defaults to Mean.
randomStateintRandom seed for reproducibility. Defaults to 0.
columnIndicesint[]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
InitialStrategy
Gets the initial imputation strategy.
public IterativeImputerInitialStrategy InitialStrategy { get; }
Property Value
MaxIterations
Gets the maximum number of iterations.
public int MaxIterations { get; }
Property Value
SupportsInverseTransform
Gets whether this transformer supports inverse transformation.
public override bool SupportsInverseTransform { get; }
Property Value
Tolerance
Gets the convergence tolerance.
public double Tolerance { get; }
Property Value
Methods
FitCore(Matrix<T>)
Fits the imputer by learning the relationships between features.
protected override void FitCore(Matrix<T> data)
Parameters
dataMatrix<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
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 the data by imputing missing values.
protected override Matrix<T> TransformCore(Matrix<T> data)
Parameters
dataMatrix<T>The data to transform.
Returns
- Matrix<T>
The data with missing values imputed.