Confusion Matrix
Definition: A confusion matrix is a performance measurement tool for machine learning classification problems. It is a table that describes the performance of a classification model on a set of test data for which the true values are known.
Structure: The confusion matrix is typically structured as a square matrix with dimensions corresponding to the number of classes. For a binary classification, it is a 2x2 matrix, whereas for a multiclass classification, it expands accordingly.
Components:
- True Positive (TP): The number of correct positive predictions.
- True Negative (TN): The number of correct negative predictions.
- False Positive (FP): The number of incorrect positive predictions (Type I error).
- False Negative (FN): The number of incorrect negative predictions (Type II error).
Example for Binary Classification: | | Predicted Positive | Predicted Negative | |----------------|--------------------|--------------------| | Actual Positive| TP | FN | | Actual Negative| FP | TN |
Metrics Derived from Confusion Matrix:
- Accuracy: ((TP + TN) / (TP + TN + FP + FN))
- Precision: (TP / (TP + FP))
- Recall (Sensitivity): (TP / (TP + FN))
- Specificity: (TN / (TN + FP))
- F1 Score: (2 \times (Precision \times Recall) / (Precision + Recall))
Usage: The confusion matrix provides a more nuanced view of the classification performance than a single metric like accuracy, especially in cases where the class distribution is imbalanced.