How to write MATLAb code to generate confusion matrices and calcultes recall and precision?
4 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I've a data file of 101 records with 21 classes. First of all, I want to generate 21 separate confusion matrices for these 21 classes and then want to calculate recall and precision for these 21 confusion matrices. Please guide me that how can I write MATLAB code for this task?
Thank you.
0 件のコメント
回答 (1 件)
MHN
2016 年 2 月 5 日
編集済み: MHN
2016 年 2 月 5 日
You do not have to make 21 separate confusion matrices. You should just make one confusion matrix. E.g. let Y be a vector with 12 elements that shows the real classes of your instances. and let Y_hat be the predicted class of the instances. Then you can easily compute the confusion matrix by the following code:
Y = [1 1 1 1 2 2 2 2 3 3 3 3];
Y_hat = [1 1 1 3 2 3 1 1 3 3 3 3];
C = confusionmat(Y,Y_hat)
C is the confusion matrix.
The same for 101 instances and 21 classes. e.g (I have used a random vector as a real classes and then randomly changed 20 of them to make Y_hat which could be the result of a prediction):
Y = randi(21,101,1);
Y_hat = Y;
Y_hat(randi(101,20,1)) = randi(21,20,1);
[c,order] = confusionmat(Y,Y_hat);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Statistics and Machine Learning Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!