Hi,
This can be done using the "plotconfusion" function. By default, this command will also plot the True Positive, False Negative, Positive Predictive, and False Discovery rates in they grey-colored boxes. Please refer to the following example:
targetsVector = [1 2 1 1 3 2]; % True classes
outputsVector = [1 3 1 2 3 1]; % Predicted classes
% Convert this data to a [numClasses x 6] matrix
targets = zeros(3,6);
outputs = zeros(3,6);
targetsIdx = sub2ind(size(targets), targetsVector, 1:6);
outputsIdx = sub2ind(size(outputs), outputsVector, 1:6);
targets(targetsIdx) = 1;
outputs(outputsIdx) = 1;
% Plot the confusion matrix for a 3-class problem
plotconfusion(targets,outputs)
The class labels can be customized by setting that 'XTickLabel' and 'YTickLabel' properties of the axis:
h = gca;
h.XTickLabel = {'Class A','Class B','Class C',''};
h.YTickLabel = {'Class A','Class B','Class C',''};
h.YTickLabelRotation = 90;
To know more about true values and predicted values, refer to the following links -
- https://in.mathworks.com/matlabcentral/answers/348606-how-to-extract-true-positive-and-true-negative-rates-from-confusion-matrix-obtained-using-classifica?s_tid=answers_rc1-1_p1_Topic
- https://in.mathworks.com/matlabcentral/answers/492598-matlab-pca-lda-code?s_tid=answers_rc1-2_p2_MLT
- https://in.mathworks.com/matlabcentral/answers/325791-what-is-the-value-of-predicted-and-actual