Skip to content

IterativeImputer automatically removes variables with all missing values #16977

@mabdelhack

Description

@mabdelhack

IterativeImputer seems to have a strange behavior where a variable with all missing values is just removed from the data decreasing the number of columns in the matrix without setting off any warnings. This appears to happen at the initial imputation step.
I know I should not give it a variable without any useful values but in the course of a large code it makes no sense that if there is such an error in the data, the code would stop for such an error. I think it should give the option to fill such values with certain value or even return the column with Nan so I can do whatever intervention needed.

Code example:
import numpy as np
from sklearn.experimental import enable_iterative_imputer
from sklearn.impute import IterativeImputer

X = \
[[ np.nan, np.nan, np.nan, np.nan, -1.41260556 ],
[ np.nan, np.nan, 0.70710678, 0.70710678, np.nan],
[ np.nan, np.nan, np.nan, np. nan, np.nan ]]
X = np.asarray(X)
print(X.shape)
solver = IterativeImputer()
X_imputed = solver.fit_transform(X)
print(X_imputed.shape)

Output:
(3,5)
(3,3)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions