如何将 SMOTE 重采样和特征选择集成到 RFECV 中

问题描述

我正在研究一个形状为 (41188,58) 的数据集来制作二元分类器。数据极不平衡。最初,我打算通过 RFECV 进行特征选择,这是我使用的从 here 借来的代码

# Create the RFE object and compute a cross-validated score.
svc = SVC(kernel="linear")

# The "accuracy" scoring is proportional to the number of correct classifications
min_features_to_select = 1  # Minimum number of features to consider
rfecv = RFECV(estimator=svc,step=1,cv=StratifiedKFold(5),scoring='accuracy',min_features_to_select=min_features_to_select)
rfecv.fit(X,y)

print("Optimal number of features : %d" % rfecv.n_features_)

# Plot number of features VS. cross-validation scores
plt.figure()
plt.plot(range(min_features_to_select,len(rfecv.grid_scores_) +
                  min_features_to_select),rfecv.grid_scores_)
plt.show()

我得到了以下结果:

enter image description here

然后我将代码更改为 cv=StratifiedKFold(2)min_features_to_select = 20,这次我得到了:

enter image description here

在上述情况下,均未进行重采样。由于重采样应该应用于训练数据,因此我在这里使用交叉验证,因此每个训练数据折叠也应该重新采样(例如 SMOTE)。我想知道如何将重采样和特征选择集成到 RFECV 中?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)