code: def get_xgboost_preds_df(xgbmodel, X_row, pos_label=1):
      """returns the marginal contributions of each tree in
      an xgboost ensemble
  
      Args:
          xgbmodel: a fitted sklearn-comptaible xgboost model
              (i.e. XGBClassifier or XGBRegressor)
          X_row: a single row of data, e.g X_train.iloc[0]
          pos_label: for classifier the label to be used as positive label
              Defaults to 1.
  
      Returns:
          pd.DataFrame
      """
      if str(type(xgbmodel)).endswith("XGBClassifier'>"):
          is_classifier = True
          n_classes = len(xgbmodel.classes_)
          if n_classes == 2:
              if pos_label == 1:
                  base_proba = (
                      xgbmodel.get_params()["base_score"] or 0.5
                  )
              elif pos_label == 0:
                  base_proba = (
                      1 - xgbmodel.get_params()["base_score"] or 0.5
                  )
              else:
                  raise ValueError("pos_label should be either 0 or 1!")
              n_trees = len(xgbmodel.get_booster().get_dump())
              base_score = np.log(base_proba / (1 - base_proba))
          else:
              base_proba = 1.0 / n_classes
              base_score = xgbmodel.get_params()["base_score"]
              n_trees = int(
                  len(xgbmodel.get_booster().get_dump()) / n_classes
              )
  
      elif str(type(xgbmodel)).endswith("XGBRegressor'>"):
          is_classifier = False
          base_score = xgbmodel.get_params()["base_score"]
          n_trees = len(xgbmodel.get_booster().get_dump())
      else:
          raise ValueError(
              "Pass either an XGBClassifier or XGBRegressor!"
          )
  
      if is_classifier:
          if n_classes == 2:
              if pos_label == 1:
                  preds = [
                      xgbmodel.predict(
                          X_row,
                          iteration_range=(0, i + 1),
                          output_margin=True,
                      )[0]
                      for i in range(n_trees)
                  ]
              elif pos_label == 0:
                  preds = [
                      -xgbmodel.predict(
                          X_row,
                          iteration_range=(0, i + 1),
                          output_margin=True,
                      )[0]
                      for i in range(n_trees)
                  ]
              pred_probas = (
                  np.exp(preds) / (1 + np.exp(preds))
              ).tolist()
          else:
              margins = [
                  xgbmodel.predict(
                      X_row,
                      iteration_range=(0, i + 1),
                      output_margin=True,
                  )[0]
                  for i in range(n_trees)
              ]
              preds = [margin[pos_label] for margin in margins]
              pred_probas = [
                  (np.exp(margin) / np.exp(margin).sum())[pos_label]
                  for margin in margins
              ]
  
      else:
          preds = [
              xgbmodel.predict(
                  X_row, iteration_range=(0, i + 1), output_margin=True
              )[0]
              for i in range(n_trees)
          ]
  
      xgboost_preds_df = pd.DataFrame(
          dict(tree=range(-1, n_trees), pred=[base_score] + preds)
      )
      xgboost_preds_df["pred_diff"] = xgboost_preds_df.pred.diff()
      xgboost_preds_df.loc[0, "pred_diff"] = xgboost_preds_df.loc[
          0, "pred"
      ]
  
      if is_classifier:
          xgboost_preds_df["pred_proba"] = [base_proba] + pred_probas
          xgboost_preds_df[
              "pred_proba_diff"
          ] = xgboost_preds_df.pred_proba.diff()
          xgboost_preds_df.loc[
              0, "pred_proba_diff"
          ] = xgboost_preds_df.loc[0, "pred_proba"]
      return xgboost_preds_df
  
imports: from functools import partial
  import re
  from collections import Counter
  from typing import List, Union
  import warnings
  import numpy
  import pandas
  from pandas.api.types import is_numeric_dtype, is_categorical_dtype
  from dtreeviz.trees import ShadowDecTree
  from sklearn.metrics import make_scorer
  from sklearn.base import clone
  from sklearn.pipeline import Pipeline
  from sklearn.model_selection import KFold, StratifiedKFold
  from joblib import Parallel, delayed
label_desc: Use image node_id 32 for calling a global function with example usage: get_xgboost_preds_df(xgbmodel, X_row, pos_label) and returns: xgboost_preds_df