accuracy calculation in machine learning

18 ビュー (過去 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