%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function plotConfMat(varargin)
%PLOTCONFMAT plots the confusion matrix with colorscale, absolute numbers
% and precision normalized percentages
%
% usage:
% PLOTCONFMAT(confmat) plots the confmat with integers 1 to n as class labels
% PLOTCONFMAT(confmat, labels) plots the confmat with the specified labels
%
% Arguments
% confmat: a square confusion matrix
% labels (optional): vector of class labels
% number of arguments
switch (nargin)
case 0
confmat = 1;
labels = {'1'};
case 1
confmat = varargin{1};
labels = 1:size(confmat, 1);
otherwise
confmat = varargin{1};
labels = varargin{2};
end
confmat(isnan(confmat))=0; % in case there are NaN elements
numlabels = size(confmat, 1); % number of labels
% calculate the percentage accuracies
confpercent = 100*confmat./repmat(sum(confmat, 1),numlabels,1);
% plotting the colors
imagesc(confpercent');
title(sprintf('Accuracy: %.2f%%', 100*trace(confmat)/sum(confmat(:))));
ylabel('Output Class (Truth)'); xlabel('Target Class (Predicted)');
% set the colormap
maxcolor = [180,60,60]; % 最大值颜色
mincolor = [255,255,255]; % 最小值颜色
mymap = [linspace(mincolor(1)/255,maxcolor(1)/255,64)',...
linspace(mincolor(2)/255,maxcolor(2)/255,64)',...
linspace(mincolor(3)/255,maxcolor(3)/255,64)'];
colormap(mymap)
colorbar()
confmat = confmat';
confpercent = confpercent';
% colormap(flipud(gray));
% Create strings from the matrix values and remove spaces
textStrings = num2str([confpercent(:), confmat(:)], '%.1f%%\n%d\n');
textStrings = strtrim(cellstr(textStrings));
% Create x and y coordinates for the strings and plot them
[x,y] = meshgrid(1:numlabels);
hStrings = text(x(:),y(:),textStrings(:), ...
'HorizontalAlignment','center','fontsize',8);
% Get the middle value of the color range
midValue = mean(get(gca,'CLim'));
% Choose white or black for the text color of the strings so
% they can be easily seen over the background color
textColors = repmat(confpercent(:) > midValue,1,3);
set(hStrings,{'Color'},num2cell(textColors,2));
% Setting the axis labels
set(gca,'XTick',1:numlabels,...
'XTickLabel',labels,...
'YTick',1:numlabels,...
'YTickLabel',labels,...
'TickLength',[0 0]);
a1 = get(gca,'XTickLabel');
set(gca,'XTickLabel',a1,'fontsize',12)
end
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
PNN分类.zip (8个子文件)
zjyanseplotConfMat.m 2KB
data3.mat 91KB
data2.mat 91KB
1.png 39KB
PNN.m 2KB
data1.mat 91KB
data4.mat 91KB
2.png 43KB
共 8 条
- 1
资源评论
前程算法屋
- 粉丝: 5459
- 资源: 782
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功