2015-11-20 410 views
0

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

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; 
+0

你可以发布包含少量样本数据的[完整示例](http://stackoverflow.com/help/mcve)吗?你错过了一些作品,但很难指出他们没有一个工作的例子。大多数情况下,我想知道'l'里面是什么。 – kmac

回答

0

这是一个功能,可以做到这一点。我在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