Confusion matrix

Confusion matrix can be created from predicted and actual labels using confusion_matrix:

using ClassificationMetrics

actual    = [0, 0, 0, 1, 1, 1, 2, 2, 2]
predicted = [1, 2, 0, 0, 0, 1, 0, 2, 0]

confusion_matrix(predicted, actual, sort_labels=true)
┌──────────┬───┬───┬───┐
│ Actual ↓  0  1  2 │
├──────────┼───┼───┼───┤
│        0  1  1  1 │
├──────────┼───┼───┼───┤
│        1  2  1  0 │
├──────────┼───┼───┼───┤
│        2  2  0  1 │
└──────────┴───┴───┴───┘

It is possible to provide full label set in case not all classes are present in the data. Optional argument sort_labels specifies whether the labels should be sorted or not. The confusion matrix is stored in a convenience struct ConfusionMatrix that holds the matrix itself and the labels. It can be passed to prediction_results and classification_report to get further results or "pretty printed" in the terminal.