Python: ‘SMOTE’ object has no attribute ‘_validate_data’ 如何解决???求大神
代码如下:
#过采样算法
import pandas as pd
from imblearn.over_sampling import SMOTE
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import confusion_matrix
from sklearn.model_selection import train_test_split
columns=data.columns
X_columns=columns.delete(len(columns)-1)
X=data.drop([‘target’],axis=1)
y=data[‘target’]
X_train,X_test,y_train,y_test=train_test_split(X,
y,
test_size=0.2,
random_state=0)
oversample=SMOTE(random_state=0)
X_os,y_os=oversample.fit_resample(X_train,y_train)
执行后:
AttributeError Traceback (most recent call last)
in ()
1 oversample=SMOTE(random_state=0)
----> 2 X_os,y_os=oversample.fit_resample(X_train,y_train)
~\Anaconda3\lib\site-packages\imblearn\base.py in fit_resample(self, X, y)
75 check_classification_targets(y)
76 arrays_transformer = ArraysTransformer(X, y)
—> 77 X, y, binarize_y = self.check_X_y(X, y)
78
79 self.sampling_strategy = check_sampling_strategy(
~\Anaconda3\lib\site-packages\imblearn\base.py in _check_X_y(self, X, y, accept_sparse)
132 accept_sparse = [“csr”, “csc”]
133 y, binarize_y = check_target_type(y, indicate_one_vs_all=True)
–> 134 X, y = self._validate_data(
135 X, y, reset=True, accept_sparse=accept_sparse
136 )
AttributeError: ‘SMOTE’ object has no attribute ‘_validate_data’