code: def test_regression_metrics_at_limits():
      # Single-sample case
      # Note: for r2 and d2_tweedie see also test_regression_single_sample
      assert_almost_equal(mean_squared_error([0.0], [0.0]), 0.0)
      assert_almost_equal(root_mean_squared_error([0.0], [0.0]), 0.0)
      assert_almost_equal(mean_squared_log_error([0.0], [0.0]), 0.0)
      assert_almost_equal(mean_absolute_error([0.0], [0.0]), 0.0)
      assert_almost_equal(mean_pinball_loss([0.0], [0.0]), 0.0)
      assert_almost_equal(
          mean_absolute_percentage_error([0.0], [0.0]), 0.0
      )
      assert_almost_equal(median_absolute_error([0.0], [0.0]), 0.0)
      assert_almost_equal(max_error([0.0], [0.0]), 0.0)
      assert_almost_equal(explained_variance_score([0.0], [0.0]), 1.0)
  
      # Perfect cases
      assert_almost_equal(r2_score([0.0, 1], [0.0, 1]), 1.0)
      assert_almost_equal(d2_pinball_score([0.0, 1], [0.0, 1]), 1.0)
  
      # Non-finite cases
      # R² and explained variance have a fix by default for non-finite cases
      for s in (r2_score, explained_variance_score):
          assert_almost_equal(s([0, 0], [1, -1]), 0.0)
          assert_almost_equal(
              s([0, 0], [1, -1], force_finite=False), -np.inf
          )
          assert_almost_equal(s([1, 1], [1, 1]), 1.0)
          assert_almost_equal(
              s([1, 1], [1, 1], force_finite=False), np.nan
          )
      msg = (
          "Mean Squared Logarithmic Error cannot be used when targets "
          "contain negative values."
      )
      with pytest.raises(ValueError, match=msg):
          mean_squared_log_error([-1.0], [-1.0])
      msg = (
          "Mean Squared Logarithmic Error cannot be used when targets "
          "contain negative values."
      )
      with pytest.raises(ValueError, match=msg):
          mean_squared_log_error([1.0, 2.0, 3.0], [1.0, -2.0, 3.0])
      msg = (
          "Mean Squared Logarithmic Error cannot be used when targets "
          "contain negative values."
      )
      with pytest.raises(ValueError, match=msg):
          mean_squared_log_error([1.0, -2.0, 3.0], [1.0, 2.0, 3.0])
      msg = (
          "Root Mean Squared Logarithmic Error cannot be used when targets "
          "contain negative values."
      )
      with pytest.raises(ValueError, match=msg):
          root_mean_squared_log_error([1.0, -2.0, 3.0], [1.0, 2.0, 3.0])
  
      # Tweedie deviance error
      power = -1.2
      assert_allclose(
          mean_tweedie_deviance([0], [1.0], power=power),
          2 / (2 - power),
          rtol=1e-3,
      )
      msg = "can only be used on strictly positive y_pred."
      with pytest.raises(ValueError, match=msg):
          mean_tweedie_deviance([0.0], [0.0], power=power)
      with pytest.raises(ValueError, match=msg):
          d2_tweedie_score([0.0] * 2, [0.0] * 2, power=power)
  
      assert_almost_equal(
          mean_tweedie_deviance([0.0], [0.0], power=0), 0.0, 2
      )
  
      power = 1.0
      msg = (
          "only be used on non-negative y and strictly positive y_pred."
      )
      with pytest.raises(ValueError, match=msg):
          mean_tweedie_deviance([0.0], [0.0], power=power)
      with pytest.raises(ValueError, match=msg):
          d2_tweedie_score([0.0] * 2, [0.0] * 2, power=power)
  
      power = 1.5
      assert_allclose(
          mean_tweedie_deviance([0.0], [1.0], power=power),
          2 / (2 - power),
      )
      msg = (
          "only be used on non-negative y and strictly positive y_pred."
      )
      with pytest.raises(ValueError, match=msg):
          mean_tweedie_deviance([0.0], [0.0], power=power)
      with pytest.raises(ValueError, match=msg):
          d2_tweedie_score([0.0] * 2, [0.0] * 2, power=power)
  
      power = 2.0
      assert_allclose(
          mean_tweedie_deviance([1.0], [1.0], power=power),
          0.00,
          atol=1e-8,
      )
      msg = "can only be used on strictly positive y and y_pred."
      with pytest.raises(ValueError, match=msg):
          mean_tweedie_deviance([0.0], [0.0], power=power)
      with pytest.raises(ValueError, match=msg):
          d2_tweedie_score([0.0] * 2, [0.0] * 2, power=power)
  
      power = 3.0
      assert_allclose(
          mean_tweedie_deviance([1.0], [1.0], power=power),
          0.00,
          atol=1e-8,
      )
      msg = "can only be used on strictly positive y and y_pred."
      with pytest.raises(ValueError, match=msg):
          mean_tweedie_deviance([0.0], [0.0], power=power)
      with pytest.raises(ValueError, match=msg):
          d2_tweedie_score([0.0] * 2, [0.0] * 2, power=power)
  
imports: from itertools import product
  import numpy
  import pytest
  from numpy.testing import assert_allclose
  from scipy import optimize
  from scipy.special import factorial, xlogy
  from sklearn.dummy import DummyRegressor
  from sklearn.exceptions import UndefinedMetricWarning
  from sklearn.metrics import d2_absolute_error_score, d2_pinball_score, d2_tweedie_score, explained_variance_score, make_scorer, max_error, mean_absolute_error, mean_absolute_percentage_error, mean_pinball_loss, mean_squared_error, mean_squared_log_error, mean_tweedie_deviance, median_absolute_error, r2_score, root_mean_squared_error, root_mean_squared_log_error
  from sklearn.metrics._regression import _check_reg_targets
  from sklearn.model_selection import GridSearchCV
  from sklearn.utils._testing import assert_almost_equal, assert_array_almost_equal, assert_array_equal
label_desc: Use image node_id 4 for calling a global function with example usage: test_regression_metrics_at_limits() without return types