Guest User

Untitled

a guest
Feb 14th, 2020
114
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function [cf_mat, total_error] = get_confusion_error(predictions, num_classes)
  2.     actuals = [];
  3.     if num_classes == 2
  4.         actuals = [repmat(1,1,200) repmat(2,1,200)];
  5.     else
  6.         actuals = [repmat(1,1,100) repmat(2,1,200) repmat(3,1,150)];
  7.     end
  8.     cf_mat = repmat(0,num_classes,num_classes);
  9.     for i = 1:length(actuals)
  10.         cf_mat(actuals(i), predictions(i)) = cf_mat(actuals(i), predictions(i)) + 1;
  11.     end
  12.     total_error = sum(cf_mat, 'all');
  13.     errors = [];
  14.     for i = 1:length(cf_mat)
  15.         errors = [errors, (sum(cf_mat(i, :))-cf_mat(i, i))/sum(cf_mat(i, :))];
  16.         total_error = total_error - cf_mat(i,i);
  17.     end
  18.     total_error = total_error/sum(cf_mat, 'all');
  19. end
RAW Paste Data