Skip to content

Commit

Permalink
Merge pull request #3 from guibmartins/master
Browse files Browse the repository at this point in the history
Bug-fix in opf_accuracy() function
  • Loading branch information
gugarosa authored Mar 8, 2021
2 parents ee7e5e8 + 648a986 commit 61d516c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions opfython/math/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def opf_accuracy(labels, preds):
errors = np.zeros((n_class, 2))

# Gathering the amount of labels per class
_, counts = np.unique(labels, return_counts=True)
counts = np.bincount(labels)[1:]

# For every label and prediction
for label, pred in zip(labels, preds):
Expand All @@ -105,10 +105,10 @@ def opf_accuracy(labels, preds):
errors[:, 1] /= counts

# Calculating the float value of the predicted label errors
errors[:, 0] /= (np.sum(counts) - counts)
errors[:, 0] /= (np.nansum(counts) - counts)

# Calculates the sum of errors per class
errors = np.sum(errors, axis=1)
errors = np.nansum(errors, axis=1)

# Calculates the OPF accuracy
accuracy = 1 - (np.sum(errors) / (2 * n_class))
Expand Down Expand Up @@ -142,7 +142,7 @@ def opf_accuracy_per_label(labels, preds):

# Gathering the amount of labels per class
_, counts = np.unique(labels, return_counts=True)

# For every label and prediction
for label, pred in zip(labels, preds):
# If label is different from prediction
Expand Down

0 comments on commit 61d516c

Please sign in to comment.