accuracy calculation in machine learning

19 visualizaciones (últimos 30 días)
Roberto Dettori
Roberto Dettori el 23 de Abr. de 2023
Comentada: Roberto Dettori el 24 de Abr. de 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?

Respuestas (1)

the cyclist
the cyclist el 23 de Abr. de 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 comentario
Roberto Dettori
Roberto Dettori el 24 de Abr. de 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

Iniciar sesión para comentar.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by