自定义 TensorFlow 指标:给定假阳性率下的真阳性率

编程入门 行业动态 更新时间:2024-10-09 16:24:06
本文介绍了自定义 TensorFlow 指标:给定假阳性率下的真阳性率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个二元分类问题,类别背景 (bg) = 0,信号 (sig) = 1,我正在为此训练 NN.出于监控目的,我正在尝试使用 TensorFlow 后端在 Keras 中实现自定义指标,该指标执行以下操作:

I have a binary classification problem with categories background (bg) = 0, signal (sig) = 1, for which I am training NNs. For monitoring purposes, I am trying to implement a custom metric in Keras with TensorFlow backend that does the following:

1) 计算我的 NN 输出的阈值,这将导致 X 的误报率(将 bg 分类为信号)(在这种情况下 X = 0.02,但它可以是任何东西).

1) Calculate the threshold on my NN output which would result in a false positive rate (classifying bg as signal) of X (in this case X = 0.02, but it could be anything).

2) 计算此阈值下的真阳性率.

2) Calculate the true positive rate at this threshold.

给定 numpy 数组 y_true, y_pred,我会写一个函数:

Given numpy arrays y_true, y_pred, I would write a function like:

def eff_at_2percent_metric(y_true, y_pred):
    #Find list of bg events
    bg_list = np.argwhere(y_true < 0.5)
    #Order by the NN output
    ordered_bg_predictions = np.flip(np.sort(y_pred[bg_list]),axis=0)
    #Find the threshold with 2% false positive rate
    threshold = ordered_bg_predictions[0.02*round(len(ordered_bg_list))]

    #Find list of signal events
    sig_list = np.argwhere(y_true > 0.5)
    #Order these by NN output
    ordered_sig_predictions = np.sort(y_pred[sig_list])
    #Find true positive rate with this threshold
    sig_eff = 1 - np.searchsorted(ordered_sig_predictions,threshold)/len(ordered_sig_predictions)

    return sig_eff

当然,这行不通,因为要实现自定义指标,y_true 和 y_pred 应该是 TensorFlow 张量而不是 numpy 数组.有什么办法可以让我正常工作吗?

Of course, this does not work because to implement a custom metric, y_true and y_pred are supposed to be TensorFlow tensors rather than numpy arrays. Is there any way I can make this work correctly?

推荐答案

对特异性的敏感性,我认为这是等效的(特异性是 1 减去 FPR).

There's a metric for sensitivity at specificity, which I believe is equivalent (specificity is one minus FPR).

这篇关于自定义 TensorFlow 指标:给定假阳性率下的真阳性率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 04:21:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1404594.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:阳性率   自定义   指标   TensorFlow

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!