@@ -317,12 +317,7 @@ def test_regression_all(self):
317317 for metric , scorer in autosklearn .metrics .REGRESSION_METRICS .items ():
318318 y_true = np .array ([1 , 2 , 3 , 4 ])
319319 y_pred = y_true .copy ()
320-
321- # the best possible score of r2 loss is 1.
322- if metric == 'r2' :
323- previous_score = 1
324- else :
325- previous_score = 0
320+ previous_score = scorer ._optimum
326321 current_score = scorer (y_true , y_pred )
327322 self .assertAlmostEqual (current_score , previous_score )
328323
@@ -346,18 +341,17 @@ def test_classification_binary(self):
346341 for metric , scorer in autosklearn .metrics .CLASSIFICATION_METRICS .items ():
347342 # Skip functions not applicable for binary classification.
348343 # TODO: Average precision should work for binary classification,
349- # TODO: but its behavior is not right.
344+ # TODO: but its behavior is not right. When y_pred is completely
345+ # TODO: wrong, it does return 0.5, but when it is not completely
346+ # TODO: wrong, it returns value smaller than 0.5.
350347 if metric in ['average_precision' , 'pac_score' ,
351348 'precision_samples' , 'recall_samples' , 'f1_samples' ]:
352349 continue
353350
354351 y_true = np .array ([1.0 , 1.0 , 1.0 , 0.0 , 0.0 , 0.0 ])
355352 y_pred = np .array ([[0.0 , 1.0 ], [0.0 , 1.0 ], [0.0 , 1.0 ], [1.0 , 0.0 ],
356353 [1.0 , 0.0 ], [1.0 , 0.0 ]])
357- if metric is 'log_loss' :
358- previous_score = 0 # the best value for log loss is 0.
359- else :
360- previous_score = 1 # the best value for other losses is 1.
354+ previous_score = scorer ._optimum
361355 current_score = scorer (y_true , y_pred )
362356 self .assertAlmostEqual (current_score , previous_score )
363357
@@ -390,10 +384,7 @@ def test_classification_multiclass(self):
390384 y_true = np .array ([0.0 , 0.0 , 1.0 , 1.0 , 2.0 ])
391385 y_pred = np .array ([[1.0 , 0.0 , 0.0 ], [1.0 , 0.0 , 0.0 ],
392386 [0.0 , 1.0 , 0.0 ], [0.0 , 1.0 , 0.0 ], [0.0 , 0.0 , 1.0 ]])
393- if metric is 'log_loss' : # the best possible score for log_loss is 0.
394- previous_score = 0
395- else :
396- previous_score = 1 # the best value for other losses is 1.
387+ previous_score = scorer ._optimum
397388 current_score = scorer (y_true , y_pred )
398389 self .assertAlmostEqual (current_score , previous_score )
399390
@@ -424,7 +415,7 @@ def test_classification_multilabel(self):
424415 continue
425416 y_true = np .array ([[1 , 0 , 0 ], [1 , 1 , 0 ], [0 , 1 , 1 ], [1 , 1 , 1 ]])
426417 y_pred = y_true .copy ()
427- previous_score = 1
418+ previous_score = scorer . _optimum
428419 current_score = scorer (y_true , y_pred )
429420 self .assertAlmostEqual (current_score , previous_score )
430421
0 commit comments