如何更改 sklearn 中任何学习算法的训练阈值?

How can I change the training threshold for any learning algorithm in sklearn?

我正在尝试使用 sklearn 训练模型,但是,我想将决策阈值更改为 训练 模型。我在 SO 中找到的大部分结果都是针对测试集的预测。

概率 class 训练器(通过 scikit-learn 或任何其他框架)不涉及 阈值。

在推理时需要一个阈值,以便将概率预测转换为硬标签,而这又是计算本质上 业务 指标所必需的,例如准确性,精度、召回率等。但这些指标在模型训练中发挥 没有 作用,其中唯一重要的数量(并在模型拟合期间最小化)是 loss.并且损失的计算不涉及任何阈值。

换句话说,硬 class 预测(仅需要阈值)在模型训练中完全没有作用,因此在训练期间不涉及任何阈值。

我建议阅读我的以下答案,以阐明损失和准确性之间的关系(尽管有标题,它们并不特定于 Keras,但它们原则上适用于任何二进制 class化问题):

也引用自交叉验证线程 Reduce Classification Probability Threshold:

the statistical component of your exercise ends when you output a probability for each class of your new sample. Choosing a threshold beyond which you classify a new observation as 1 vs. 0 is not part of the statistics any more. It is part of the decision component.