简体   繁体   English

Matlab中混淆矩阵的最小值和最大值

[英]Min and Max of Confusion matrices in Matlab

In Matlab I have a cell of 100 confusion matrices. 在Matlab中,我有一个包含100个混淆矩阵的单元。

For example confusionMatrix{1} = 例如confusionMatrix{1} =

16     1     0
 0    12     2
 0    10     9

How do I find the two confusion matrices out of these that have the best and worst prediction rates (sum of non-diagonal elements)? 如何从其中具有最佳和最差预测率(非对角元素的总和)的两个混淆矩阵中找到?

You can discriminate the non-diagonal elements of a matrix A by using triu displaced up for both the matrix and its transpose: triu(A,1) and triu(A',1): 通过对矩阵及其转置使用向上移位的triu,可以区分矩阵A的非对角元素:triu(A,1)和triu(A',1):

sum(sum(triu(a,1)+triu(a',1)'))

If you want to do so for all cells in confusionMatrix{:} you can use cellfun, and then sort: 如果要对confusionMatrix {:}中的所有单元格执行此操作,则可以使用cellfun,然后进行排序:

prediction_rate=cellfun(@(a)  sum(sum(triu(a,1)+triu(a',1)')), confusionMatrix);
[r,idx]=sort(prediction_rate);
best_rate=r(end);
best_rated=idx(end);
worst_rate=r(1);
worst_rated=idx(1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM