code: def test_ranking():
      # generate random data
      x_train = np.random.rand(1000, 10)
      y_train = np.random.randint(5, size=1000)
      train_group = np.repeat(50, 20)
  
      x_valid = np.random.rand(200, 10)
      y_valid = np.random.randint(5, size=200)
      valid_group = np.repeat(50, 4)
  
      x_test = np.random.rand(100, 10)
  
      params = {
          "tree_method": "exact",
          "objective": "rank:pairwise",
          "learning_rate": 0.1,
          "gamma": 1.0,
          "min_child_weight": 0.1,
          "max_depth": 6,
          "n_estimators": 4,
      }
      model = xgb.sklearn.XGBRanker(**params)
      model.fit(
          x_train,
          y_train,
          group=train_group,
          eval_set=[(x_valid, y_valid)],
          eval_group=[valid_group],
      )
      assert model.evals_result()
  
      pred = model.predict(x_test)
  
      train_data = xgb.DMatrix(x_train, y_train)
      valid_data = xgb.DMatrix(x_valid, y_valid)
      test_data = xgb.DMatrix(x_test)
      train_data.set_group(train_group)
      assert train_data.get_label().shape[0] == x_train.shape[0]
      valid_data.set_group(valid_group)
  
      params_orig = {
          "tree_method": "exact",
          "objective": "rank:pairwise",
          "eta": 0.1,
          "gamma": 1.0,
          "min_child_weight": 0.1,
          "max_depth": 6,
      }
      xgb_model_orig = xgb.train(
          params_orig,
          train_data,
          num_boost_round=4,
          evals=[(valid_data, "validation")],
      )
      pred_orig = xgb_model_orig.predict(test_data)
  
      np.testing.assert_almost_equal(pred, pred_orig)
  
imports: import json
  import os
  import pickle
  import random
  import tempfile
  import warnings
  from typing import Callable, Optional
  import numpy
  import pytest
  from sklearn.utils.estimator_checks import parametrize_with_checks
  import xgboost
  from xgboost import testing
  from xgboost.testing.ranking import run_ranking_categorical, run_ranking_qid_df
  from xgboost.testing.shared import get_feature_weights, validate_data_initialization
  from xgboost.testing.updater import get_basescore
label_desc: Use image node_id 4 for calling a global function with example usage: test_ranking() without return types