MATLAB中的混淆矩阵的实现
【摘要】
转自:https://blog.csdn.net/zhaomengszu/article/details/56283832
混淆矩阵的matlab代码实现:
actual:就是我们已知的label。
detected是我们通过模型预测得到的label
结合下面语句实现:
[pred,acc,preb] = svmp...
转自:https://blog.csdn.net/zhaomengszu/article/details/56283832
混淆矩阵的matlab代码实现:
actual:就是我们已知的label。
detected是我们通过模型预测得到的label
结合下面语句实现:
[pred,acc,preb] = svmpredict(double(testLabel), testData, model, '-b 1');
- function confusion_matrix(actual,detected)
- [mat,order] = confusionmat(actual,detected);
- %mat = rand(10); %# 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)
- 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');
- 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]);
文章来源: dujiahei.blog.csdn.net,作者:dujiahei,版权归原作者所有,如需转载,请联系作者。
原文链接:dujiahei.blog.csdn.net/article/details/80789945
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)