function[summary]=mb_knnsummary(knntrials) % MB_KNNSUMMARY - Summarize kNN performance over several trials % % [summary] = MB_KNNSUMMARY(KNNTRIALS) % % Outputs: % SUMMARY.CMAT - confusion matrix derived (% correct form) from % all of the elements in knntrials (number correct form) % SUMMARY.CMAT_NOUNK - confusion matrix for classification attempts % SUMMARY.CRATE - Two elements: % 1. average of the diagonal elements in CMAT % 2. average of the diagonal elements in a confusion matrix % generated by excluding the unknown category (i.e. what % fraction of the classification attempts were correct. % % Inputs: % KNNTRIALS - cell array output from mb_knntrainpicktest % % % M. Boland - 15 Apr 1999 % $Id: mb_knnsummary.m_tmp,v 1.1 1999/06/26 14:16:36 boland Exp $ if(~iscell(knntrials)) error('KNNTRIALS must be a cell array containing output from mb_knntrainpicktest') ; end % % Sum all confusion matrices in knntrials confusion = zeros(size(knntrials{1}.cmat)) ; crates=[] ; for i=1:length(knntrials) confusion = confusion + knntrials{i}.cmat ; crates = [crates ; knntrials{i}.crate] ; end % % Calculate the confusion matrix as percentages % rather than numbers of samples summary.cmat = confusion ./ (sum(confusion')' * ones(1,size(confusion,2))) ; % % Same calculations for the matrix without the unknown classes % (i.e. what fraction of the non-unknown samples are correctly classified) confusion_nounk = confusion(:,1:(end-1)) ; summary.cmat_nounk = confusion_nounk ./ (sum(confusion_nounk')' * ... ones(1,size(confusion_nounk,2))) ; numunknown = sum(confusion(:,end)) ; numcorrect = sum(diag(confusion_nounk)) ; summary.Pc_mean=[mean(crates)] ; summary.Pc_var =[var(crates)] ;>>>>
>>