Main Content

Create confusion matrix chart for classification problem

`confusionchart(`

creates a confusion matrix chart from true labels `trueLabels`

,`predictedLabels`

)`trueLabels`

and predicted labels `predictedLabels`

and returns a `ConfusionMatrixChart`

object. The rows of the confusion matrix correspond to the true class and the columns correspond to the predicted class. Diagonal and off-diagonal cells correspond to correctly and incorrectly classified observations, respectively. Use `cm`

to modify the confusion matrix chart after it is created. For a list of properties, see ConfusionMatrixChart Properties.

`confusionchart(`

creates a confusion matrix chart from the numeric confusion matrix `m`

)`m`

. Use this syntax if you already have a numeric confusion matrix in the workspace.

`confusionchart(`

specifies class labels that appear along the `m`

,`classLabels`

)*x*-axis and *y*-axis. Use this syntax if you already have a numeric confusion matrix and class labels in the workspace.

`confusionchart(`

creates the confusion chart in the figure, panel, or tab specified by `parent`

,___)`parent`

.

`confusionchart(___,`

specifies additional `Name,Value`

)`ConfusionMatrixChart`

properties using one or more name-value pair arguments. Specify the properties after all other input arguments. For a list of properties, see ConfusionMatrixChart Properties.

returns the `cm`

= confusionchart(___)`ConfusionMatrixChart`

object. Use `cm`

to modify properties of the chart after creating it. For a list of properties, see ConfusionMatrixChart Properties.

MATLAB

^{®}code generation is not supported for`ConfusionMatrixChart`

objects.

If you have one-hot (one-of-N) data, use

`onehotdecode`

to prepare your data for use with`confusionchart`

. For example, suppose you have true labels`targets`

and predicted labels`outputs`

, with observations in columns. You can create a confusion matrix chart usingnumClasses = size(targets,1); trueLabels = onehotdecode(targets,1:numClasses,1); predictedLabels = onehotdecode(outputs,1:numClasses,1); confusionchart(trueLabels,predictedLabels)

If you have Statistics and Machine Learning Toolbox™, you can create a confusion matrix chart for tall arrays. For details, see

`confusionchart`

(Statistics and Machine Learning Toolbox) and Confusion Matrix for Classification Using Tall Arrays (Statistics and Machine Learning Toolbox).