Skip to content

Instantly share code, notes, and snippets.

@timvw
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save timvw/2745b143542cc28cc623 to your computer and use it in GitHub Desktop.

Select an option

Save timvw/2745b143542cc28cc623 to your computer and use it in GitHub Desktop.
function [accuracy, precision, recall, f1] = classify(X)
% X is a matrix with the following data:
% X(1,1) we predict that it is true, it is true - true positive
% X(1,2) we predict that it is true, it is false - false positive
% X(2,1) we predict that it is false, it is true - false negative
% X(2,2) we predict that it is false, it is false - true negative
accuracy = ( X(1,1) + X(2,2) ) / sum(sum(X))
precision = X(1,1) / ( X(1,1) + X(1,2) )
recall = X(1,1) / ( X(1,1) + X(2,1) )
f1 = (2 * precision * recall) / (precision + recall)
% ============================================================
end
@timvw

timvw commented Aug 1, 2015

Copy link
Copy Markdown
Author

Calculate accuracy, precision, recall and f1 with Octave

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment