clear;
CM = load('confusionMatrix_5Exp.mat');
fieldNames = fieldnames(CM);
fieldNames = fieldNames';
varNames = {'CM', 'Sen', 'Spc', 'Prc', 'F1', 'Acc'};
varTypes = {'cell', 'double', 'double', 'double', 'double', 'double'};
CMCell = cell(numel(fieldNames),1);
CMTable = table('Size', [numel(fieldNames) numel(varNames)], 'VariableTypes', varTypes, 'VariableNames', varNames, 'RowNames', fieldNames);
for iField = 1:numel(fieldNames)
curCM = getfield(CM, fieldNames{iField});
resultCM = genRes(curCM);
CMCell{iField} = curCM;
CMTable(iField, :) = {{curCM}, resultCM.Sensitivity, resultCM.Specificity, resultCM.Precision, resultCM.F1, resultCM.Accuracy};
end
%% Support Functions
function resultCM = genRes(CM)
resultCM.Sensitivity = CM(1,1)/(CM(1,1) + CM(2,1));
resultCM.Specificity = CM(2,2)/(CM(2,2) + CM(1,2));
resultCM.Precision = CM(1,1)/(CM(1,1) + CM(1,2));
resultCM.F1 = 2*((resultCM.Precision*resultCM.Specificity)/(resultCM.Precision+resultCM.Specificity));
resultCM.Accuracy = (CM(1,1)+CM(2,2))/sum(CM, 'all')*100;
end
% 附件地址:https://files.cnblogs.com/files/virter/confusionMatrix_5Exp.rar