what is confusion matrix in machine learning

1 year ago 44
Nature

A confusion matrix is a table that summarizes the performance of a machine learning model on a set of test data. It is used to measure the performance of classification models, which aim to predict a categorical label for each input instance. The matrix displays the number of true positives (TP), true negatives (TN), false positives (FP), and false negatives (FN) produced by the model on the test data.

  • True Positive (TP): The number of times the model correctly predicted the positive class.
  • True Negative (TN): The number of times the model correctly predicted the negative class.
  • False Positive (FP): The number of times the model incorrectly predicted the positive class.
  • False Negative (FN): The number of times the model incorrectly predicted the negative class.

For binary classification, the matrix will be of a 2x2 table, while for multi-class classification, the matrix shape will be equal to the number of classes, i.e., for n classes, it will be n x n. The confusion matrix is useful for visualizing how well the model is performing in terms of correctly predicting each class. It is also helpful in cases where there is a significant class imbalance in the given data, or when you want to weigh predictions by your model differently. The confusion matrix can be used to calculate various metrics such as precision, recall, F1 score, and accuracy.