【问题标题】:Accuracy for each probability cutoff in a binary classification problem (python sklearn accuracy)二进制分类问题中每个概率截止的准确度(python sklearn 准确度)
【发布时间】:2020-05-13 02:37:57
【问题描述】:

想象一个二元分类问题。假设我有 800,000 个预测概率存储在 pred_test 中。我将cutoff 定义为pred_test 中的任何值,这样大于或等于cutoff 的值被分配值1,而小于cutoff 的值被分配值0。

sklearn 中是否有一个函数可以返回 pred_train 中每个 cutoff 的模型精度?我希望将模型的准确性作为每个截止值的函数来系统地选择一个截止值。

我尝试了以下方法:

_list = []
for cutoff in np.unique(np.sort(pred_test)):
    binary_prediction = np.where(pred_test >= cutoff, 1, 0)
    _list.append( (cutoff, binary_prediction == y_test).sum() / len(pred_test) )

这里,y_test 是基本事实(一个包含 800,000 行中每一行的观察结果的数组)。此代码返回一个列表,其中每个值都包含截止值及其对应的准确度分数。

pred_test 对象有大约 600,000 个不同的值,所以我迭代了大约 600,000 次。上面的代码可以运行,但是需要很长时间才能完成。有没有更有效的方法来做到这一点?我敢打赌sklearn 已经有一个功能可以做到这一点。

【问题讨论】:

    标签: python scikit-learn classification


    【解决方案1】:

    这里有一些类似的线程来检查它:Getting the maximum accuracy for a binary probabilistic classifier in scikit-learn

    scikit-learn 中没有内置函数。我认为未实施的原因是您将有机会过度拟合,您基本上会将您的训练集调整到对测试集有风险的基线。

    【讨论】:

      猜你喜欢
      • 2018-09-22
      • 2018-03-03
      • 2015-10-07
      • 2021-10-18
      • 2018-10-01
      • 2020-01-10
      • 1970-01-01
      • 2019-02-01
      • 2019-09-06
      相关资源
      最近更新 更多