code: def explain_weights_xgboost(
      xgb,
      vec=None,
      top=20,
      target_names=None,  # ignored
      targets=None,  # ignored
      feature_names=None,
      feature_re=None,  # type: Pattern[str]
      feature_filter=None,
      importance_type="gain",
  ):
      """
      Return an explanation of an XGBoost estimator (via scikit-learn wrapper
      XGBClassifier or XGBRegressor, or via xgboost.Booster)
      as feature importances.
  
      See :func:`eli5.explain_weights` for description of
      ``top``, ``feature_names``,
      ``feature_re`` and ``feature_filter`` parameters.
  
      ``target_names`` and ``targets`` parameters are ignored.
  
      Parameters
      ----------
      importance_type : str, optional
          A way to get feature importance. Possible values are:
  
          - 'gain' - the average gain of the feature when it is used in trees
            (default)
          - 'weight' - the number of times a feature is used to split the data
            across all trees
          - 'cover' - the average coverage of the feature when it is used in trees
      """
      booster, is_regression = _check_booster_args(xgb)
      xgb_feature_names = booster.feature_names
      coef = _xgb_feature_importances(
          booster, importance_type=importance_type
      )
      return get_feature_importance_explanation(
          xgb,
          vec,
          coef,
          feature_names=feature_names,
          estimator_feature_names=xgb_feature_names,
          feature_filter=feature_filter,
          feature_re=feature_re,
          top=top,
          description=DESCRIPTION_XGBOOST,
          is_regression=is_regression,
          num_features=coef.shape[-1],
      )
  
imports: from __future__ import absolute_import
  from functools import partial
  import re
  from typing import Any, Dict, List, Tuple, Optional, Pattern
  import numpy
  import scipy.sparse
  from xgboost import XGBClassifier, XGBRegressor, Booster, DMatrix
  from eli5.explain import explain_weights, explain_prediction
  from eli5.sklearn.utils import add_intercept, get_X, get_X0, handle_vec, predict_proba
  from eli5.utils import is_sparse_vector
  from eli5._decision_path import get_decision_path_explanation
  from eli5._feature_importances import get_feature_importance_explanation
label_desc: Use image node_id 1 for calling a global function with example usage: explain_weights_xgboost(xgb, vec, top, target_names, targets, feature_names, feature_re, feature_filter, importance_type) and returns: get_feature_importance_explanation