confusion Matrix ,sensitivity and specificity

61 vues (au cours des 30 derniers jours)
Saba Bashir
Saba Bashir le 28 Mar 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);
  1 commentaire
Ameer Hamza
Ameer Hamza le 28 Mar 2020
What is not working? What is the error?

Connectez-vous pour commenter.

Réponses (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 commentaire
Mina Kheirkhah Rahimabadi
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'

Connectez-vous pour commenter.

Catégories

En savoir plus sur Verification, Validation, and Test dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by