Error in HeatMap, In following code confusion matrix is plotted but i want to visualize the same using a heat map, what is wrong?

7 visualizaciones (últimos 30 días)
Error using HeatMap/set Invalid parameter/value pair arguments.
Error in HeatMap (line 392) set(obj, pvPairs{:});
Error in maintotaldemo (line 78) HeatMap(Conf_Mat, test_label, test_label, 1,'Colormap','red','ShowAllTicks',1,'UseLogColorMap',true,'Colorbar',true);
clear all; clc;
%% BUILD DORSAL HAND VEIN TEMPLATE DATABASE
%% load mat files
load('db1.mat');
load('db2.mat');
%%reshape into row vector
reduced_testdata = reshape(reduced_testdata,1,4,20); % one row,four column and 15(60/4) group for 20 classes reduced_traindata = reshape(reduced_traindata,1,4,40); % one row,four column and 45(180/4) group for 20 classes
%%adjust dimension
% Adjust matrix dimension
P_test = cell2mat(reduced_testdata); % Convert cell array to matrix
P_train = cell2mat(reduced_traindata);
%% rearranges the dimensions of P_test and P_train
C = permute(P_test,[1 3 2]);
P_test = reshape(C,[],size(P_test,2),1);
C = permute(P_train,[1 3 2]);
P_train = reshape(C,[],size(P_train,2),1);
%% labeling class
train_label=load('train_label.txt');
test_label=load('test_label.txt');
%%Normalisation
%
P_train=P_train/256;
P_test=P_test/256;
%% Normalisation by min max
% P_train=mapminmax(P_train,0,1); % P_test=mapminmax(P_test,0,1);
%% normalisation by Z-scores
% P_train = zscore(P_train,0,2); % P_test =zscore(P_test,0,2);
%% %% PCA low dimension reduction % % P_train = P_train'; % % %%% if classes are 20 then eiganvectors not exceed then 179 % model = perform_pca(P_train,rank(P_train)-1); %rank(P_train)-1 % % test_features= linear_subspace_projection(P_test, model, 1); % P_train=model.train'; % P_test=test_features';
%% classfication
predictlabel = knnclassify(P_test, P_train, train_label,3,'euclidean','nearest'); cp = classperf(test_label,predictlabel);
% mdl = fitcknn(P_train,train_label,'Distance','euclidean','NumNeighbors',3); % predictlabel = predict(mdl,P_test);
Conf_Mat = confusionmat(test_label,predictlabel); disp(Conf_Mat) HeatMap(Conf_Mat, test_label, test_label, 1,'Colormap','red','ShowAllTicks',1,'UseLogColorMap',true,'Colorbar',true);
%% % Evaluate performance
[FPR, TPR,Thr, AUC, OPTROCPT] = perfcurve(predictlabel, test_label,1);
plot(TPR,FPR,'--rs','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10)
figure,
plot(TPR,FPR,'r-','LineWidth',4);
xlabel('False positive rate')
ylabel('True positive rate')
title('ROC Curve for Classification ')
Tbl = table(FPR, TPR,Thr)
%% FAR = FPR = FP/(FP + TN) and FRR = FNR = FN/(FN + TP)
[FPR, FNR,Thr] = perfcurve(predictlabel, test_label,1,'xCrit','FPR','yCrit','FNR','TVals','all'); Thr = Thr/10; figure, plot(Thr,FPR,'r--','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10); xlabel('Threshold') ylabel('False positive rate / FAR') title('ROC Curve for Classification ')
figure,
plot(Thr,FNR,'r--','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10);
xlabel('Threshold')
ylabel('False Negative rate / FRR')
title('ROC Curve for Classification ')
Tbl = table(FPR, FNR,Thr)
fprintf('\n\n Overall accuracy:%f%%\n',cp.CorrectRate*100);

Respuestas (1)

sanidhyak
sanidhyak el 21 de Feb. de 2025
Based on the error message, I am assuming that you are using MATLAB R2016b or an earlier version. This is because the HeatMap function was deprecated after R2014b and fully removed in R2017a. In versions prior to R2017a, the HeatMap function exists but does not support value pairs like Colormap and Colorbar, which is causing the mentioned error.
To resolve this, I recommend switching to the heatmap function, which was introduced in R2017a and supports the desired features.
Kindly refer to the following corrected part of the code using “heatmap” function in MATLAB R2017a and later versions:
% Create heatmap for confusion matrix
h = heatmap(Conf_Mat);
% Set heatmap title and axis labels
h.Title = 'Confusion Matrix';
h.XLabel = 'Predicted Labels';
h.YLabel = 'True Labels';
% Apply colormap (for a red-yellow color gradient)
h.Colormap = hot;
% Display colorbar
colorbar;
Kindly refer to the following official documentation on "heatmap" function in MATLAB:
I hope this helps!

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by