How to calculate confusion matrix , accuracy and precision

조회 수: 266 (최근 30일)
Abdussalam Elhanashi
Abdussalam Elhanashi 2020년 12월 10일
댓글: sed 2022년 8월 20일
Hi
I have two logical tables 100 x 100 for each that contain 0 & 1 values . one table for original values and other table is for predicted values
i want to know how can i make confusion matrix and calculate accuracy and precision for predicted values in comparision to original values
Here the tables:-
original values
predicted values

답변 (2개)

Srivardhan Gadila
Srivardhan Gadila 2020년 12월 17일
You can refer to the following functions available in MATLAB to compute confusion matrix: Functions for computing "confusion matrix".
accuracy = sum(OrigValues == PredValues,'all')/numel(PredValues)
Make sure that the above computations are performed properly w.r.t the number of samples dimension and necessary changes are to be made based on it (i.e., Dimension of number of samples can be number of rows or number of columns or the number of tables itself in your case as it is not mentioned anywhere in the question).

Ayokunmi Opaniyi
Ayokunmi Opaniyi 2022년 5월 22일
I will like to calculate the accuracy, precision and recall of my dataset in matlab.
can anyone please help me how to go about it with the sample code.
Thank you in advance.
  댓글 수: 1
sed
sed 2022년 8월 20일
figure
cm=confusionchart(Ytest,YPred)
cm.ColumnSummary = 'column-normalized';
cm.RowSummary = 'row-normalized';
cm.Title = ' Confusion Matrix';
[m,order]=confusionmat(Ytest,YPred);
Diagonal=diag(m);
sum_rows=sum(m,2);
Precision=Diagonal./sum_rows;
Overall_Precision=mean(Precision)
sum_col=sum(m,1);
recall=Diagonal./sum_col';
overall_recall=mean(recall)
F1_Score=2*((Overall_Precision*overall_recall)/(Overall_Precision+overall_recall))

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Phased Array Design and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by