フィルターのクリア

confusion Matrix ,sensitivity and specificity

28 ビュー (過去 30 日間)
Saba Bashir
Saba Bashir 2020 年 3 月 28 日
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 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 3 月 28 日
What is not working? What is the error?

サインインしてコメントする。

回答 (1 件)

Abdallah Ghazi Faisal Zaid Alkilani
Abdallah Ghazi Faisal Zaid Alkilani 2020 年 3 月 28 日
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
Mina Kheirkhah Rahimabadi 2021 年 10 月 4 日
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 Center および File ExchangeVerification, Validation, and Test についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by