How to calculate true positive, true negative, false positive and false negative?

조회 수: 11 (최근 30일)
Hello everyone!
I created artificial neural network to compute answers for my diagnosis. Now, I would like to compare the amount of true positive, true negative, false positive and false negative. I was thinking about creating a loop and count every values.
Thank you for your help.

답변 (1개)

Shreeya
Shreeya 2024년 1월 13일
To calculate the TP, TN, FP, FN, you can refer to the code down below.
% An example considering 1 & 2 as positive and 3 as negative:
real = [1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3];
predicted = [2 2 3 2 1 2 3 2 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3];
realPos = (real==1) | (real == 2);
realNeg = ~realPos;
predictedPos = (predicted==1) | (predicted == 2);
predictedNeg = ~predictedPos;
TP = sum(predictedPos & realPos) % 6
FP = sum(predictedPos & realNeg) % 1
TN = sum(predictedNeg & realNeg) % 27
FN = sum(predictedNeg & realPos) % 6
You can refer to the discussion for more details.

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by