模型评估:类别不平衡的分类模型

用 Python 练习机器学习面试题

Lisa Stuart

Data Scientist

类别不平衡

  • 分类目标变量
    • 各类别样本数大致相等
    • 差异过大会导致结果偏差

不平衡 vs 平衡类别

用 Python 练习机器学习面试题

混淆矩阵

混淆矩阵

1 https://scaryscientist.blogspot.com/2016/03/confusion-matrix.html
用 Python 练习机器学习面试题

性能指标

性能指标

1 https://scaryscientist.blogspot.com/2016/03/confusion-matrix.html
用 Python 练习机器学习面试题

由矩阵得出的指标

性能指标

1 https://scaryscientist.blogspot.com/2016/03/confusion-matrix.html
用 Python 练习机器学习面试题

重采样技术

  • 对少数类过采样
  • 对多数类欠采样
  • 注意:在重采样前先划分训练/测试集!

重采样技术

1 https://www.svds.com/learning-imbalanced-classes/
用 Python 练习机器学习面试题

函数

函数 返回
sklearn.linear_model.LogisticRegression 逻辑回归
sklearn.metrics.confusion_matrix(y_test,y_pred) 混淆矩阵
sklearn.metrics.precision_score(y_test,y_pred) 精确率
sklearn.metrics.recall_score(y_test,y_pred) 召回率
sklearn.metrics.f1_score(y_test,y_pred) F1 分数
sklearn.utils.resample(deny, n_samples=len(approve)) 重采样
用 Python 练习机器学习面试题

Passons à la pratique !

用 Python 练习机器学习面试题

Preparing Video For Download...