MATLAB: Calculation of tp,tn,fp,fn for multi classes

fnfptntp

Output=[1,1,1,-1,1,2,9,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,2,5,6,4,14,3,4]
Labels=[1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5,6,6,6,6,6]
from these values I have to calculate TP,TN,FP,FN..

Best Answer

The standard approach for c classes is to use a target matrix of size [ c N ]that only contains columns of the matrix eye(c). The correspondence between the true class indices 1,2,...c and the target is
N = length(truclassindices)
target = ind2vec(truclassindices)
The assigned classes and corresponding errors are obtained from the net output via
output = net(input);
assignedclasses = vec2ind(output);
errors = assignedclasses~=truclassindices;
Nerr = sum(errors)
PctErr = 100*Nerr/N
[cm order] = confusionmat(target,output)
Hope this helps.
Thank you for formally accepting my answer
Greg
Related Question