相关疑难解决方法(0)

如何在sklearn中使用交叉验证执行SMOTE

我有一个高度不平衡的数据集,并希望执行SMOTE来平衡数据集并进行交叉验证以测量准确性。但是,大多数现有教程仅利用单次trainingtesting迭代来执行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)
Run Code Online (Sandbox Code Playgroud)

如果需要,我很乐意提供更多详细信息。

python classification machine-learning scikit-learn cross-validation

2
推荐指数
2
解决办法
1298
查看次数