code: def merge_categorical_shap_interaction_values(
      shap_interaction_values, old_columns, new_columns, onehot_dict
  ):
      """
      Returns a 3d numpy array shap_interaction_values where the onehot-encoded
      categorical columns have been added up together.
  
      Warning:
          Column names in new_columns that are not found in old_columns are
          assumed to be categorical feature names.
  
      Args:
          shap_interaction_values (np.ndarray): shap_interaction output from
              e.g. shap.TreeExplainer(X).shap_interaction_values().
          old_columns (list of str): list of column names with onehotencodings,
              e.g. ["Age", "Sex_Male", "Sex_Female"]
          new_columns (list of str): list of column names without onehotencodings,
              e.g. ["Age", "Sex"]
          onehot_dict (dict): dict of features with lists for onehot-encoded variables,
               e.g. {'Fare': ['Fare'], 'Sex' : ['Sex_male', 'Sex_Female']}
  
      Returns:
          np.ndarray: shap_interaction values with all the onehot-encoded features
              summed together.
      """
  
      if isinstance(old_columns, pd.DataFrame):
          old_columns = old_columns.columns
      if isinstance(new_columns, pd.DataFrame):
          new_columns = new_columns.columns
      old_columns = pd.Index(old_columns)
      new_columns = pd.Index(new_columns)
  
      siv = np.zeros(
          (
              shap_interaction_values.shape[0],
              len(new_columns),
              len(new_columns),
          )
      )
  
      # note: given the for loops here, this code could probably be optimized.
      #       But only runs once anyway...
      for new_col1 in new_columns:
          for new_col2 in new_columns:
              newcol_idx1 = new_columns.get_loc(new_col1)
              newcol_idx2 = new_columns.get_loc(new_col2)
              oldcol_idxs1 = [
                  old_columns.get_loc(col)
                  for col in onehot_dict[new_col1]
              ]
              oldcol_idxs2 = [
                  old_columns.get_loc(col)
                  for col in onehot_dict[new_col2]
              ]
              siv[
                  :, newcol_idx1, newcol_idx2
              ] = shap_interaction_values[:, oldcol_idxs1, :][
                  :, :, oldcol_idxs2
              ].sum(
                  axis=(1, 2)
              )
      return siv
  
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 15 for calling a global function with example usage: merge_categorical_shap_interaction_values(shap_interaction_values, old_columns, new_columns, onehot_dict) and returns: siv