Solved – how to calculate precision, recall, and accuracy, if the label is not binary

I know how to evaluate the prediction performance if the label is binary, such as the classification label is sick(yes/no).

The situation is the label is sick(level1/level2/level3),in this situation, could we still calculate the precision? and how?

I feel confused in how to calculate TN/TP/FN/FP. I hope anyone can help me. And I understand R code, if needed, you can write in R or use any R package. For a better descript of data, it is kind like

label  x1   x2 1      21   123 1      223  22 2      22   1 3      8    9 

You need to calculate the confusion matrix, the cross-tabulation of observed and predicted classes. A confusion matrix is 2×2 in binary classification: Predicted (True and False) by Observed (True and False). A confusion matrix is k-by-k in multi-class, where k is the number of classes.

confusion_matrix_example

The positive/correct cells will be on the diagonal (e.g., predict sick-level1 and observed sick-level1). The negative/incorrect cells on the off diagonal and will be segmented by type. There are 2 ways to make a misprediction:

  1. Predict sick-level1 but observed sick-level2
  2. Predict sick-level1 but observed sick-level3

The best R package is caret and use the confusionMatrix function.

Similar Posts:

Rate this post

Leave a Comment