code: def test_early_stopping(self):
      D_train = xgb.DMatrix(self.X_train, self.y_train)
      D_valid = xgb.DMatrix(self.X_valid, self.y_valid)
      evals_result = {}
      rounds = 30
      early_stopping_rounds = 5
      booster = xgb.train(
          {"objective": "binary:logistic", "eval_metric": "error"},
          D_train,
          evals=[(D_train, "Train"), (D_valid, "Valid")],
          num_boost_round=rounds,
          evals_result=evals_result,
          verbose_eval=True,
          early_stopping_rounds=early_stopping_rounds,
      )
      dump = booster.get_dump(dump_format="json")
      assert (
          len(dump) - booster.best_iteration
          == early_stopping_rounds + 1
      )
  
imports: import json
  import os
  import tempfile
  from typing import Union
  import pytest
  import xgboost
  from xgboost import testing
label_desc: Use image node_id 4 for calling the TestCallbacks obj's underlying member method code with example usage: obj.test_early_stopping() without return types