confusionchart
Display a chart of a confusion matrix.
The two vectors of values trueLabels and predictedLabels, which
are used to compute the confusion matrix, must be defined with the same
format as the inputs of confusionmat.
Otherwise a confusion matrix m as computed by confusionmat can
be given.
classLabels is an array of labels, i.e. the list of the class names.
If the first argument is a handle to a figure or to a uipanel,
then the confusion matrix chart is displayed inside that object.
Optional property/value pairs are passed directly to the underlying objects,
e.g. "xlabel", "ylabel", "title", "fontname",
"fontsize" etc.
The optional return value cm is a ConfusionMatrixChart object.
Specific properties of a ConfusionMatrixChart object are:
"DiagonalColor"
The color of the patches on the diagonal, default is [0.0, 0.4471, 0.7412].
"OffDiagonalColor"
The color of the patches off the diagonal, default is [0.851, 0.3255, 0.098].
"GridVisible"
Available values: on (default), off.
"Normalization"
Available values: absolute (default), column-normalized,
row-normalized, total-normalized.
"ColumnSummary"
Available values: off (default), absolute,
column-normalized,total-normalized.
"RowSummary"
Available values: off (default), absolute,
row-normalized, total-normalized.
Run demo confusionchart to see some examples.
See also: confusionmat, sortClasses
Source Code: confusionchart
## Setting the chart properties
Yt = [8 5 6 8 5 3 1 6 4 2 5 3 1 4]';
Yp = [8 5 6 8 5 2 3 4 4 5 5 7 2 6]';
confusionchart (Yt, Yp, "Title", ...
"Demonstration with summaries","Normalization",...
"absolute","ColumnSummary", "column-normalized","RowSummary",...
"row-normalized")
ans =
ConfusionMatrixChart with properties:
NormalizedValues: [ 8x8 double ]
ClassLabels: { 8x1 cell }
|
## Cellstr as inputs
Yt = {"Positive", "Positive", "Positive", "Negative", "Negative"};
Yp = {"Positive", "Positive", "Negative", "Negative", "Negative"};
m = confusionmat (Yt, Yp);
confusionchart (m, {"Positive", "Negative"});
|
## Editing the object properties
Yt = {"Positive", "Positive", "Positive", "Negative", "Negative"};
Yp = {"Positive", "Positive", "Negative", "Negative", "Negative"};
cm = confusionchart (Yt, Yp);
cm.Title = "This is an example with a green diagonal";
cm.DiagonalColor = [0.4660, 0.6740, 0.1880];
|
## Sorting classes
Yt = [8 5 6 8 5 3 1 6 4 2 5 3 1 4]';
Yp = [8 5 6 8 5 2 3 4 4 5 5 7 2 6]';
cm = confusionchart (Yt, Yp, "Title", ...
"Classes are sorted in ascending order");
cm = confusionchart (Yt, Yp, "Title", ...
"Classes are sorted according to clusters");
sortClasses (cm, "cluster");
|