Skip to content

IterativeImputer automatically removes variables with all missing values #16977

Closed

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)

Activity

  1. rth commented on Apr 21, 2020

    @rth
    Member

    Thanks for the feedback @mabdelhack ! See the discussion in #16426. Once the corresponding PR is merged, we can make one for IterativeImputer.

  2. rth commented on Apr 21, 2020

    @rth
    Member

    Once the corresponding PR is merged, we can make one for IterativeImputer.

    No actually the corresponding PR #16695 already include a fix for IterativeImputer

  3. mabdelhack commented on Apr 22, 2020

    @mabdelhack
    Author

    Thanks a lot for the response. I'll wait for the new version, and meanwhile I'll preprocess my matrix to make sure it passes unscathed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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