Borrar filtros
Borrar filtros

confusion Matrix ,sensitivity and specificity

28 visualizaciones (últimos 30 días)
Saba Bashir
Saba Bashir el 28 de Mzo. de 2020
Comentada: Mina Kheirkhah Rahimabadi el 4 de Oct. de 2021
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);

Respuestas (1)

Abdallah Ghazi Faisal Zaid Alkilani
Abdallah Ghazi Faisal Zaid Alkilani el 28 de Mzo. de 2020
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 comentario
Mina Kheirkhah Rahimabadi
Mina Kheirkhah Rahimabadi el 4 de Oct. de 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'

Iniciar sesión para comentar.

Categorías

Más información sobre Verification, Validation, and Test en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by