Precision & Recall in
Multiclass Classification

Prof. Dr. Mirco Schoenfeld

confusion matrix

In binary classification, we have this:

https://en.wikipedia.org/wiki/Confusion_matrix

multiclass?

But how is it in multiclass classification?

We usually do not have any notions of positive or negative.

multiclass, not multilabel

We only consider multiclass, not multilabel classification.

Accuracy

For accuracy, this is easy:

\(\text{Accuracy} = \frac{\text{Correct predictions}}{\text{All predictions}}\)

Downsides of accuracy

As always, accuracy is not the perfect measurement.

It disregards class balance and the cost of different errors.

An example

https://www.evidentlyai.com/classification-metrics/multi-class-metrics

An example

https://www.evidentlyai.com/classification-metrics/multi-class-metrics

Precision and Recall in Multiclass classification

To consider precision and recall in multiclass classification,
obtain these metrics for each class individually.

Precision and Recall in Multiclass classification

For Class A, this becomes:

\(\text{Precision}_{\text{Class A}} = \frac{\text{TP}_{\text{Class A}}}{\text{TP}_{\text{Class A}} + \text{FP}_{\text{Class A}}}\)

\(\text{Recall}_{\text{Class A}} = \frac{\text{TP}_{\text{Class A}}}{\text{TP}_{\text{Class A}} + \text{FN}_{\text{Class A}}}\)

Precision and Recall in Multiclass classification

https://www.evidentlyai.com/classification-metrics/multi-class-metrics

Precision and Recall in Multiclass classification

https://www.evidentlyai.com/classification-metrics/multi-class-metrics

Precision and Recall in Multiclass classification

https://www.evidentlyai.com/classification-metrics/multi-class-metrics

Precision and Recall in Multiclass classification

https://www.evidentlyai.com/classification-metrics/multi-class-metrics

Overall Precision and Recall in Multiclass classification

In the end, obtain an average of
precision and recall of individual classes.

Either the macro-average, or the micro-average.

Macro Average

The Macro Average:

\(\text{Precision} = \frac{\text{Precision}_{\text{Class A}} + \dots{} + \text{Precision}_{\text{Class N}}}{N}\)

\(\text{Recall} = \frac{\text{Recall}_{\text{Class A}} + \dots{} + \text{Recall}_{\text{Class N}}}{N}\)

Micro Average

The Micro Average:

\(\text{Precision} = \frac{\text{TP}_{\text{Class A}} + \dots{} + \text{TP}_{\text{Class N}}}{\text{TP}_{\text{Class A}} + \text{FP}_{\text{Class A}} + \dots{} + \text{TP}_{\text{Class N}} + \text{FP}_{\text{Class N}}}\)

\(\text{Recall} = \frac{\text{TP}_{\text{Class A}} + \dots{} + \text{TP}_{\text{Class N}}}{\text{TP}_{\text{Class A}} + \text{FN}_{\text{Class A}} + \dots{} + \text{TP}_{\text{Class N}} + \text{FN}_{\text{Class N}}}\)

Macro vs micro

Macro-averaging gives equal weight to each class

Micro-averaging gives equal weight to each instance

Macro vs micro

Macro-average precision is 76%.
Macro-average recall is 71%.
Micro-average precision and recall are both 82%.

https://www.evidentlyai.com/classification-metrics/multi-class-metrics