Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Scikit learn Scikit learn IterativeImputer

From Leeroopedia


Knowledge Sources
Domains Machine Learning, Missing Data, Imputation
Last Updated 2026-02-08 15:00 GMT

Overview

Concrete implementation of multivariate iterative imputation for missing values provided by scikit-learn.

Description

The IterativeImputer class implements a strategy for imputing missing values by modeling each feature with missing values as a function of other features in a round-robin fashion. At each step, a feature is designated as output and the other features are treated as inputs. An estimator is fit on known values and used to predict missing ones. This process repeats for multiple iterations. The class is experimental and requires explicit import from sklearn.experimental.

Usage

Use IterativeImputer when you need sophisticated imputation that accounts for feature correlations, rather than simple mean/median imputation. It is particularly useful when missing data patterns are not completely at random (MCAR).

Code Reference

Source Location

Signature

class IterativeImputer(_BaseImputer):
    def __init__(
        self,
        estimator=None,
        *,
        missing_values=np.nan,
        sample_posterior=False,
        max_iter=10,
        tol=1e-3,
        n_nearest_features=None,
        initial_strategy="mean",
        fill_value=None,
        imputation_order="ascending",
        skip_complete=False,
        min_value=-np.inf,
        max_value=np.inf,
        verbose=0,
        random_state=None,
        add_indicator=False,
        keep_empty_features=False,
    ):
        ...

    def fit(self, X, y=None, **fit_params):
        ...

    def transform(self, X):
        ...

    def fit_transform(self, X, y=None, **fit_params):
        ...

Import

from sklearn.experimental import enable_iterative_imputer  # noqa
from sklearn.impute import IterativeImputer

I/O Contract

Inputs

Name Type Required Description
X array-like of shape (n_samples, n_features) Yes Data with missing values to impute
estimator estimator instance No Estimator to use for imputation (default: BayesianRidge)
max_iter int No Maximum number of imputation rounds (default: 10)
initial_strategy str No Strategy for initial imputation: "mean", "median", "most_frequent", "constant"
imputation_order str No Order of feature imputation: "ascending", "descending", "roman", "arabic", "random"
missing_values int, float, or np.nan No Placeholder for missing values

Outputs

Name Type Description
X_imputed ndarray of shape (n_samples, n_features) Data with missing values imputed
n_iter_ int Number of rounds of imputation performed

Usage Examples

Basic Usage

import numpy as np
from sklearn.experimental import enable_iterative_imputer  # noqa
from sklearn.impute import IterativeImputer

X = np.array([[1, 2], [np.nan, 3], [7, 6], [4, np.nan]])
imp = IterativeImputer(max_iter=10, random_state=42)
X_imputed = imp.fit_transform(X)
print(X_imputed)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment