accuracy calculation in machine learning

조회 수: 19 (최근 30일)
Roberto Dettori
Roberto Dettori 2023년 4월 23일
댓글: Roberto Dettori 2023년 4월 24일
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?

답변 (1개)

the cyclist
the cyclist 2023년 4월 23일
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
Roberto Dettori
Roberto Dettori 2023년 4월 24일
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

댓글을 달려면 로그인하십시오.

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by