How to create a confusion matrix?

조회 수: 2 (최근 30일)
Emmy Bechtold
Emmy Bechtold 2020년 9월 30일
답변: Pankhuri Kasliwal 2020년 10월 8일
I am trying to use the example from mathworks, identifying significant features and classifying protein profiles, to create a confusion matrix. I am having difficulties identifying what the true values and predicted would be when looking at the PCA-LDA. Can someone help me identify them?
Link below:
https://www.mathworks.com/help/bioinfo/ug/identifying-significant-features-and-classifying-protein-profiles.html#d122e20387

답변 (1개)

Pankhuri Kasliwal
Pankhuri Kasliwal 2020년 10월 8일
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 -

카테고리

Help CenterFile Exchange에서 Dimensionality Reduction and Feature Extraction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by