sklearn分类器 - 最大化auc的predict_proba阈值

问题描述 投票:0回答:1

我有一个三级分类问题。我训练分类器,然后为不同的类绘制ROC。

enter image description here

我需要获得每个类的阈值,以最大化TPR并最小化FPR。在Matlab中,这是返回的。有没有办法在python / sklearn中检索它?

谢谢。

python machine-learning scikit-learn classification roc
1个回答
1
投票

所以我的想法看起来像这样:

import numpy as np
idx = np.linalg.norm(
    (np.array([[0, 1]]) -np.stack([fpr, tpr], axis=1)), 
    axis=1).argmax()
max_thresh = thresholds[idx]

这里做了什么:将FPR和TPR一起堆叠为2D矢量。减去向量的每一行的左上角并采用标准。这计算距离。拿argmax知道最大值出现在哪一行。最后,返回该索引的阈值

© www.soinside.com 2019 - 2024. All rights reserved.