8000 [MRG+1] Update class_weight.py by MMeketon · Pull Request #8319 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG+1] Update class_weight.py #8319

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 4 commits into from
Feb 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sklearn/utils/class_weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def compute_class_weight(class_weight, classes, y):
for c in class_weight:
i = np.searchsorted(classes, c)
if i >= len(classes) or classes[i] != c:
raise ValueError("Class label %d not present." % c)
raise ValueError("Class label {} not present.".format(c))
else:
weight[i] = class_weight[c]

Expand Down
6 changes: 6 additions & 0 deletions sklearn/utils/tests/test_class_weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ def test_compute_class_weight_not_present():
classes = np.arange(4)
y = np.asarray([0, 0, 0, 1, 1, 2])
assert_raises(ValueError, compute_class_weight, "balanced", classes, y)
# Fix exception in error message formatting when missing label is a string
# https://github.com/scikit-learn/scikit-learn/issues/8312
assert_raise_message(ValueError,
'Class label label_not_present not present',
compute_class_weight,
{'label_not_present': 1.}, classes, y)
# Raise error when y has items not in classes
classes = np.arange(2)
assert_raises(ValueError, compute_class_weight, "balanced", classes, y)
Expand Down
0