code: def plot_ice_explanation(explanation, title):
      feature_names = list(explanation.keys())
  
      fig = plt.figure(layout="constrained", figsize=(15, 10))
      gs0 = gridspec.GridSpec(
          2,
          1,
          figure=fig,
          height_ratios=[1, int(len(feature_names) / 3)],
          top=0.9,
      )
      gs2 = gridspec.GridSpecFromSubplotSpec(
          int(len(feature_names) / 3), 3, subplot_spec=gs0[1]
      )
      gs1 = gridspec.GridSpecFromSubplotSpec(
          1, 3, subplot_spec=gs0[0], width_ratios=[4.5, 10, 4.5]
      )
  
      for i, feature_col in enumerate(feature_names):
          if i > 0:
              gs = gs2[i - 1]
          else:
              gs = gs1[1]
  
          ax = fig.add_subplot(gs)
          delta_avg = 0
          delta_ice_values = []
          for i in range(len(explanation[feature_col])):
              delta_ice = (
                  explanation[feature_col][i]["ice_value"]
                  - explanation[feature_col][i]["ice_value"][0]
              )
              delta_ice_values.append(delta_ice)
              ax.plot(
                  explanation[feature_col][i]["feature_value"],
                  delta_ice,
                  color="b",
                  alpha=0.2,
              )
  
          delta_ice_values = np.asarray(delta_ice_values)
          # average ice value across test instances
          delta_avg = np.mean(delta_ice_values, axis=0)
          ax.plot(
              explanation[feature_col][0]["feature_value"],
              delta_avg,
              color="r",
          )
  
          ax.set_title("{}".format(feature_col))
  
          if i == 0:
              ax.set_ylabel("Model Prediction")
              ax.set_xlabel("Feature Value")
  
      fig.suptitle(title, fontsize="x-large")
      plt.show()
  
file_path: AIX360/examples/gce/plots.py
imports: from typing import List, Union, Tuple
  import matplotlib.pyplot
  import matplotlib.gridspec
  from plotly import express
  from plotly import graph_objects
  from plotly.subplots import make_subplots
  import plotly.io
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: plot_ice_explanation(explanation, title) without return types