code: def test_gamma_lik(self) -> None:
      import scipy.stats as stats
  
      rng = np.random.default_rng(1994)
      n_samples = 32
      n_features = 10
  
      X = rng.normal(0, 1, size=n_samples * n_features).reshape(
          (n_samples, n_features)
      )
  
      alpha, loc, beta = 5.0, 11.1, 22
      y = stats.gamma.rvs(
          alpha, loc=loc, scale=beta, size=n_samples, random_state=rng
      )
      reg = xgb.XGBRegressor(
          tree_method="hist",
          objective="reg:gamma",
          n_estimators=64,
          eval_metric="gamma-nloglik",
      )
      reg.fit(X, y, eval_set=[(X, y)])
  
      score = reg.predict(X)
  
      booster = reg.get_booster()
      nloglik = float(
          booster.eval(xgb.DMatrix(X, y)).split(":")[1].split(":")[0]
      )
  
      # \beta_i = - (1 / \theta_i a)
      # where \theta_i is the canonical parameter
      # XGBoost uses the canonical link function of gamma in evaluation function.
      # so \theta = - (1.0 / y)
      # dispersion is hardcoded as 1.0, so shape (a in scipy parameter) is also 1.0
      beta = -(1.0 / (-(1.0 / y)))  # == y
      nloglik_stats = -stats.gamma.logpdf(score, a=1.0, scale=beta)
  
      np.testing.assert_allclose(
          nloglik, np.mean(nloglik_stats), rtol=1e-3
      )
  
imports: import numpy
  import pytest
  import xgboost
  from xgboost import testing
  from xgboost.testing.metrics import check_precision_score, check_quantile_error
label_desc: Use image node_id 7 for calling the TestEvalMetrics obj's underlying member method code with example usage: obj.test_gamma_lik() without return types