【问题标题】:Torch/Lua, how to compute Area Under the Curve (AUC)?Torch/Lua,如何计算曲线下面积(AUC)?
【发布时间】:2014-03-19 02:45:09
【问题描述】:

我是 Torch 的新手,我正在解决一个问题,我必须描绘接收器操作特征 (ROC) 曲线及其曲线下面积 (AUC)。

我必须数组:y 轴上的TPrate 和x 轴上的FPrate,大小都为n

如何在 Torch7 或 Lua 中计算此函数的曲线下面积?

我也找到了this code from JayClascoe.com,但我不知道如何使用它的功能。

【问题讨论】:

    标签: lua roc auc


    【解决方案1】:

    您将无法使用 JayClascoe 的代码,因为它适用于函数,而您的代码是一组点。假设FPrate 有 x 坐标的 x 值排序,TPrate 有对应的值,你可以使用Trapezoidal rule。这样的事情可能会奏效:

    local area = 0
    for i = 2, n do
      area = area + (FPrate[i] - FPrate[i-1]) * (TPrate[i-1] + TPrate[i])/2
    end
    

    【讨论】:

    • 谢谢。不应该是:面积 + ( (FPrate[n] - FPrate[n-1]) * (TPrate[n-1] + TPrate[n]) ) /2 ? /2 之前还有两个括号?
    • 在这种情况下应该没关系,不是吗?
    【解决方案2】:

    前段时间我写了一个小torch包,可以计算ROC点和曲线下的面积。我的代码在 github 上,你可以看看并试一试:

    https://github.com/hpenedones/metrics

    让我知道它是否适合您或您是否发现任何问题。这是一个如何使用它的示例:

    require 'torch'
    metrics = require 'metrics'
    gfx = require 'gfx.js'
    
    resp = torch.DoubleTensor { -0.9, -0.8, -0.8, -0.5, -0.1, 0.0, 0.2, 0.2, 0.51, 0.74, 0.89}
    labels = torch.IntTensor  { -1, -1 , 1, -1, -1, 1, 1, -1, -1, 1, 1 }
    
    roc_points, thresholds = metrics.roc.points(resp, labels)
    area = metrics.roc.area(roc_points)
    
    print(area)
    
    gfx.chart(roc_points)
    

    【讨论】:

    • 嘿雨果,我想使用你的包,但我无法安装它。我应该怎么做才能安装它?谢谢
    • 嗨,Davide,我已经在 github 中更新了 README 中的安装说明。
    猜你喜欢
    • 2012-01-29
    • 2017-01-25
    • 2017-06-05
    • 2018-01-28
    • 2011-06-24
    • 1970-01-01
    • 2019-06-22
    • 1970-01-01
    相关资源
    最近更新 更多