Commit 3e63cf170d53f67c7d7ca1f574e3a5335dddadb8
1 parent
d64fa68d
added matlab files to aid in classifier characterization
Showing
3 changed files
with
38 additions
and
0 deletions
Show diff stats
1 | +function M = cls_ConfusionMatrix(GT, T) | |
2 | + | |
3 | +%calculate the classes (unique elements in the GT array) | |
4 | +C = unique(GT); | |
5 | +nc = length(C); %calculate the number of classes | |
6 | +M = zeros(nc); %allocate space for the confusion matrix | |
7 | + | |
8 | +%for each class | |
9 | +for ci = 1:nc | |
10 | + for cj = 1:nc | |
11 | + M(ci, cj) = nnz((GT == C(ci)) .* (T == C(cj))); | |
12 | + end | |
13 | +end | |
0 | 14 | \ No newline at end of file | ... | ... |
1 | +function S = cls_MeanClassFeatures(F, T) | |
2 | +%Calculates the mean set of features for each class given the feature matrix F and targets T | |
3 | + | |
4 | +C = unique(T); %get the class IDs | |
5 | +nc = length(C); | |
6 | + | |
7 | +S = zeros(nc, size(F, 2)); %allocate space for the mean feature vectors | |
8 | +for c = 1:nc %for each class | |
9 | + S(c, :) = mean(F(T == C(c), :)); %calculate the mean feature vector for class c | |
10 | +end | |
11 | + | |
12 | +S = S'; | |
0 | 13 | \ No newline at end of file | ... | ... |
1 | +function cls_PlotConfusionMatrix(M) | |
2 | + | |
3 | + | |
4 | +%normalize each row by its column | |
5 | +sum_cols = repmat(sum(M, 1), size(M, 1), 1); | |
6 | +Mc = M ./ sum_cols; | |
7 | +subplot(2, 1, 1), | |
8 | +bar(Mc'); | |
9 | + | |
10 | +sum_rows = repmat(sum(M, 2), 1, size(M, 2)); | |
11 | +Mr = M ./ sum_rows; | |
12 | +subplot(2, 1, 2), | |
13 | +bar(Mr); | |
0 | 14 | \ No newline at end of file | ... | ... |