混淆矩阵的MATLAB实现
2017-10-09 10:02
441 查看
混淆矩阵的每一列代表了预测类别,每一列的总数表示预测为该类别的数据的数目;每一行代表了数据的真实归属类别,每一行的数据总数表示该类别的数据实例的数目。在图像精度评价中,主要用于比较分类结果和实际测得值,可以把分类结果的精度显示在一个混淆矩阵里面。
下面是混淆矩阵的Matlab实现示例,可直接复制粘贴运行:
% function confusion_matrix(actual,detected)
% [mat,order] = confusionmat(actual,detected);
mat = rand(5); %# A 5-by-5 matrix of random values from 0 to 1
mat(3,3) = 0; %# To illustrate
mat(5,2) = 0; %# To illustrate
imagesc(mat); %# Create a colored plot of the matrix values
colormap(flipud(gray)); %# Change the colormap to gray (so higher values are
%# black and lower values are white)
title('confusion matrix of recognition');
textStrings = num2str(mat(:),'%0.02f'); %# Create strings from the matrix values
textStrings = strtrim(cellstr(textStrings)); %# Remove any space padding
%% ## New code: ###
%idx = find(strcmp(textStrings(:), '0.00'));
%textStrings(idx) = {' '};
%% ################
[x,y] = meshgrid(1:5); %# Create x and y coordinates for the strings
hStrings = text(x(:),y(:),textStrings(:),... %# Plot the strings
'HorizontalAlignment','center');
% hStrings = text(x,y,textStrings(:),... %# Plot the strings
% 'HorizontalAlignment','center');
midValue = mean(get(gca,'CLim')); %# Get the middle value of the color range
textColors = repmat(mat(:) > midValue,1,3); %# Choose white or black for the
%# text color of the strings so
%# they can be easily seen over
%# the background color
set(hStrings,{'Color'},num2cell(textColors,2)); %# Change the text colors
set(gca,'XTick',1:5,... %# Change the axes tick marks
'XTickLabel',{'Bob','Hyt','Maple','Study','Zm'},... %# and tick labels
'YTick',1:5,...
'YTickLabel',{'Bob','Hyt','Maple','Study','Zm'},...
'TickLength',[0 0]);下面是运行结果:
参考:
MATLAB中的混淆矩阵的实现
下面是混淆矩阵的Matlab实现示例,可直接复制粘贴运行:
% function confusion_matrix(actual,detected)
% [mat,order] = confusionmat(actual,detected);
mat = rand(5); %# A 5-by-5 matrix of random values from 0 to 1
mat(3,3) = 0; %# To illustrate
mat(5,2) = 0; %# To illustrate
imagesc(mat); %# Create a colored plot of the matrix values
colormap(flipud(gray)); %# Change the colormap to gray (so higher values are
%# black and lower values are white)
title('confusion matrix of recognition');
textStrings = num2str(mat(:),'%0.02f'); %# Create strings from the matrix values
textStrings = strtrim(cellstr(textStrings)); %# Remove any space padding
%% ## New code: ###
%idx = find(strcmp(textStrings(:), '0.00'));
%textStrings(idx) = {' '};
%% ################
[x,y] = meshgrid(1:5); %# Create x and y coordinates for the strings
hStrings = text(x(:),y(:),textStrings(:),... %# Plot the strings
'HorizontalAlignment','center');
% hStrings = text(x,y,textStrings(:),... %# Plot the strings
% 'HorizontalAlignment','center');
midValue = mean(get(gca,'CLim')); %# Get the middle value of the color range
textColors = repmat(mat(:) > midValue,1,3); %# Choose white or black for the
%# text color of the strings so
%# they can be easily seen over
%# the background color
set(hStrings,{'Color'},num2cell(textColors,2)); %# Change the text colors
set(gca,'XTick',1:5,... %# Change the axes tick marks
'XTickLabel',{'Bob','Hyt','Maple','Study','Zm'},... %# and tick labels
'YTick',1:5,...
'YTickLabel',{'Bob','Hyt','Maple','Study','Zm'},...
'TickLength',[0 0]);下面是运行结果:
参考:
MATLAB中的混淆矩阵的实现
相关文章推荐
- 基于PCA的人脸识别_Matlab实现(个人研读之后的一些总结)
- Matlab 2. 接上回,repmat函数,复制和平铺矩阵,实现1维数据转化为2维数据
- 梯度下降(Gradient Descent)简析及matlab实现
- matlab 常用机器学习算法的实现
- matlab中的开方sqrt用牛顿迭代法实现的代码
- Matlab实现FFT变换
- 小白学《神经网络与深度学习》笔记之二-利用稀疏编码器找图像的基本单位(1)MatLab实现SparseAutoEncoder
- 高斯消去法与列选主元的高斯消去法-matlab实现
- MATLAB实现数图的缩放:双线性内插法
- matlab实现CP分解 代码
- Matlab/OpenCV自己实现Harris特征点提取和匹配
- Poisson image editing算法实现的Matlab代码解析
- Sobel算子matlab实现
- 数字图像去噪典型算法及matlab实现
- matlab实现将彩色图像(R,G,B)色分量的直方图显示出
- 粒子滤波(Particle filter)算法简介及MATLAB实现
- matlab实现分水岭算法详细步骤
- Matlab 实现对码功能
- PCA算法学习_2(PCA理论的matlab实现)
- Matlab Tricks(二十八)—— 笛卡尔积的实现