How to find accuracy of a classification algorithm

3 views (last 30 days)
How do I find the algorithm of my BLOB classification algorithm? I have extracted all the information and have found the positive BLOBs and the negative. I have the ground positives and negative.
I understand that to find the accuracy I need to know the true positives etc, but how do I calculate them?
Im = [0 1 1 0 0 0 0 0 0 0;
0 1 1 0 1 1 0 0 0 1;
0 1 1 0 1 1 0 1 0 1;
0 0 0 0 0 0 0 1 0 1;
0 1 1 1 0 1 1 1 0 1;
0 0 0 0 0 0 1 1 0 1;
0 1 0 0 0 0 0 0 0 1;
0 1 0 0 0 0 1 1 0 0;
0 0 0 0 0 0 1 0 0 0;
0 0 0 0 0 0 0 0 0 0];
bw = bwlabel(Im,4);
blob = regionprops(bw, 'All');
% These are the blob indexes for the BLOBs
GN = [2 5 7]; % Ground Negative
GP = [1 3 4 6 ] % Ground Positive
all = [blob(:).Area];
Positive = find(all < 5 )
Negative = find(all > 5 )
% N = TN + TP + FP + FN
% Acc = (TP + TN)/N

Accepted Answer

Jimmy Neutron
Jimmy Neutron on 20 Nov 2021
Edited: Jimmy Neutron on 20 Nov 2021
Im = [0 1 1 0 0 0 0 0 0 0;
0 1 1 0 1 1 0 0 0 1;
0 1 1 0 1 1 0 1 0 1;
0 0 0 0 0 0 0 1 0 1;
0 1 1 1 0 1 1 1 0 1;
0 0 0 0 0 0 1 1 0 1;
0 1 0 0 0 0 0 0 0 1;
0 1 0 0 0 0 1 1 0 0;
0 0 0 0 0 0 1 0 0 0;
0 0 0 0 0 0 0 0 0 0];
bw = bwlabel(Im,4);
blob = regionprops(bw, 'All');
GN = [0 1 0 0 1 0 1] % white Blobs
ground_truth = [1 0 1 1 0 1 0] % Orange Blobs
all = [blob(:).Area];
test_data = (all < 5 )
% Negative = (all > 5 )
% FP Negative in ground truth, but positive in test
false_positives = ~ground_truth & test_data;
false_positive_rate = sum(false_positives(:)) / numel(false_positives);
% FN Positive in ground truth data but negative in your test
false_negatives = ground_truth & ~test_data;
false_negative_rate = sum(false_negatives(:)) / numel(false_negatives);
% TP Positive in both
true_positives = ground_truth & test_data;
true_positive_rate = sum(true_positives(:)) / numel(true_positives);
% TN Negative in both
true_negatives = ~ground_truth & ~test_data;
true_negative_rate = sum(true_negatives(:)) / numel(true_negatives);
% N = TN + TP + FP + FN
N = true_negative_rate + true_positive_rate + false_positive_rate + false_negative_rate;
% Acc = (TP + TN)/N
Acc = (true_positive_rate + true_negative_rate )/N

More Answers (1)

Image Analyst
Image Analyst on 20 Nov 2021
Hmmmm...lots of problem with your code. First of all, you have no reliable ground truth. It's very dangerous to just assume a blob is true or false based on its label. The labels can change from image to image. Even if the image is the same but just very slightly rotated or has a slight amount of noise, the label number could change. So you can't use label numbers as an indicator of whether a blob is true or not.
You'll have to come up with a ground truth IMAGE. Then you can use dice() to compute the similarity coefficient. Or you can use imreconstruct() to determine what blobs you found in your test image with your algorithm being tested, are in, or missing, from your ground truth image. Then you can compute true and false positives and negatives. Then, assuming you want to build up the ROC curve you're going to have to
  1. change either the algorithm (and use the same image) or
  2. change images (but use the same algorithm).
For #2 you're going to have to have a ground truth image for each input image of course.

Categories

Find more on Recognition, Object Detection, and Semantic Segmentation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!