【问题标题】:Building ROC curve from scrach using Matlab使用 Matlab 从头开始​​构建 ROC 曲线
【发布时间】:2016-02-23 11:00:18
【问题描述】:

我正在尝试使用 Matlab 从头开始​​构建 ROC 曲线。当我运行文件时 auc 是

auc_area =

-2.8129e-006

我认为它错过了切断步骤,但我无法理解。有什么功能可以执行吗? 这是我的代码:

num_pos = sum(all_labels);
tp = cumsum(l==1,1);
fp = repmat((1:n)',[1 m])-tp;

num_neg = n-num_pos;
fpr = bsxfun(@rdivide,fp,num_neg); %False Positive Rate
tpr = bsxfun(@rdivide,tp,num_pos); %True Positive Rate

%Plot the ROC curve

plot(fpr,tpr);
xlabel('False Positive');
ylabel('True Positive');

auc_area = sum(tpr.*[(diff(fp)==1); zeros(1,m)])./num_neg;

【问题讨论】:

  • 你能发一个complete example 包括少量的样本数据吗?您遗漏了一些部分,但如果没有工作示例,很难指出它们。主要是我想知道l中的内容。

标签: matlab machine-learning roc


【解决方案1】:

这是一个执行此操作的函数。我是 3 年前写的。

function auc = areaundercurve(FPR,TPR)
% given true positive rate and false positive rate calculates the area under the curve
% true positive are on the y-axis and false positives on the x-axis
% sum rectangular area between all points
% example: auc=areaundercurve(FPR,TPR);
[x2,inds]=sort(FPR);
x2=[x2,1]; % the trick is in inventing a last point 1,1
y2=TPR(inds);
y2=[y2,1];
xdiff=diff(x2);
xdiff=[x2(1),xdiff];
auc1=sum(y2.*xdiff); % upper point area
auc2=sum([0,y2([1:end-1])].*xdiff); % lower point area
auc=mean([auc1,auc2]);
end

【讨论】:

    猜你喜欢
    • 2013-09-28
    • 2014-08-09
    • 2016-12-26
    • 2021-01-30
    • 2016-09-23
    • 2021-03-08
    • 2016-08-27
    • 2020-09-26
    • 1970-01-01
    相关资源
    最近更新 更多