code: def plot_confusion_matrix(model, partition):
      r"""Draw the confusion matrix.
  
      Parameters
      ----------
      model : alphapy.Model
          The model object with plotting specifications.
      partition : alphapy.Partition
          Reference to the dataset.
  
      Returns
      -------
      None : None
  
      References
      ----------
  
      http://scikit-learn.org/stable/modules/model_evaluation.html#confusion-matrix
  
      """
  
      logger.info("Generating Confusion Matrices")
      plot_dir = get_plot_directory(model)
      pstring = datasets[partition]
  
      # For classification only
  
      if model.specs["model_type"] != ModelType.classification:
          logger.info("Confusion Matrix is for classification only")
          return None
  
      # Get X, Y for correct partition.
      X, y = get_partition_data(model, partition)
  
      # Plot Parameters
      np.set_printoptions(precision=2)
      cmap = plt.cm.Blues
      fmt = ".2f"
  
      # Generate a Confusion Matrix for each algorithm
  
      for algo in model.algolist:
          logger.info("Confusion Matrix for Algorithm: %s", algo)
  
          # get predictions for this partition
          y_pred = model.preds[(algo, partition)]
  
          # compute confusion matrix
          cm = confusion_matrix(y, y_pred)
          logger.info("Confusion Matrix:")
          logger.info("%s", cm)
  
          # normalize confusion matrix
          cm_pct = cm.astype("float") / cm.sum(axis=1)[:, np.newaxis]
  
          # initialize plot
          _, ax = plt.subplots()
  
          # set the title of the confusion matrix
          title = (
              algo
              + " Confusion Matrix: "
              + pstring
              + " ["
              + str(np.sum(cm))
              + "]"
          )
          plt.title(title)
  
          # only use the labels that appear in the data
          classes = unique_labels(y, y_pred)
  
          # show all ticks
          ax.set(
              xticks=np.arange(cm.shape[1]),
              yticks=np.arange(cm.shape[0]),
              xticklabels=classes,
              yticklabels=classes,
              title=title,
              ylabel="True Label",
              xlabel="Predicted Label",
          )
  
          # rotate the tick labels and set their alignment
          plt.setp(
              ax.get_xticklabels(),
              rotation=45,
              ha="right",
              rotation_mode="anchor",
          )
  
          # loop over data dimensions and create text annotations
          thresh = (cm_pct.max() + cm_pct.min()) / 2.0
          for i in range(cm.shape[0]):
              for j in range(cm.shape[1]):
                  cm_text = (
                      format(cm_pct[i, j], fmt)
                      + "  ["
                      + str(cm[i, j])
                      + "]"
                  )
                  ax.text(
                      j,
                      i,
                      cm_text,
                      ha="center",
                      va="center",
                      color="white"
                      if cm_pct[i, j] >= thresh
                      else "black",
                  )
  
          # show the color bar
          im = ax.imshow(cm_pct, interpolation="nearest", cmap=cmap)
          ax.figure.colorbar(im, ax=ax)
  
          # save the chart
          tag = USEP.join([pstring, algo])
          write_plot("matplotlib", plt, "confusion", tag, plot_dir)
  
imports: from alphapy.estimators import get_estimators
  from alphapy.globals import BSEP, PSEP, SSEP, USEP
  from alphapy.globals import ModelType
  from alphapy.globals import Partition, datasets
  from alphapy.globals import Q1, Q3
  from alphapy.utilities import remove_list_items
  from bokeh.plotting import figure, show, output_file
  import itertools
  import logging
  import math
  import matplotlib
  import matplotlib.pyplot
  from mpl_toolkits.mplot3d import Axes3D
  import numpy
  import pandas
  from scipy import interp
  import seaborn
  from sklearn.calibration import calibration_curve
  from sklearn.inspection import partial_dependence
  from sklearn.inspection import plot_partial_dependence
  from sklearn.metrics import auc
  from sklearn.metrics import confusion_matrix
  from sklearn.metrics import roc_curve
  from sklearn.model_selection import cross_val_score
  from sklearn.model_selection import learning_curve
  from sklearn.model_selection import StratifiedKFold
  from sklearn.model_selection import train_test_split
  from sklearn.model_selection import validation_curve
  from sklearn.utils.multiclass import unique_labels
label_desc: Use image node_id 9 for calling a global function with example usage: plot_confusion_matrix(model, partition) and returns: None