code: def viz_leaf_criterion(
      tree_model,
      tree_index: int = None,  # required in case of tree ensemble,
      display_type: str = "plot",
      colors: dict = None,
      fontsize: int = 10,
      fontname: str = "Arial",
      grid: bool = False,
      bins: int = 10,
      figsize: tuple = None,
      ax=None,
  ):
      """Visualize leaves criterion.
  
      The most common criterion/impurity for tree regressors is “mse”, “friedman_mse”, “mae” and for tree classifers are
      "gini" and "entropy". This information shows the leaf performance/confidence for its predictions, namely how pure or
      impure are the samples from each leaf. Each leaf performance, in the end, will determine the general tree performance.
  
      This visualisation can be used together with viz_leaf_samples() for a better leaf interpretation. For example,
      a leaf with good confidence, but few samples, can be a sign of overfitting. The best scenario would be to have a
      leaf with good confidence and also a lot of samples.
  
      We can call this function in two ways :
      1. by using shadow tree
          ex. viz_leaf_criterion(shadow_dtree)
          - we need to initialize shadow_tree before this call
              - ex. shadow_dtree = ShadowSKDTree(tree_model, dataset[features], dataset[target], features, target, [0, 1])
          - the main advantage is that we can use the shadow_tree for other visualisations methods as well
      2. by using sklearn, xgboost tree
          ex. viz_leaf_criterion(tree_model)
          - maintain backward compatibility
  
      This method contains three types of visualizations:
      - a plot bar visualisations for each leaf criterion, when we want to interpret individual leaves
      - a hist visualizations with leaf criterion, when we want to have a general overview for all leaves
      - a text visualisations, useful when number of leaves is very large and visual interpretation becomes difficult.
  
      :param tree_model: tree.DecisionTreeRegressor, tree.DecisionTreeClassifier, xgboost.core.Booster,
                  dtreeviz.models.sklearn_decision_trees.ShadowSKDTree,
                  dtreeviz.models.xgb_decision_trees.ShadowXGBDTree
          The tree model or dtreeviz shadow tree model to interpret
      :param tree_index: int, optional
          Required in case of tree ensemble. Specify the tree index to interpret.
      :param display_type: str, optional
         'plot', 'text'. 'hist'
      :param colors: dict
          The set of colors used for plotting
      :param fontsize: int
          Plot labels font size
      :param fontname: str
          Plot labels font name
      :param grid: bool
          True if we want to display the grid lines on the visualization
      :param bins:  int
          Number of histogram bins
      :param figsize: optional (width, height) in inches for the entire plot
      :param ax: optional matplotlib "axes" to draw into
      :return:
      """
      warnings.warn(
          "viz_leaf_criterion() function is deprecated starting from version 2.0. \n "
          "For the same functionality, please use this code instead: \n m = dtreeviz.model(...) \n m.leaf_purity()",
          DeprecationWarning,
          stacklevel=2,
      )
  
      shadow_tree = ShadowDecTree.get_shadow_tree(
          tree_model, None, None, None, None, None, tree_index
      )
      model = DTreeVizAPI(shadow_tree)
      model.leaf_purity(
          display_type,
          colors,
          fontsize,
          fontname,
          grid,
          bins,
          figsize,
          ax,
      )
  
imports: import warnings
  from numbers import Number
  from typing import Mapping, List
  import numpy
  import pandas
  from sklearn import tree
  from dtreeviz.models.shadow_decision_tree import ShadowDecTree
  from dtreeviz.utils import myround, DTreeVizRender
  from dtreeviz.trees import DTreeVizAPI
label_desc: Use image node_id 9 for calling a global function with example usage: viz_leaf_criterion(tree_model, tree_index, display_type, colors, fontsize, fontname, grid, bins, figsize, ax) without return types