Matlab画混淆矩阵和ROC曲线(精华)

一、画混淆矩阵

Matlab画混淆矩阵和ROC曲线(精华)_第1张图片

clc;
clear;
close all;

fuse_matrix=rand(5)#产生矩阵

imagesc(fuse_matrix)
set(gca,'xtick',1:5)
set(gca,'xticklabel',{'one ','two','three','four','five'},'XTickLabelRotation',45)#设置横轴和横轴标签大小
set(gca,'ytick',1:5)
set(gca,'yticklabel',{'one','two','three','four','five'})#设置纵轴
set(gca,'FontSize',14,'Fontname', 'Times New Roman');#设置坐标系的数字大小
colorbar#产生colorbar

二、画ROC曲线

clc; clear; close all;

FPR = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.050,0.15,0.15,0.15,0.20,0.20,0.20,0.20,0.20,0.20,0.20,0.25,0.25,0.30,0.35,0.40,0.45,0.45,0.55,0.60,0.65,0.65,0.70,0.70,0.70,0.70,0.70,0.70,0.75,0.75,0.80,0.85,0.90,0.90,0.90,0.95,0.95,0.95,1];
TPR = [0,0,0.050,0.050,0.050,0.050,0.10,0.15,0.15,0.15,0.15,0.15,0.15,0.20,0.25,0.30,0.35,0.35,0.40,0.45,0.45,0.50,0.55,0.60,0.60,0.60,0.60,0.60,0.60,0.65,0.70,0.80,0.85,0.85,0.85,0.95,0.95,0.95,0.95,0.95,0.95,0.95,0.95,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];

acurve=trapz(FPR,TPR);%计算AUC

x_dig=0:0.01:1;
y_dig=x_dig;

color1=[0.9300    0.4700    0.5000];%红色
color2=[86 180 232]./255;
color3=[229 159 1]./255;
color4=[107,105,102]./255;
h=figure;
set(h,'units','normalized','position',[0.1 0.1 0.48 0.8]);%设置绘图窗口的大小
set(h,'color','w');%设置绘图窗口的背景为白色
h1=plot(FPR, TPR,'Color',color2,'LineWidth',3,'MarkerSize',3);hold on;
plot(x_dig,y_dig,'--','Color',color4,'LineWidth',1.5);%画中间的虚线
xlabel('False Positive Ratio (1-specificity)','fontsize',2,'FontWeight','bold');%x轴
ylabel('True Positive Ratio (Sensitivity)','fontsize',2,'FontWeight','bold');%y轴
set(gca,'YLim',[0,1.02]);
set(gca,'XLim',[-0.01,1.01]);

set(gca,'FontSize',24,'LineWidth',1.6)
set(get(gca,'YLabel'),'FontSize',24);
set(get(gca,'XLabel'),'FontSize',24);
set(gca,'YTick',[0:0.2:1])

grid on

ROCtitle_1=['AI AUC = ',num2str(roundn(acurve,-3))];
hh=legend([h1],ROCtitle_1)%,'Location','southeast');
set(hh,'edgecolor','white')

Matlab画混淆矩阵和ROC曲线(精华)_第2张图片

 

更多经常内容可以关注公众号"AI算法与数学之美”,并点击右下角进群

Matlab画混淆矩阵和ROC曲线(精华)_第3张图片

欢迎大家多多点赞和评论

你可能感兴趣的:(AI算法与数学之美)