Skip to content

Commit

Permalink
Merge pull request #32 from kevinalexmathews/master
Browse files Browse the repository at this point in the history
Add weighted average
  • Loading branch information
Hironsan authored Sep 30, 2020
2 parents 332eead + a82a873 commit 5e624d7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion seqeval/metrics/sequence_labeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def classification_report(y_true, y_pred, digits=2, suffix=False):
for e in pred_entities:
d2[e[0]].add((e[1], e[2]))

last_line_heading = 'macro avg'
last_line_heading = 'weighted avg'
width = max(name_width, len(last_line_heading), digits)

headers = ["precision", "recall", "f1-score", "support"]
Expand Down Expand Up @@ -375,6 +375,12 @@ def classification_report(y_true, y_pred, digits=2, suffix=False):
f1_score(y_true, y_pred, suffix=suffix),
np.sum(s),
width=width, digits=digits)
report += row_fmt.format('macro avg',
np.average(ps),
np.average(rs),
np.average(f1s),
np.sum(s),
width=width, digits=digits)
report += row_fmt.format(last_line_heading,
np.average(ps, weights=s),
np.average(rs, weights=s),
Expand Down

0 comments on commit 5e624d7

Please sign in to comment.