'sklearn model_selection Error: ImportError: cannot import name '_approximate_mode'

I'm trying to import sklearn model_selection but I'm getting the following error:

ImportError                               Traceback (most recent call last)
<ipython-input-219-6bc6f0a77ca9> in <module>()
----> 1 import sklearn.model_selection

~/anaconda3/lib/python3.6/site-packages/sklearn/model_selection/__init__.py in <module>()
----> 1 from ._split import BaseCrossValidator
      2 from ._split import KFold
      3 from ._split import GroupKFold
      4 from ._split import StratifiedKFold
      5 from ._split import TimeSeriesSplit

~/anaconda3/lib/python3.6/site-packages/sklearn/model_selection/_split.py in <module>()
     21 
     22 from ..utils import indexable, check_random_state, safe_indexing
---> 23 from ..utils import _approximate_mode
     24 from ..utils.validation import _num_samples, column_or_1d
     25 from ..utils.validation import check_array

ImportError: cannot import name '_approximate_mode'

I tried uninstalling scikit-learn and reinstalling it but I get the same error. My current version of scikit-learn is 0.21.2. Thanks for the help!



Solution 1:[1]

I shutdown the kernel and restarted it again. Now it's working fine! Thanks!!

Solution 2:[2]

You are using python notebook. I found that error once when I have installed the package before importing. I have tested this at Google AI notebook and worked well.

Save the notebook -> shutdown the kernel -> close and open the notebook again.

Solution 3:[3]

You can restart the kernel or use the importlib library

from importlib import reload
sklearn= reload(sklearn)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Harshana Sridhar
Solution 2 Partha Sen
Solution 3 welowis