code: def confusion_matrix_plot(
      confusion_matrix,
      labels=None,
      output_feature_name=None,
      filename=None,
      callbacks=None,
  ):
      mpl.rcParams.update({"figure.autolayout": True})
  
      # Dynamically set the size of the plot based on the number of labels
      # Use minimum size to prevent plot from being too small
      default_width, default_height = plt.rcParams.get("figure.figsize")
      width = max(default_width, len(labels))
      height = max(default_height, len(labels))
      fig, ax = plt.subplots(figsize=(width, height))
  
      ax.invert_yaxis()
      ax.xaxis.tick_top()
      ax.xaxis.set_label_position("top")
  
      # Set alpha value to prevent blue hues from being too dark
      cax = ax.matshow(confusion_matrix, cmap="Blues", alpha=0.6)
      # Annotate confusion matrix plot
      for (i, j), z in np.ndenumerate(confusion_matrix):
          # Format differently based on whether the value is normalized or not
          if z.is_integer():
              z_format = f"{z:.0f}"
          else:
              z_format = f"{z:.3f}"
          ax.text(
              j,
              i,
              z_format,
              ha="center",
              va="center",
              color="black",
              fontweight="medium",
              wrap=True,
          )
  
      ax.xaxis.set_major_locator(ticker.MultipleLocator(1))
      ax.yaxis.set_major_locator(ticker.MultipleLocator(1))
      ax.set_xticklabels([""] + labels, rotation=45, ha="left")
      ax.set_yticklabels([""] + labels, rotation=45, ha="right")
      ax.grid(False)
      ax.tick_params(axis="both", which="both", length=0)
      # https://stackoverflow.com/a/26720422/10102370 works nicely for square plots
      fig.colorbar(cax, ax=ax, extend="max", fraction=0.046, pad=0.04)
      ax.set_xlabel(f"Predicted {output_feature_name}")
      ax.set_ylabel(f"Actual {output_feature_name}")
  
      plt.tight_layout()
      visualize_callbacks(callbacks, plt.gcf())
      if filename:
          plt.savefig(filename, bbox_inches="tight")
      else:
          plt.show()
  
imports: import copy
  import logging
  from collections import Counter
  from sys import platform
  from typing import Dict, List
  import numpy
  import pandas
  import ptitprince
  from packaging import version
  from ludwig.constants import SPACE, TRAINING, VALIDATION
label_desc: Use image node_id 19 for calling a global function with example usage: confusion_matrix_plot(confusion_matrix, labels, output_feature_name, filename, callbacks) without return types