confusiion matrix label in matlab

To create a confusion matrix in MATLAB, you can use the confusionmat function. This function takes in two vectors, one containing the predicted labels and the other containing the true labels, and returns a confusion matrix.

Here's an example:

main.m
% example predicted labels
predicted = [1 1 1 2 2 2 3 3 3];

% example true labels
truth = [1 1 2 2 2 3 3 3 3];

% create confusion matrix
cm = confusionmat(truth, predicted)

% plot confusion matrix
confusionchart(cm)
219 chars
12 lines

In this example, we have a classification problem with three classes. The predicted vector contains our predicted labels, and the truth vector contains the true labels. We call the confusionmat function to compute the confusion matrix, which is then stored in the cm variable.

We can then visualize the confusion matrix using the confusionchart function, which produces a plot like this:

Confusion matrix plot

The confusion matrix shows the number of true positives, false positives, true negatives, and false negatives for each class. It can be a useful tool for evaluating the performance of a classification model.

gistlibby LogSnag