code: def normalize_shap_interaction_values(
      shap_interaction_values, shap_values=None
  ):
      """
      Normalizes shap_interaction_values to make sure that the rows add up to
      the shap_values.
  
      This is a workaround for an apparant bug where the diagonals of
      shap_interaction_values of a RandomForestClassifier are set equal to the
      shap_values instead of the main effect.
  
      I Opened an issue here: https://github.com/slundberg/shap/issues/723
  
      (so far doesn't seem to be fixed)
  
      Args:
          shap_interaction_values (np.ndarray): output of shap.Explainer.shap_interaction_values()
          shap_values (np.ndarray): output of shap.Explainer.shap_values()
      """
      siv = shap_interaction_values.copy()
  
      orig_diags = np.einsum("ijj->ij", siv)
      row_sums = np.einsum("ijk->ij", siv)
      row_diffs = (
          row_sums - orig_diags
      )  # sum of rows excluding diagonal elements
  
      if shap_values is not None:
          diags = shap_values - row_diffs
      else:
          # if no shap_values provided assume that the original diagonal values
          # were indeed equal to the shap values, and so simply
          diags = orig_diags - row_diffs
  
      s0, s1, s2 = siv.shape
  
      # should have commented this bit of code earlier:
      #   (can't really explain it anymore, but it works! :)
      # In any case, it assigns our new diagonal values to siv:
      siv.reshape(s0, -1)[:, :: s2 + 1] = diags
      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 26 for calling a global function with example usage: normalize_shap_interaction_values(shap_interaction_values, shap_values) and returns: siv