i want to calculate precision , recall , f-score and ...., but i get this erro:
Undefined function 'diag' for input arguments of type 'mlearnlib.graphics.chart.ConfusionMatrixChart'.
Error in SHIVANaugmented (line 74)
tp_m = diag(cm);
==============================================the following is a part of my code:
cm=confusionchart (imdsValidation.Labels, YPred);
%%
tp_m = diag(cm);
for i = 1:2 % number of classes
TP = tp_m(i);
FP = sum(cm(:, i), 1) - TP;
FN = sum(cm(i, :), 2) - TP;
TN = sum(cm(:)) - TP - FP - FN;
Accuracy = (TP+TN)./(TP+FP+TN+FN);
TPR = TP./(TP + FN);%tp/actual positive RECALL SENSITIVITY
if isnan(TPR)
TPR = 0;
end
PPV = TP./ (TP + FP); % tp / predicted positive PRECISION
if isnan(PPV)
PPV = 0;
end
TNR = TN./ (TN+FP); %tn/ actual negative SPECIFICITY
if isnan(TNR)
TNR = 0;
end
FPR = FP./ (TN+FP);
if isnan(FPR)
FPR = 0;
end
FScore = (2*(PPV * TPR)) / (PPV+TPR);
if isnan(FScore)
FScore = 0;
end
end
%%
save youRnetwork net

2 件のコメント

Walter Roberson
Walter Roberson 2020 年 9 月 9 日
A confusion chart is a graphic object. What are you hoping that diag() of one would return?
shivan artosh
shivan artosh 2020 年 9 月 10 日
Number

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

 採用された回答

Walter Roberson
Walter Roberson 2020 年 9 月 10 日

0 投票

tp_m = diag(cm.NormalizedValues);

5 件のコメント

shivan artosh
shivan artosh 2020 年 9 月 10 日
excuse me i get this error:
Error using sum
Invalid data type. First argument must be numeric or logical.
Error in SHIVANaugmented (line 78)
FP = sum(cm(:, i), 1) - TP;
Walter Roberson
Walter Roberson 2020 年 9 月 10 日
Well, Don't Do That.
The return value from confusionchart is not a confusion matrix !!
shivan artosh
shivan artosh 2020 年 9 月 10 日
yes i read it but i can not fix my error
Walter Roberson
Walter Roberson 2020 年 9 月 10 日
Go back to your original code and change
cm=confusionchart (imdsValidation.Labels, YPred);
to
cc = confusionchart (imdsValidation.Labels, YPred);
cm = cc.NormalizedValues;
shivan artosh
shivan artosh 2020 年 9 月 10 日
excellent it is working now. thank you

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by