from
Informedness of a Contingency Matrix
by David Powers
Calculates the probability results are informed and recall, precision, F factor, G factor.
|
| bookmaker(cm) |
% results = bookmaker([contingency matrix])
%
% contingency matrix -> contingency matrix/table of network classification and training targets
% ie. classification x target'
%
% results <- structure of results with the following fields
% contingencyMatrix: As provided as argument 1 to function
% recall: Ratio of correctly claimed class to total count
% it actually was that class
% precision: Ratio correctly claimed class to total count of
% times that it was claimed to be that class
% weightedAverage: Ratio of correctly claimed classes to total
% number of cases
% F: Harmonic mean
% Fall: F over all classes
% G: Geometric mean
% Gall: G over all classes
% bookmakerMatrix: Matrix of bookmaker results per class
% bookmaker: Bookmaker result for all classes
%
% The informedness of a prediction method as captured by a contingency matrix is
% defined as the probability that the prediction method will make a correct decision
% as opposed to guessing and is calculated using the bookmaker algorithm.
%
% Alternate measures of the usefulness of a prediction method are all defective
% in that they do not take into account all cells of the continency matrix,
% they do not take into account the baseline performance due to chance/guessing, or
% they are concerned with significance or information rather than correctness.
%
% The Recall, Precision and Rank average are calculated for comparison, along
% with the F and G measures corresponding to their harmonic and geometric means.
%
% matlab: Sean Fitzgibbon 16/03/03
% octave: David Powers 11/04/03
%
% For technical paper see www.infoeng.flinders.edu.au/papers/20030007.doc
% For tutorial poster see www.infoeng.flinders.edu.au/papers/20030003.ppt
function results = bookmaker(cm)
if (size(cm,1) ~= size(cm,2))
error('Contingency matrix must be square');
else
k = size(cm,1);
end
N = sum(sum(cm));
rprob = sum(cm) ./ N;
pprob = sum(cm') ./ N;
recall = diag(cm)' ./ sum(cm);
precision = diag(cm')' ./ sum(cm');
wav = sum(diag(cm)) ./ N;
% Fall is wrong - use reciprocal formula
F = (2.*precision.*recall) ./ (precision + recall);
Fall = k / sum(ones(1,k)./F);
% Gall is wrong - use kth root
G = sqrt(precision.*recall);
Gall = (prod(G)^(1/k));
mask = diag(ones(1,k));
maskc = reshape(mask,k*k,1);
ind = find(maskc==0);
maskc(ind) = -1;
mask = reshape(maskc,k,k);
prob = rprob;
prob = prob(ones(k,1),:)';
probc = reshape(prob,k*k,1);
probc(ind) = 1-probc(ind);
prob = reshape(probc,k,k);
bmcm = cm ./ prob;
bmcm = bmcm .* mask;
bms = sum(bmcm') / N;
bm = bms * pprob';
%results.contingencyMatrix = cm;
results.N = N;
results.recall = recall;
results.precision = precision;
results.weightedAverage = wav;
results.F = F;
results.Fall = Fall;
results.G = G;
results.Gall = Gall;
%results.bookmakerMatrix = bmcm;
results.bookmakerSum = bms;
results.bookmaker = bm;
|
|
Contact us at files@mathworks.com