简体   繁体   English

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

[英]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.

相关问题 如何正确重塑sklearn分类器的predict_proba的多类output? - How to correctly reshape the multiclass output of predict_proba of a sklearn classifier? Sklearn -predict_proba等效项 - Sklearn - predict_proba equivalents 无法运行StackNet分类器的predict_proba - Unable to run predict_proba of StackNet Classifier 回归与分类器predict_proba - Regression vs Classifier predict_proba sklearn Forecast_proba没有Macthing类标签 - sklearn predict_proba not macthing class labels Keras 分类器 predict_proba() 与 predict() 不匹配 - Keras classifier predict_proba() doesn't match predict() 为什么 sklearn 的 permutation_test_score 返回的 ROC AUC 分数与我使用 predict_proba 和 roc_auc_score 手动计算时不同? - Why does sklearn's permutation_test_score return a different ROC AUC score than when I calculate manually using predict_proba and roc_auc_score? SciKit学习predict_proba-将阈值从0.5移至其他 - SciKit learn predict_proba - move threshold from .5 to something else predict_proba 不适用于我的高斯混合 model(sklearn,python) - predict_proba is not working for my gaussian mixture model (sklearn, python) sklearn的predict_proba返回无限概率 - sklearn's predict_proba returns infinite probabilties
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM