class_docstr: This object provides the primary interface to the functionality of this library. You can think of it as
  an adaptor that adapts the various decision-tree based libraries for use with dtreeviz. In implementation,
  however, this object encapsulates the key functionality and API but delegates tree model adaptation
  from sklearn etc... to dtreeviz.models.ShadowDecTree subclasses.
class_docstr_tok: ["This","object","provides","the","primary","interface","to","the","functionality","of","this","library",".","You","can","think","of","it","as","an","adaptor","that","adapts","the","various","decision-tree","based","libraries","for","use","with","dtreeviz",".","In","implementation",",","however",",","this","object","encapsulates","the","key","functionality","and","API","but","delegates","tree","model","adaptation","from","sklearn","etc","...","to","dtreeviz.models.ShadowDecTree","subclasses","."]
docstr: Visualize leaves criterion/purities.
  
  The most common criterion/purity 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 leaf_sizes() 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.
  
  
  Usage example :
  viz_model = dtreeviz.model(tree_model, X_train=dataset[features], y_train=dataset[target],
                             feature_names=features, target_name=target, class_names=[0, 1])
  viz_model.leaf_purity()
  
  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 display_type: str, optional
     'plot', 'text'. 'hist'
  :param colors: dict
      A custom set of colors for visualisations
  :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:
code: def leaf_purity(
      self,
      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/purities.
  
      The most common criterion/purity 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 leaf_sizes() 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.
  
  
      Usage example :
      viz_model = dtreeviz.model(tree_model, X_train=dataset[features], y_train=dataset[target],
                                 feature_names=features, target_name=target, class_names=[0, 1])
      viz_model.leaf_purity()
  
      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 display_type: str, optional
         'plot', 'text'. 'hist'
      :param colors: dict
          A custom set of colors for visualisations
      :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:
      """
      leaf_id, leaf_criteria = self.shadow_tree.get_leaf_criterion()
  
      if display_type == "text":
          for leaf, criteria in zip(leaf_id, leaf_criteria):
              print(
                  f"leaf {leaf} has {criteria} {self.shadow_tree.criterion()}"
              )
      elif display_type in ["plot", "hist"]:
          colors = adjust_colors(colors)
          if ax is None:
              if figsize:
                  fig, ax = plt.subplots(figsize=figsize)
              else:
                  fig, ax = plt.subplots()
      else:
          raise ValueError(f"Unknown display_type = {display_type}")
  
      if display_type == "plot":
          ax.set_xticks(range(0, len(leaf_id)))
          ax.set_xticklabels(leaf_id)
          barcontainers = ax.bar(
              range(0, len(leaf_id)),
              leaf_criteria,
              color=colors["hist_bar"],
              lw=0.3,
              align="center",
              width=1,
          )
          for rect in barcontainers.patches:
              rect.set_linewidth(0.5)
              rect.set_edgecolor(colors["rect_edge"])
  
          _format_axes(
              ax,
              "Leaf IDs",
              self.shadow_tree.criterion(),
              colors,
              fontsize,
              fontname,
              ticks_fontsize=None,
              grid=grid,
          )
  
      elif display_type == "hist":
          n, bins, patches = ax.hist(
              leaf_criteria, bins=bins, color=colors["hist_bar"]
          )
          for rect in patches:
              rect.set_linewidth(0.5)
              rect.set_edgecolor(colors["rect_edge"])
  
          _format_axes(
              ax,
              self.shadow_tree.criterion(),
              "Leaf Count",
              colors,
              fontsize,
              fontname,
              ticks_fontsize=None,
              grid=grid,
          )
  
imports: import os
  import tempfile
  from typing import Mapping, List, Callable
  import matplotlib
  import matplotlib.patches
  import matplotlib.pyplot
  import numpy
  import pandas
  from colour import Color, rgb2hex
  from sklearn import tree
  from dtreeviz.colors import adjust_colors
  from dtreeviz.interpretation import explain_prediction_plain_english, explain_prediction_sklearn_default
  from dtreeviz.models.shadow_decision_tree import ShadowDecTree
  from dtreeviz.models.shadow_decision_tree import ShadowDecTreeNode
  from dtreeviz.utils import myround, DTreeVizRender, add_classifier_legend, _format_axes, _draw_wedge, _set_wedge_ticks, tessellate, is_numeric
label_desc: Use image node_id 5 for calling the DTreeVizAPI obj's underlying member method code with example usage: obj.leaf_purity(display_type, colors, fontsize, fontname, grid, bins, figsize, ax) without return types