MATLAB画ROC曲线,及计算AUC值

标签:
roc |
分类: 数据挖掘 |
步骤:
- 根据决策值和真实标签画ROC曲线,同时计算AUC的值:
- 计算算法的决策函数值deci
- 根据决策函数值deci对真实标签y进行降序排序,得到新的排序roc_y
- 根据roc_y分别对正负类样本进行累积分布stack_x,stack_y
- 根据stack_x,stack_y计算RUC的值
http://images2015.cnblogs.com/blog/543473/201605/543473-20160515122332898-1976579270.jpg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
function auc
= roc_curve(deci,label_y) %�ci=wx+b,
label_y, true label
[val,ind]
= sort (deci, 'descend' );
roc_y
= label_y(ind);
stack_x
= cumsum (roc_y
== -1)/ sum (roc_y
== -1);
stack_y
= cumsum (roc_y
== 1)/ sum (roc_y
== 1);
auc
= sum ((stack_x(2: length (roc_y),1)-stack_x(1: length (roc_y)-1,1)).*stack_y(2: length (roc_y),1))
%Comment
the above lines if using perfcurve of statistics
toolbox
%[stack_x,stack_y,thre,auc]=perfcurve(label_y,deci,1);
plot (stack_x,stack_y);
xlabel ( 'False
Positive Rate' );
ylabel ( 'True
Positive Rate' );
title ([ 'ROC
curve of (AUC = ' num2str (auc) '
)' ]);
end |
前一篇:深度学习资料