code: def analyze_functional(
      model: SklearnModel,
      functional: callable,
      ax=None,
      name=None,
      X=None,
      y=None,
  ):
      if ax is None:
          _, ax = plt.subplots(1, 1)
      n_chains = model.n_chains
      chain_len = int(len(model.model_samples) / n_chains)
      color = iter(cm.rainbow(np.linspace(0, 1, n_chains)))
  
      functional_specific = partial(functional, X=X, y=y, model=model)
  
      for c in range(n_chains):
          clr = next(color)
          chain_sample = model.model_samples[
              c * chain_len : (c + 1) * chain_len
          ]
          chain_functional = [
              functional_specific(sample=s) for s in chain_sample
          ]
          ax.plot(
              np.arange(chain_len),
              chain_functional,
              color=clr,
              label=f"Chain {c}",
          )
  
      ax.set_ylabel(name)
      ax.set_xlabel("Iteration")
      ax.legend()
      # ax.set_title(title)
      return ax
  
imports: import argparse
  import itertools
  import os
  from functools import partial
  import numpy
  import pandas
  import matplotlib.pyplot
  from matplotlib import cm
  from tqdm import tqdm
  from sklearn import model_selection, datasets
  from sklearn.metrics import mean_squared_error
  from imodels import get_clean_dataset
  from imodels.experimental.bartpy.model import Model
  from imodels.experimental.bartpy.tree import Tree
  from ..sklearnmodel import BART, SklearnModel
label_desc: Use image node_id 4 for calling a global function with example usage: analyze_functional(model, functional, ax, name, X, y) and returns: ax