code: def get_feature_weights(
      X: ArrayLike,
      y: ArrayLike,
      fw: np.ndarray,
      parser_path: str,
      tree_method: str,
      model: Type[xgb.XGBModel] = xgb.XGBRegressor,
  ) -> np.ndarray:
      """Get feature weights using the demo parser."""
      with tempfile.TemporaryDirectory() as tmpdir:
          colsample_bynode = 0.5
          reg = model(
              tree_method=tree_method, colsample_bynode=colsample_bynode
          )
  
          reg.fit(X, y, feature_weights=fw)
          model_path = os.path.join(tmpdir, "model.json")
          reg.save_model(model_path)
          with open(model_path, "r", encoding="utf-8") as fd:
              model = json.load(fd)
  
          spec = importlib.util.spec_from_file_location(
              "JsonParser", parser_path
          )
          assert spec is not None
          jsonm = importlib.util.module_from_spec(spec)
          assert spec.loader is not None
          spec.loader.exec_module(jsonm)
          model = jsonm.Model(model)
          splits: Dict[int, int] = {}
          total_nodes = 0
          for tree in model.trees:
              n_nodes = len(tree.nodes)
              total_nodes += n_nodes
              for n in range(n_nodes):
                  if tree.is_leaf(n):
                      continue
                  if splits.get(tree.split_index(n), None) is None:
                      splits[tree.split_index(n)] = 1
                  else:
                      splits[tree.split_index(n)] += 1
  
          od = collections.OrderedDict(sorted(splits.items()))
          tuples = list(od.items())
          k, v = list(zip(*tuples))
          w = np.polyfit(k, v, deg=1)
          return w
  
file_path: xgboost/python-package/xgboost/testing/shared.py
imports: import collections
  import importlib.util
  import json
  import os
  import tempfile
  from typing import Any, Callable, Dict, Type
  import numpy
  import xgboost
  from xgboost._typing import ArrayLike
label_desc: Use image node_id 3 for calling a global function with example usage: get_feature_weights(X, y, fw, parser_path, tree_method, model) and returns: w