confusion Matrix ,sensitivity and specificity

55 Ansichten (letzte 30 Tage)
Saba Bashir
Saba Bashir am 28 Mär. 2020
I have actual Y and prdicted Y matrix of 27×1 double type. i have written the following code but its not working. Kindly help me where i am wrong?
[cm,order] = confusionmat(actual_Y,predicted_Y);
% if yHat are your predictions and yval are your y true then
tp = sum((predicted_Y == 1) & (actual_Y == 1))
fp = sum((predicted_Y == 1) & (actual_Y == 0))
tn = sum((predicted_Y == 0) & (actual_Y == 1))
fn = sum((predicted_Y == 0) & (actual_Y == 0))
sensitivity = tp/(tp + fn) %TPR
specificity = tn/(tn + fp) %TNR
precision = tp / (tp + fp)
FPR = fp/(tn+fp);
Accuracy = (TP+TN)./(TP+FP+TN+FN);
recall = tp / (tp + fn)
F1 = (2 * precision * recall) / (precision + recall);

Antworten (1)

Abdallah Ghazi Faisal Zaid Alkilani
This line:
Accuracy = (TP+TN)./(TP+FP+TN+FN);
Is inconsistent with your variable names:
tp = sum((predicted_Y == 1) & (actual_Y == 1))
fp = sum((predicted_Y == 1) & (actual_Y == 0))
tn = sum((predicted_Y == 0) & (actual_Y == 1))
fn = sum((predicted_Y == 0) & (actual_Y == 0))
Pay closer attention to your variable names.
---------------------------------------------------------------
When I tried your code, I got this error:
Unrecognized function or variable 'TP'.
Error in Untitled (line 12)
Accuracy = (TP+TN)./(TP+FP+TN+FN);
Which means TP wasn't defined. After closer inspection, you will see that you should be using tp not TP. Same for the other variables in the statment above.
  1 Kommentar
Mina Kheirkhah Rahimabadi
Mina Kheirkhah Rahimabadi am 4 Okt. 2021
Just wanted to correct this in your code: tn = sum((predicted_Y == 0) & (actual_Y == 1))
This has to be 'fn' and the other one 'tn'

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Verification, Validation, and Test finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by