ImportError: cannot import name '_deprecate_positional_args' from 'sklearn.utils.validation'

Viewed 5912

when I try to import deprecate_positional_args fuction from sklearn.utils.validation' I got this import error:

ImportError: cannot import name '_deprecate_positional_args' from 'sklearn.utils.validation'

The scikit-learn version is 0.21.3

4 Answers

I was facing the same error when running in a Jupyter environment. Was resolved by installing imbalanced-learn by running !pip install -U imbalanced-learn and then restarting the runtime. Restarting the runtime is the key here. If you don't restart, the error won't go.

I solved this problem by upgrading scikit-learn:

pip install --upgrade scikit-learn

This is caused by a mismatch between the scikit-learn versions with which you train the model and load the model. Check your scikit-learn versions with sklearn.__version__ and up/downgrade one of the packages with pip install --upgrade scikit-learn==<version_number>.

I think that some of the answers here will work provided that you're working with Python 3.7 or a newer version. I couldn't upgrade to a newer Python version due to workplace restrictions and what worked for me was downgrading to scikit-learn 0.23.

You can do it via the command

pip install scikit-learn==0.23

Or, if you're using Jupyter Notebook:

import sys
!{sys.executable} -m pip install scikit-learn==0.23
Related