code: def confusion_matrix(
      estimator,
      X_train,
      y_train,
      X_test=None,
      y_test=None,
      ax=None,
      sample_weight=None,
      percent=False,
      classes=None,
      encoder=None,
      cmap="YlOrRd",
      fontsize=None,
      is_fitted="auto",
      force_model=False,
      show=True,
      **kwargs,
  ):
      """Confusion Matrix
  
      Creates a heatmap visualization of the sklearn.metrics.confusion_matrix().
      A confusion matrix shows each combination of the true and predicted
      classes for a test data set.
  
      The default color map uses a yellow/orange/red color scale. The user can
      choose between displaying values as the percent of true (cell value
      divided by sum of row) or as direct counts. If percent of true mode is
      selected, 100% accurate predictions are highlighted in green.
  
      Requires a classification model.
  
      Parameters
      ----------
      estimator : estimator
          A scikit-learn estimator that should be a classifier. If the model is
          not a classifier, an exception is raised. If the internal model is not
          fitted, it is fit when the visualizer is fitted, unless otherwise specified
          by ``is_fitted``.
  
      X_train : array-like, 2D
          The table of instance data or independent variables that describe the outcome of
          the dependent variable, y. Used to fit the visualizer and also to score the
          visualizer if test splits are not specified.
  
      y_train : array-like, 2D
          The vector of target data or the dependent variable predicted by X. Used to fit
          the visualizer and also to score the visualizer if test splits are not
          specified.
  
      X_test: array-like, 2D, default: None
          The table of instance data or independent variables that describe the outcome of
          the dependent variable, y. Used to score the visualizer if specified.
  
      y_test: array-like, 1D, default: None
          The vector of target data or the dependent variable predicted by X. Used to
          score the visualizer if specified.
  
      ax : matplotlib Axes, default: None
          The axes to plot the figure on. If not specified the current axes will be
          used (or generated if required).
  
      sample_weight: array-like of shape = [n_samples], optional
          Passed to ``confusion_matrix`` to weight the samples.
  
      percent: bool, default: False
          Determines whether or not the confusion_matrix is displayed as counts
          or as a percent of true predictions. Note, if specifying a subset of
          classes, percent should be set to False or inaccurate figures will be
          displayed.
  
      classes : list of str, defult: None
          The class labels to use for the legend ordered by the index of the sorted
          classes discovered in the ``fit()`` method. Specifying classes in this
          manner is used to change the class names to a more specific format or
          to label encoded integer classes. Some visualizers may also use this
          field to filter the visualization for specific classes. For more advanced
          usage specify an encoder rather than class labels.
  
      encoder : dict or LabelEncoder, default: None
          A mapping of classes to human readable labels. Often there is a mismatch
          between desired class labels and those contained in the target variable
          passed to ``fit()`` or ``score()``. The encoder disambiguates this mismatch
          ensuring that classes are labeled correctly in the visualization.
  
      cmap : string, default: ``'YlOrRd'``
          Specify a colormap to define the heatmap of the predicted class
          against the actual class in the confusion matrix.
  
      fontsize : int, default: None
          Specify the fontsize of the text in the grid and labels to make the
          matrix a bit easier to read. Uses rcParams font size by default.
  
      is_fitted : bool or str, default="auto"
          Specify if the wrapped estimator is already fitted. If False, the estimator
          will be fit when the visualizer is fit, otherwise, the estimator will not be
          modified. If "auto" (default), a helper method will check if the estimator
          is fitted before fitting it again.
  
      force_model : bool, default: False
          Do not check to ensure that the underlying estimator is a classifier. This
          will prevent an exception when the visualizer is initialized but may result
          in unexpected or unintended behavior.
  
      show: bool, default: True
          If True, calls ``show()``, which in turn calls ``plt.show()`` however you cannot
          call ``plt.savefig`` from this signature, nor ``clear_figure``. If False, simply
          calls ``finalize()``
  
      kwargs : dict
          Keyword arguments passed to the visualizer base classes.
  
      Returns
      -------
      viz : ConfusionMatrix
          Returns the fitted, finalized visualizer
      """
      # Instantiate the visualizer
      visualizer = ConfusionMatrix(
          estimator=estimator,
          ax=ax,
          sample_weight=sample_weight,
          percent=percent,
          classes=classes,
          encoder=encoder,
          cmap=cmap,
          fontsize=fontsize,
          is_fitted=is_fitted,
          force_model=force_model,
          **kwargs,
      )
  
      # Fit and transform the visualizer (calls draw)
      visualizer.fit(X_train, y_train, **kwargs)
  
      # Scores the visualizer with X_test and y_test if provided,
      # X_train, y_train if not provided
      if X_test is not None and y_test is not None:
          visualizer.score(X_test, y_test)
      else:
          visualizer.score(X_train, y_train)
  
      if show:
          visualizer.show()
      else:
          visualizer.finalize()
  
      # Return the visualizer
      return visualizer
  
file_path: yellowbrick/yellowbrick/classifier/confusion_matrix.py
imports: import numpy
  from sklearn.metrics import confusion_matrix
  from yellowbrick.utils import div_safe
  from yellowbrick.style import find_text_color
  from yellowbrick.style.palettes import color_sequence
  from yellowbrick.classifier.base import ClassificationScoreVisualizer
label_desc: Use image node_id 1 for calling a global function with example usage: confusion_matrix(estimator, X_train, y_train, X_test, y_test, ax, sample_weight, percent, classes, encoder, cmap, fontsize, is_fitted, force_model, show) and returns: visualizer