@@ -366,7 +366,8 @@ def test_matthews_corrcoef():
366366 y_true_inv = ["b" if i == "a" else "a" for i in y_true ]
367367
368368 assert_almost_equal (matthews_corrcoef (y_true , y_true_inv ), - 1 )
369- y_true_inv2 = label_binarize (y_true , ["a" , "b" ]) * - 1
369+ y_true_inv2 = label_binarize (y_true , ["a" , "b" ])
370+ y_true_inv2 = np .where (y_true_inv2 , 'a' , 'b' )
370371 assert_almost_equal (matthews_corrcoef (y_true , y_true_inv2 ), - 1 )
371372
372373 # For the zero vector case, the corrcoef cannot be calculated and should
@@ -379,8 +380,7 @@ def test_matthews_corrcoef():
379380
380381 # And also for any other vector with 0 variance
381382 mcc = assert_warns_message (RuntimeWarning , 'invalid value encountered' ,
382- matthews_corrcoef , y_true ,
383- rng .randint (- 100 , 100 ) * np .ones (20 , dtype = int ))
383+ matthews_corrcoef , y_true , ['a' ] * len (y_true ))
384384
385385 # But will output 0
386386 assert_almost_equal (mcc , 0. )
@@ -1267,6 +1267,13 @@ def test__check_targets():
12671267 assert_raise_message (ValueError , msg , _check_targets , y1 , y2 )
12681268
12691269
1270+ def test__check_targets_multiclass_with_both_y_true_and_y_pred_binary ():
1271+ # https://github.com/scikit-learn/scikit-learn/issues/8098
1272+ y_true = [0 , 1 ]
1273+ y_pred = [0 , - 1 ]
1274+ assert_equal (_check_targets (y_true , y_pred )[0 ], 'multiclass' )
1275+
1276+
12701277def test_hinge_loss_binary ():
12711278 y_true = np .array ([- 1 , 1 , 1 , - 1 ])
12721279 pred_decision = np .array ([- 8.5 , 0.5 , 1.5 , - 0.3 ])
0 commit comments