Skip to content

raise warning if labels and target_names have different length in classification_report #7751

@amueller

Description

@amueller

Summarizing #3959. If target_names doesn't match the length of (inferred) labels, probably something is wrong. The following code should raise a warning and point the user to the labels parameter.

y_true = [0, 0, 2, 0, 0]
y_pred = [0, 2, 2, 0, 0]
target_names = ['class 0', 'class 1', 'class 2']
print(metrics.classification_report(y_true, y_pred, target_names=target_names))

== console ==
             precision    recall  f1-score   support

    class 0       1.00      0.75      0.86         4
    class 1       0.50      1.00      0.67         1

avg / total       0.90      0.80      0.82         5

Metadata

Metadata

Assignees

No one assigned

    Labels

    EasyWell-defined and straightforward way to resolve

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions