% predict - 分类器对测试集的分类结果
% ground_truth - 测试集的正确标签,这里只考虑二分类,即0和1
% auc - 返回ROC曲线的曲线下的面积
function plot_roc()
%初始点为(1.0, 1.0)
%计算出ground_truth中正样本的数目pos_num和负样本的数目neg_num
% predict, ground_truth
tic
data = xlsread('F:\滑坡\洪都拉斯\多元线性回归数据20170715\ROC_DATA.xlsx');
predict = data(:,2);
ground_truth = data(:,1);
pos_num = sum(ground_truth==1);
neg_num = sum(ground_truth==0);
m=size(ground_truth,1);
[pre,Index]=sort(predict);
ground_truth=ground_truth(Index);
x=zeros(m+1,1);
y=zeros(m+1,1);
auc=0;
x(1)=1;y(1)=1;
for i=2:m
TP=sum(ground_truth(i:m)==1);FP=sum(ground_truth(i:m)==0);
x(i)=FP/neg_num;
y(i)=TP/pos_num;
auc=auc+(y(i)+y(i-1))*(x(i-1)-x(i))/2;
end;
x(m+1)=0;y(m+1)=0;
auc=auc+y(m)*x(m)/2;%计算的面积
disp('AUC : ')
disp(auc)
%% plot%%
figure
plot(x,y,'r','linewidth',1);
hold on
plot([0,1],[0,1])
grid on
set(gca,'XTick',0:0.2:1);
set(gca,'YTick',0:0.2:1);
axis equal
title('ROC Curve');
xlabel('1 - Specificity');
ylabel('Sensitivity');
set(gca, 'Fontname', 'arial');
grid on
toc
end
%% Writed by 王明文 8/29/2017
matlab画ROC曲线
4星 · 超过85%的资源 需积分: 43 32 浏览量
2017-08-31
14:49:34
上传
评论 9
收藏 372KB RAR 举报
themingyi
- 粉丝: 203
- 资源: 15
最新资源
- TG-2024-04-26-183849310.mp4
- 汇编语言的概要介绍与分析
- 个人博客系统设计与开发.zip
- 2023-04-06-项目笔记 - 第一百十五阶段 - 4.4.2.113全局变量的作用域-113 -2024.04.26
- 2023-04-06-项目笔记 - 第一百十五阶段 - 4.4.2.113全局变量的作用域-113 -2024.04.26
- htmlzwbjq_downyi.com.zip
- 无头单向非循环链表的实现(Test.c)
- 无头单向非循环链表的实现(SList.c)
- 浏览器重定向插件更新文件
- SSA-BP麻雀算法优化BP神经网络多特征分类预测(Matlab实现完整源码和数据)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈