Scikit-learn: ImportError sklearn.impute.IterativeImputer

Created on 3 Apr 2020  路  1Comment  路  Source: scikit-learn/scikit-learn

Describe the bug

Hey,
apparently upon calling from sklearn.impute import IterativeImputer an ImportError is thrown. I set up a fresh conda environment but the problem persists. Had to update /sklearn/impute/__init__.py and was just wondering if that was intended. According to the patch notes IterativeImputer should still be included.

Steps/Code to Reproduce

conda create -n sklearn_test python=3.7
conda activate sklearn_test
pip install scikit-learn
python
from sklearn.impute import IterativeImputer

Error

ImportError: cannot import name 'IterativeImputer' from 'sklearn.impute' (/Users/schidani/anaconda3/envs/sklearn_test/lib/python3.7/site-packages/sklearn/impute/__init__.py)

with /sklearn/impute/__init__.py content:

"""Transformers for missing value imputation"""  

from ._base import MissingIndicator, SimpleImputer
from ._knn import KNNImputer

__all__ = [
    'MissingIndicator', 
    'SimpleImputer',
    'KNNImputer' 
]

Solution

Adapted /sklearn/impute/__init__.py content:

"""Transformers for missing value imputation"""  

from ._base import MissingIndicator, SimpleImputer
from ._knn import KNNImputer
from ._iterative import IterativeImputer

__all__ = [
    'MissingIndicator', 
    'SimpleImputer',
    'KNNImputer', 
    'IterativeImputer'
]

Versions

conda==4.8.1
python==3.7.7
sklearn==0.22.2.post1

Cheers,
dsethz

triage

Most helpful comment

It is explicitly written in the documentation of sklearn.impute.IterativeImputer that you need to enable the import because this estimator is still experimental:

>>> # explicitly require this experimental feature
>>> from sklearn.experimental import enable_iterative_imputer  # noqa
>>> # now you can import normally from sklearn.impute
>>> from sklearn.impute import IterativeImputer

Hope this answers your question :)

>All comments

It is explicitly written in the documentation of sklearn.impute.IterativeImputer that you need to enable the import because this estimator is still experimental:

>>> # explicitly require this experimental feature
>>> from sklearn.experimental import enable_iterative_imputer  # noqa
>>> # now you can import normally from sklearn.impute
>>> from sklearn.impute import IterativeImputer

Hope this answers your question :)

Was this page helpful?
0 / 5 - 0 ratings