To solve AttributeError: ‘SMOTE’ object has no attribute ‘_validate_data’ error follow below methods.
Code that causes this error :
sm = SMOTE(random_state=1)
X, Y = sm.fit_resample(X_train, Y_train)
ERROR LOG
AttributeError: 'SMOTE' object has no attribute '_validate_data'
Contents
How to solve AttributeError: ‘SMOTE’ object has no attribute ‘_validate_data’ ?
This error AttributeError: ‘SMOTE’ object has no attribute ‘_validate_data’ is caused due to lower versions of Scikit-learn and imbalanced learn sample. You need to upgrade scikit-learn
to version 0.23.1.
Detail Explanation :
The most recent version of imbalanced-learn 0.7.0, appears to contain an undocumented dependent on scikit-learn v0.23.1. If your scikit-learnis version is 0.22 or lower, you will receive the error AttributeError: ‘SMOTE’ object has no attribute ‘_validate data’.
Installing scikit-learn version 0.23.1 may be difficult if you are using Anaconda. conda update scikit-learn
may not update scikit-learn version 0.23 or higher since the most recent scikit-learn version Conda possesses is 0.22.1. If you try to install it with conda install scikit-learn=0.23.1
or pip install scikit-learn==0.23.1
, you will receive a slew of
compatibility warnings and the installation may take a while.
As a result, the simplest method to install scikit-learn version 0.23.1 in Anaconda is to construct a new virtual environment with minimal packages, resulting in fewer or no conflicts. Then, in the new virtual environment, install scikit-learn version 0.23.1, followed by imbalanced-learn version 0.7.0.
pip install scikit-learn==0.23.1
pip install imbalanced-learn==0.7.0
Alternative to Solve AttributeError: ‘SMOTE’ object has no attribute ‘_validate_data’
It is simple hack to solve this issue. Just open the Jupyter notebook ( if you are using anaconda ) and then run the below commands.
!pip install --upgrade scikit-learn
!pip install --upgrade imblearnsample code
Once you ran the above commands then restart your kernel. The error will be gone.
Hope the above solution works.
Also read :
Could not load dynamic library ‘cudnn64_8.dll’; dlerror: cudnn64_8.dll not found
AttributeError: ‘SMOTE’ object has no attribute ‘fit_sample’