Qu

confusion_matrix

Builtin index · Statistics & ML

confusion_matrix(actual, predicted, [n_classes])

Input: actual, predicted, n_classes · Output: no output

What it is

Draws a confusion-matrix heatmap comparing a length-N vector of true labels actual against a length-N vector of predicted labels predicted, over an optional integer n_classes (inferred from the data if omitted). This is a plotting side effect, not a computed matrix handed back to the caller.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
confusion_matrix(actual, predicted, [n_classes])
actual matrix or vectornot documented yet
predicted matrix or vectornot documented yet
n_classes matrix or vector, optionalnot documented yet
no outputThis is a plotting side effect, not a computed matrix handed back to the caller.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

seq = sequential_split(X, y, test_size = 0.2)
print("sequential_split train rows: {rows(seq.X_train)}")

strat = stratified_split(Xc, yc, test_size = 0.3, seed = 9)
print("stratified_split train rows: {rows(strat.X_train)}")

tvt = train_val_test_split(Xc, yc, val_size = 0.2, test_size = 0.2, seed = 9)
print("train/val/test rows: {rows(tvt.X_train)}, {rows(tvt.X_val)}, {rows(tvt.X_test)}")

m = knn_model(strat.X_train, strat.y_train, 5, kind = "classification")
confusion_matrix(strat.y_test, m.predict(strat.X_test), 2)
output
sequential_split train rows: 96
stratified_split train rows: 140
train/val/test rows: 120, 40, 40
0, 0: 29 29 0, 1: 0 0 1, 0: 2 2 1, 1: 29 29 0 1 0 1 constant-velocity Kalman filter

from statistics-ml

How it works

confusion_matrix(actual, predicted, [n_classes]) — integer class labels assumed 0-based; n_classes defaults to the largest label seen, plus one.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.