# Confusion Matrix

Ex: we have a classifier:&#x20;

![](https://846345873-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LagOeJ2nL90MQERwhxy%2F-LgmjlQUsF7qEJOk2zoM%2F-LgnBycXAPgigmfSGQtg%2Fimage.png?alt=media\&token=d4e0cace-0df8-4f88-b0ca-328afd4786d1)

For the point selected:&#x20;

![](https://846345873-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LagOeJ2nL90MQERwhxy%2F-LgmjlQUsF7qEJOk2zoM%2F-LgnCb38Rq9SG-3PbBtr%2Fimage.png?alt=media\&token=60b3a62a-1398-4ca6-9a7c-a6ba313bcf04)

In the end:&#x20;

![](https://846345873-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LagOeJ2nL90MQERwhxy%2F-LgmjlQUsF7qEJOk2zoM%2F-LgnCoRY3R5b2Xzkez1K%2Fimage.png?alt=media\&token=b8f8314d-1a42-4329-a32d-c924de9a92c6)

Say that we have an alarm system. The top right box would be where the 'false alarm' would fall:&#x20;

![](https://846345873-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LagOeJ2nL90MQERwhxy%2F-LgmjlQUsF7qEJOk2zoM%2F-LgnDIipB_81Ikiekay6%2Fimage.png?alt=media\&token=82310e54-b5b5-4908-b1d4-cee120726c85)

We can imagine that there could be an assymetry in how much we  care of each box. False alarm, or the opposite, there is a burlar and it doesn't detect it. &#x20;

We can therefore move our prediction in one way or the other.&#x20;

Other example:

![](https://846345873-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LagOeJ2nL90MQERwhxy%2F-LgmjlQUsF7qEJOk2zoM%2F-LgnENyAVsj6AYVLEauJ%2Fimage.png?alt=media\&token=3662cd13-3ec9-48db-a237-3be3e405949b)

In our confusion matrix, we are happy when the diagonal has the largest values, because all the values in the upper and lower triangle are misclassifications.&#x20;

The terms a re&#x20;

Recall = probability that the algo will correctly identify Hugo Chavel provided that person actually is H.Chav. In our case = 10/16

Precision: 1. Supposed our algorithm observes it is Hugo, what are the chances that it's really him?

**Recall**: True Positive / (True Positive + False Negative). Out of all the items that are truly positive, how many were correctly classified as positive. Or simply, how many positive items were 'recalled' from the dataset.

**Precision**: True Positive / (True Positive + False Positive). Out of all the items labeled as positive, how many truly belong to the positive class.

Other example:&#x20;

![](https://846345873-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LagOeJ2nL90MQERwhxy%2F-LgmjlQUsF7qEJOk2zoM%2F-LgnTRu7emmP9i-H8dUV%2Fimage.png?alt=media\&token=e188d954-7308-406c-88a1-8f75090ca90b)

Equations:

![](https://846345873-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LagOeJ2nL90MQERwhxy%2F-LgmjlQUsF7qEJOk2zoM%2F-LgnUQAxzlSbShh6iJ9B%2Fimage.png?alt=media\&token=3fd4928b-d183-44ef-a38b-19fd5f53cf3b)

Confusion matrix example:&#x20;

The predicted is across the columns, and the actual is across the rows. Therefore,

|        | Predicted |   |
| ------ | --------- | - |
| Actual | 0         | 1 |
| 0      | 23        | 1 |
| 1      | 14        | 2 |

* Therefore, there are 23 non-admitted that we predict to be non-admitted.
* There are 14 admitted that we predicted to be non-admitted.
* There is 1 non-admitted that we predict to be admitted.
* There are 2 admitted that we predict to be admitted.
