accuracy calculation in machine learning

18 vues (au cours des 30 derniers jours)
Roberto Dettori
Roberto Dettori le 23 Avr 2023
Commenté : Roberto Dettori le 24 Avr 2023
The accuracy formula is (TP+TN)/(TP+TN+FP+FN). I can't understand why in all the implementation the accuracy is calculated in one of the following way:
accuracy_tmp = sum(test_labels == predicted_labels, 'all')/numel(predicted_labels);
or in the following way:
accuracy_tmp = sum(diag(confMat)) / sum(confMat, 'all'); %confMat is the confusion matrix
In my opinion, the calculation made in that way doesn't consider the TN value. Seems that only the TP are considered.
Could someone help me to understand?

Réponses (1)

the cyclist
the cyclist le 23 Avr 2023
I'm not sure where your misunderstanding is, but let's take a look at the second formula you wrote for accuracy_tmp:
accuracy_tmp = sum(diag(confMat)) / sum(confMat, 'all'); %confMat is the confusion matrix
The numerator of that fraction is the sum of the diagonal elements of the confusion matrix. The diagonal elements of the confusion matrix are the true positive and the true negative counts. So, the numerator is TP + TN.
The denominator is the sum of all the elements of the confusion matrix, which contains counts for all cases: TP + TN + FP + FN.
All seems right with the world.
  1 commentaire
Roberto Dettori
Roberto Dettori le 24 Avr 2023
Thank you for the answer. I doesn't know that the diagonal elements of the confusion matrix are the true positive and the true negative. I thought that the diagonal elements are only the TP

Connectez-vous pour commenter.

Produits


Version

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by