1.简介
首先本文的目的是给写论文或做数据结果处理可视化的同学一个良好的现成函数,画出如下FAR-FRR对比较优雅的结果图,如下图所示。在csdn上没有发现较好地资源,于是就自己在写论文时手写了一个,并在此分享一哈,如果有bug,欢迎留言,本人会再修复。
本作图基于MATLAB代码实现,本代码比较最大的优点:清晰,美观,能在多个曲线中区分不同结果而不凌乱。
这里的颜色是经过自己精心地挑选后的结果,并且不同的线对应的点的形状也不同,可以更好地在多个曲线情况下实现明显区分,这里最多可以画出七条FAR-FRR对。实际上用户可以自己拓展。
![](https://i-blog.csdnimg.cn/blog_migrate/a32988375416f2a45f175316198df7c2.png)
2.MATLAB函数代码
2.1代码
参数:其中num参数代表你要画的个数,max代表你坐标轴的最大值,比如上图中,max的设置就是20,有时候你需要选择合适的max值来更好展示你的结果(个人的经验值设置max = EER5或者6)。之后是7个EER对,和7个字符串str。其中EER第一行是FNR,第二行是FPR,是2*N的数据格式。这里在下面的例子中给出了两个EER对。
代码如下:
function plotROC(num,max,EER1,EER2,EER3,EER4,EER5,EER6,EER7,str1,str2,str3,str4,str5,str6,str7)
%参数num为要画的曲线个数
%max 为坐标的大小,比如10,那么坐标轴的x和y最大值就是10
%之后是7个EER对,和7个str(坐标图例,如例子所示)
%其中EER第一行是FNR,第二行是FPR,是2*N的数据格式。
plot(EER1(1,:)*100,EER1(2,:)*100,'-s','LineWidth',1.5,'color','[0.12 0.56 0.980]','MarkerFaceColor','[0.12 0.56 0.980]');hold on;
if num>1
plot(EER2(1,:)*100,EER2(2,:)*100,'-o','LineWidth',1.5,'color','[0.8500 0.3250 0.0980]','MarkerFaceColor','[0.8500 0.3250 0.0980]');hold on;
end
if num>2
plot(EER3(1,:)*100,EER3(2,:)*100,'-p','LineWidth',1.5,'color','[0.19,0.58,0.08]','MarkerFaceColor','[0.19,0.58,0.08]');hold on;
end
if num>3
plot(EER4(1,:)*100,EER4(2,:)*100,'-d','LineWidth',1.5,'color','[0.4940 0.1840 0.5560]','MarkerFaceColor','[0.4940 0.1840 0.5560]');hold on;
end
if num>4
plot(EER5(1,:)*100,EER5(2,:)*100,'->','LineWidth',1.5,'color','[0.89 0.81 0.34]','MarkerFaceColor','[0.89 0.81 0.34]');hold on;
end
if num>5
plot(EER6(1,:)*100,EER6(2,:)*100,'-<','LineWidth',1.5,'color','[0.3010 0.7450 0.9330]','MarkerFaceColor','[0.3010 0.7450 0.9330]');hold on;
end
if num>6
plot(EER7(1,:)*100,EER7(2,:)*100,'-*','LineWidth',1.5,'color','[0.53 0.2 0.99330]','MarkerFaceColor','[0.3010 0.7450 0.9330]');hold on;
end
plot(EER1(1,:)*100,EER1(2,:)*100,'-s','LineWidth',1.5,'color','[0.12 0.56 0.980]','MarkerFaceColor','[0.12 0.56 0.980]');hold on;
x=0:1:max;y=0:1:max;
plot(x,y,'--','LineWidth',1,'color','[0.5 0.5 0.5]');
axis([0 max 0 max])
if num==2
legend(str1,str2);
elseif num==3
legend(str1,str2,str3);
elseif num==4
legend(str1,str2,str3,str4);
elseif num==5
legend(str1,str2,str3,str4,str5);
elseif num==6
legend(str1,str2,str3,str4,str5,str6);
elseif num==7
h=legend(str1,str2,str3,str4,str5,str6,str7);
set(h,'FontName','Times New Roman','FontSize',13,'FontWeight','normal')
end
ylabel('False Positive Rate(%)'); %加X轴说明
xlabel('False Negative Rate(%)'); %加X轴说明FNR=FRR
set(gca,'fontsize',20,'fontname','Times New Roman');grid on;
end
2.2使用范例
%这里是本人在做一个认证课题时,对数据进行滤波和不滤波的对比数据,这里将FAR-FRR的实验结果给出了
FARFRRpair1 = [0,0,0,0,0.000273585178752352,0.00181857440375678,0.00488754523085830,0.0121331974397324,0.0252017770701661,0.0467541523938180,0.0692227601678969,0.0945436576285360,0.123170937263794,0.152838755005548,0.194221784789566;0.802288612838423,0.630659690790621,0.462308964144471,0.333828010839395,0.234535351652881,0.152699687589275,0.101341535783424,0.0608915013626829,0.0415781318310968,0.0284853934323811,0.0201219053277877,0.0137570753048694,0.00762083368701014,0.00542110177404294,0.00344755680049797];
%"with-filter"
FARFRRpair2 =[0,0,0,0,0,0.000488707482993197,0.00212886380083949,0.00763977227770541,0.0187679577362860,0.0416824026631929,0.0610873208858011,0.0946598263135041,0.129247175182130,0.171908503883823,0.240000000000000;1.20000000000000,0.600000000000000,0.480000000000000,0.360000000000000,0.264000000000000,0.233006528828541,0.150200340625009,0.0945557744701009,0.0603796388936806,0.0390655782547623,0.0280063890463321,0.0175482641541465,0.0123340293693235,0.00788720821661996,0.00532063492063491];
%"without-filter"
plotROC(2,15,FARFRRpair1,FARFRRpair2,0,0,0,0,0,"with-filter","without-filter","3","4","5","6","7");
基于上述代码运行后的结果如下图,可以看到参数2,代表2个曲线,参数15代表了坐标轴的范围。
3.知识补充
(注:网上已经有许多关于这些指标的介绍,如下贴出简单的介绍,供参考)
FN:False Negative,被判定为负样本,但事实上是正样本。
FP:False Positive,被判定为正样本,但事实上是负样本。
TN:True Negative,被判定为负样本,事实上也是负样本。
TP:True Positive,被判定为正样本,事实上也是证样本。
EER的取值,即FNR与FPR相等时的值,也就是我们图中的虚线与曲线交点的值。
本文原创不易,转发请注明出处,Thanks♪(・ω・)ノ