From 14ae939b62699e7f5a40abee0d89f57a91160518 Mon Sep 17 00:00:00 2001 From: MMeketon Date: Thu, 16 Feb 2017 15:29:15 -0500 Subject: [PATCH 1/2] Update test_class_weight.py --- sklearn/utils/tests/test_class_weight.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sklearn/utils/tests/test_class_weight.py b/sklearn/utils/tests/test_class_weight.py index a073eeafcfdc3..57e03f04df561 100644 --- a/sklearn/utils/tests/test_class_weight.py +++ b/sklearn/utils/tests/test_class_weight.py @@ -117,6 +117,14 @@ def test_compute_class_weight_balanced_unordered(): assert_almost_equal(np.dot(cw, class_counts), y.shape[0]) assert_array_almost_equal(cw, [2., 1., 2. / 3]) +def test_class_weight_with_string_label(): + y = np.asarray(["A","A","A","B","B","C"]) + classes = np.unique(y) + class_weights = {c: 1.0 for c in classes} + class_weights['D'] = 1.0 # because of this, we should get a proper ValueError + cw = assert_raises(ValueError, compute_class_weight, class_weights, + classes, y) + return def test_compute_sample_weight(): # Test (and demo) compute_sample_weight. From f049bf0b8a58828e4e9ab44bbf1ab7a2a51824a5 Mon Sep 17 00:00:00 2001 From: Marc Meketon Date: Thu, 16 Feb 2017 15:39:56 -0500 Subject: [PATCH 2/2] Update test_class_weight.py --- sklearn/utils/tests/test_class_weight.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/utils/tests/test_class_weight.py b/sklearn/utils/tests/test_class_weight.py index 57e03f04df561..a225c92aa2029 100644 --- a/sklearn/utils/tests/test_class_weight.py +++ b/sklearn/utils/tests/test_class_weight.py @@ -121,7 +121,7 @@ def test_class_weight_with_string_label(): y = np.asarray(["A","A","A","B","B","C"]) classes = np.unique(y) class_weights = {c: 1.0 for c in classes} - class_weights['D'] = 1.0 # because of this, we should get a proper ValueError + class_weights['D'] = 1.0 # This should get a proper ValueError cw = assert_raises(ValueError, compute_class_weight, class_weights, classes, y) return