[英]sklearn classifier - predict_proba threshold that maximizes auc
I have a three-class classification problem. 我有一个三类分类问题。 I train the classifier and then plot the ROC for the different classes.
我训练分类器,然后为不同类别绘制ROC。
I need to get the threshold for each class which maximizes the TPR and minimizes the FPR. 我需要获取每个类的阈值,以最大化TPR和最小化FPR。 In Matlab, this is returned.
在Matlab中,将返回此值。 Is there a way to retrieve this in python / sklearn?
有没有办法在python / sklearn中检索到它?
Thanks. 谢谢。
So my idea looks like this: 所以我的想法看起来像这样:
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]
what is done here: stack the FPR and TPR together as a 2D-vector. 在这里完成的操作:将FPR和TPR堆叠为2D向量。 subtract the upper left corner of each row of the vector and take the norm.
减去向量每一行的左上角并采用范数。 This computes the distance.
这将计算距离。 Take the argmax to know in which row the maximum value appears.
使用argmax可以知道最大值出现在哪一行。 Finally, return the threshold at that index
最后,返回该索引处的阈值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.