【发布时间】:2019-08-30 15:27:09
【问题描述】:
我有一个高度不平衡的数据集,并希望执行 SMOTE 以平衡数据集并执行交叉验证以测量准确性。但是,大多数现有教程仅使用单个 training 和 testing 迭代来执行 SMOTE。
因此,我想知道使用交叉验证执行 SMOTE 的正确程序。
我当前的代码如下。但是,如上所述,它只使用单次迭代。
from imblearn.over_sampling import SMOTE
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
sm = SMOTE(random_state=2)
X_train_res, y_train_res = sm.fit_sample(X_train, y_train.ravel())
clf_rf = RandomForestClassifier(n_estimators=25, random_state=12)
clf_rf.fit(x_train_res, y_train_res)
如果需要,我很乐意提供更多详细信息。
【问题讨论】:
标签: python machine-learning scikit-learn classification cross-validation