Closed eloukas closed 4 years ago
Please specify mode='strict'
:
>>> from seqeval.metrics import classification_report
>>> from seqeval.scheme import IOB2
>>> y_pred = [['B-LOC', 'I-LOC', 'I-PER', 'B-PER']]
>>> y_true = [['O', 'O', 'O', 'O']]
>>> print(classification_report(y_true=y_true, y_pred=y_pred, scheme=IOB2, mode='strict'))
/Users/hironsan/PycharmProjects/seqeval/seqeval/metrics/v1.py:57: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
_warn_prf(average, modifier, msg_start, len(result))
/Users/hironsan/PycharmProjects/seqeval/seqeval/metrics/v1.py:57: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 due to no true samples. Use `zero_division` parameter to control this behavior.
_warn_prf(average, modifier, msg_start, len(result))
precision recall f1-score support
LOC 0.00 0.00 0.00 0
PER 0.00 0.00 0.00 0
micro avg 0.00 0.00 0.00 0
macro avg 0.00 0.00 0.00 0
weighted avg 0.00 0.00 0.00 0
As the title says, when your
y_true
contains only 'O' tokens, theclassification_report
method will return the following error:ZeroDivisionError: Weights sum to zero, can't be normalized
This can be confusing when testing on a small, local dataset where the chances of having 'O' tokens is really high, thus, confusing the user.
Maybe there should be a try catch returning an appropriate message for that case.
How to reproduce the behaviour
Your Environment