Skip to content

Commit b52fdaf

Browse files
committed
one figure for confusion matrix using knn algorithm in episode 4
1 parent 4866b70 commit b52fdaf

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

content/04-supervised-ML-classification.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ For classification tasks, metrics like accuracy, precision, recall, and the F1-s
273273
274274
275275
In classification tasks, a **confusion matrix** is a valuable tool for evaluating model performance by comparing predicted labels against true labels.
276-
For a multiclass classification task like the penguins dataset, the confusion matrix is an **N x N** matrix, where **N** is the number of target classes (here **N=3** for three penguins species). Each cell $(i, j)$ in the matrix indicates the number of instances where the true class was $i$ and the model predicted class $j$. Diagonal elements represent correct predictions, while off-diagonal elements indicate misclassifications. The confusion matrix provides an easy-to-understand overview of how often the predictions match the actual labels and where the model tends to make mistakes.
276+
For a multiclass classification task like the penguins dataset, the confusion matrix is an **N x N** matrix, where **N** is the number of target classes (here **N=3** for three penguins species). Each cell *(i, j)* in the matrix indicates the number of instances where the true class was *i* and the model predicted class *j*. Diagonal elements represent correct predictions, while off-diagonal elements indicate misclassifications. The confusion matrix provides an easy-to-understand overview of how often the predictions match the actual labels and where the model tends to make mistakes.
277277

278278
Since we will plot the confusion matrix multiple times, we write a function and call this function later whenever needed, which promotes clarity and avoids redundancy. This is especially helpful as we evaluate multiple classifiers such as KNN, Decision Trees, or SVM on the penguins dataset.
279279

@@ -302,5 +302,12 @@ We compute the confusion matrix from the trined model using the KNN algorithm, a
302302
plot_confusion_matrix(cm_knn, "Confusion Matrix using KNN algorithm", "confusion-matrix-knn.png")
303303
304304
305+
.. figure:: img/confusion-matrix-knn.png
306+
:align: center
307+
:width: 256px
308+
309+
The first row: there are 28 Adelie penguins in the test data, and all these penguins are identified as Adelie (valid). The second row: there are 20 Chinstrap pengunis in the test data, with 2 identified as Adelie (invalid), none are correctly recognized as Chinstrap, and 18 identified as Chinstrap (valid). The third row: there are 19 Gentoo penguins in the test data, and all these penguins are identified as Gentoo (valid).
310+
311+
305312

306313

content/img/confusion-matrix-knn.png

23.2 KB
Loading

0 commit comments

Comments
 (0)