【问题标题】:How to avoid overfitting with imbalanced data?如何避免过度拟合不平衡的数据?
【发布时间】:2019-12-11 03:20:03
【问题描述】:

我正在研究用于二进制分类的分类器。数据不平衡,第 0 类为 83.41%,第 1 类为 16.59%。我正在使用 Mathews 相关系数来评估分类器的性能。另请注意,维度 ((211, 800)) 的数据相当少。

我正在使用逻辑回归来解决问题。我使用 GridSearchCV 进行超参数优化,并得出以下最佳超参数值:

最佳参数:{'C': 1000, 'class_weight': {1: 0.83, 0: 0.17000000000000004}, 'penalty': 'l1', 'solver': 'liblinear'}

最佳 MCC 0.7045053547679334

我在一系列 C 值上绘制了验证曲线,以检查模型是否过拟合/欠拟合。

train_scores, test_scores = validation_curve(LogisticRegression(penalty='l1',
                                                                solver='liblinear',
                                                                class_weight={1: 0.83, 0: 0.17000000000000004}),
                                             X, y,'C', C, cv=5, scoring=make_scorer(matthews_corrcoef))
train_scores_mean = np.mean(train_scores, axis=1)
train_scores_std = np.std(train_scores, axis=1)
test_scores_mean = np.mean(test_scores, axis=1)
test_scores_std = np.std(test_scores, axis=1)

plt.title("Validation Curve with Logistic Regression")
plt.xlabel("C")
plt.ylabel("MCC")
plt.ylim(0.0, 1.1)
lw = 2
plt.semilogx(C, train_scores_mean, label="Training score",
             color="darkorange", lw=lw)
plt.fill_between(C, train_scores_mean - train_scores_std,
                 train_scores_mean + train_scores_std, alpha=0.2,
                 color="darkorange", lw=lw)
plt.semilogx(C, test_scores_mean, label="Cross-validation score",
             color="navy", lw=lw)
plt.fill_between(C, test_scores_mean - test_scores_std,
                 test_scores_mean + test_scores_std, alpha=0.2,
                 color="navy", lw=lw)
plt.legend(loc="best")
plt.show()

根据我对这条曲线的理解,它表明该模型倾向于过度拟合,因为它在验证集上的表现较低而在训练集上的表现较高。谁能指出我如何在如此小的数据集上解决这个问题的方向。

【问题讨论】:

标签: python-3.x scikit-learn


【解决方案1】:

你可以做很多事情:

  1. 使用SMOTE 对少数类进行过采样。
  2. 减少 GridSearchCV 的迭代次数或使用 RandomSearchCV。

【讨论】:

  • 因为在 SMOTE 之后,类最终会平衡,我应该仍然使用 MCC 还是切换到任何其他指标?
  • 你可以使用ROC AUC
猜你喜欢
  • 2019-12-15
  • 2017-01-09
  • 2018-01-03
  • 1970-01-01
  • 2020-03-01
  • 2020-06-24
  • 1970-01-01
  • 2020-05-20
  • 2021-07-23
相关资源
最近更新 更多