8000 [MRG + 1] Label warning by kennethjmyers · Pull Request #7802 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG + 1] Label warning #7802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jan 24, 2017
6 changes: 6 additions & 0 deletions sklearn/metrics/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,12 @@ class 2 1.00 0.67 0.80 3
else:
labels = np.asarray(labels)

if target_names is not None and len(labels) != len(target_names):
warnings.warn(
"labels size, {0}, does not match size of target_names, {1}"
.format(len(labels), len(target_names))
)

last_line_heading = 'avg / total'

if target_names is None:
Expand Down
12 changes: 12 additions & 0 deletions sklearn/metrics/tests/test_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,18 @@ def test_classification_report_multiclass_with_long_string_label():
assert_equal(report, expected_report)


def test_classification_report_labels_target_names_unequal_length():
y_true = [0, 0, 2, 0, 0]
y_pred = [0, 2, 2, 0, 0]
target_names = ['class 0', 'class 1', 'class 2']

assert_warns_message(UserWarning,
"labels size, 2, does not "
"match size of target_names, 3",
classification_report,
y_true, y_pred, target_names=target_names)


def test_multilabel_classification_report():
n_classes = 4
n_samples = 50
Expand Down
0