Matlab, how to calculate AUC (Area Under Curve)?

前端 未结 6 2073
情歌与酒
情歌与酒 2021-01-01 00:06

I have the file data.txt with two columns and N rows, something like this:

0.009943796 0.4667975
0.009795735 0.46777886
0.009623984 0.46897832
0         


        
相关标签:
6条回答
  • 2021-01-01 00:16

    There are some options to trapz for the person ready to do some coding by themselves. This link shows the implementation of Simpson's rule, with python code included. There is also a File Exchange on simpsons rule.

    0 讨论(0)
  • 2021-01-01 00:17

    Easiest way is the trapezoidal rule function trapz.

    If your data is known to be smooth, you could try using Simpson's rule, but there's nothing built-in to MATLAB for integrating numerical data via Simpson's rule. (& I'm not sure how to use it for x/y data where x doesn't increase steadily)

    0 讨论(0)
  • 2021-01-01 00:20

    Source: Link

    An example in MATLAB to help you get your answer ...

    x=[3 10 15 20 25 30];
    y=[27 14.5 9.4 6.7 5.3 4.5];
    trapz(x,y)
    

    In case you have negative values in y, you can do like,

    y=max(y,0)
    
    0 讨论(0)
  • 2021-01-01 00:21

    just add AUC = trapz(X,Y) to your program and you will get the area under the curve

    0 讨论(0)
  • 2021-01-01 00:22

    [~,~,~,AUC] = perfcurve(labels,scores,posclass);

    % posclass might be 1

    http://www.mathworks.com/matlabcentral/newsreader/view_thread/252131

    0 讨论(0)
  • 2021-01-01 00:28

    You can do something like that:

    AUC = sum((Y(1:end-1)+Y(2:end))/2.*...
      (X(2:end)-X(1:end-1)));
    
    0 讨论(0)
提交回复
热议问题