code: def test_custom_objective(self):
      param = {"max_depth": 2, "eta": 1, "silent": 1}
      watchlist = [(dtest, "eval"), (dtrain, "train")]
      num_round = 2
  
      def logregobj(preds, dtrain):
          labels = dtrain.get_label()
          preds = 1.0 / (1.0 + np.exp(-preds))
          grad = preds - labels
          hess = preds * (1.0 - preds)
          return grad, hess
  
      def evalerror(preds, dtrain):
          labels = dtrain.get_label()
          return "error", float(sum(labels != (preds > 0.0))) / len(
              labels
          )
  
      # test custom_objective in training
      bst = xgb.train(
          param, dtrain, num_round, watchlist, logregobj, evalerror
      )
      assert isinstance(bst, xgb.core.Booster)
      preds = bst.predict(dtest)
      labels = dtest.get_label()
      err = sum(
          1
          for i in range(len(preds))
          if int(preds[i] > 0.5) != labels[i]
      ) / float(len(preds))
      assert err < 0.1
  
      # test custom_objective in cross-validation
      xgb.cv(
          param,
          dtrain,
          num_round,
          nfold=5,
          seed=0,
          obj=logregobj,
          feval=evalerror,
      )
  
      # test maximize parameter
      def neg_evalerror(preds, dtrain):
          labels = dtrain.get_label()
          return "error", float(sum(labels == (preds > 0.0))) / len(
              labels
          )
  
      bst2 = xgb.train(
          param,
          dtrain,
          num_round,
          watchlist,
          logregobj,
          neg_evalerror,
          maximize=True,
      )
      preds2 = bst2.predict(dtest)
      err2 = sum(
          1
          for i in range(len(preds2))
          if int(preds2[i] > 0.5) != labels[i]
      ) / float(len(preds2))
      assert err == err2
  
file_path: turicreate/src/external/xgboost/tests/python/test_models.py
imports: import numpy
  import xgboost
  import unittest
label_desc: Use image node_id 3 for calling the TestModels obj's underlying member method code with example usage: obj.test_custom_objective() and returns: grad,  hess, str,  unknown, str,  unknown