confusion Matrix ,sensitivity and specificity

61 次查看(过去 30 天)
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 个)

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 个评论
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'

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Verification, Validation, and Test 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by