class_docstr: Confusion Matrix visualization.
  
  It is recommend to use
  :func:`~sklearn.metrics.ConfusionMatrixDisplay.from_estimator` or
  :func:`~sklearn.metrics.ConfusionMatrixDisplay.from_predictions` to
  create a :class:`ConfusionMatrixDisplay`. All parameters are stored as
  attributes.
  
  Read more in the :ref:`User Guide <visualizations>`.
  
  Parameters
  ----------
  confusion_matrix : ndarray of shape (n_classes, n_classes)
      Confusion matrix.
  
  display_labels : ndarray of shape (n_classes,), default=None
      Display labels for plot. If None, display labels are set from 0 to
      `n_classes - 1`.
  
  Attributes
  ----------
  im_ : matplotlib AxesImage
      Image representing the confusion matrix.
  
  text_ : ndarray of shape (n_classes, n_classes), dtype=matplotlib Text,             or None
      Array of matplotlib axes. `None` if `include_values` is false.
  
  ax_ : matplotlib Axes
      Axes with confusion matrix.
  
  figure_ : matplotlib Figure
      Figure containing the confusion matrix.
  
  See Also
  --------
  confusion_matrix : Compute Confusion Matrix to evaluate the accuracy of a
      classification.
  ConfusionMatrixDisplay.from_estimator : Plot the confusion matrix
      given an estimator, the data, and the label.
  ConfusionMatrixDisplay.from_predictions : Plot the confusion matrix
      given the true and predicted labels.
  
  Examples
  --------
  >>> import matplotlib.pyplot as plt
  >>> from sklearn.datasets import make_classification
  >>> from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay
  >>> from sklearn.model_selection import train_test_split
  >>> from sklearn.svm import SVC
  >>> X, y = make_classification(random_state=0)
  >>> X_train, X_test, y_train, y_test = train_test_split(X, y,
  ...                                                     random_state=0)
  >>> clf = SVC(random_state=0)
  >>> clf.fit(X_train, y_train)
  SVC(random_state=0)
  >>> predictions = clf.predict(X_test)
  >>> cm = confusion_matrix(y_test, predictions, labels=clf.classes_)
  >>> disp = ConfusionMatrixDisplay(confusion_matrix=cm,
  ...                               display_labels=clf.classes_)
  >>> disp.plot()
  <...>
  >>> plt.show()
class_docstr_tok: ["Confusion","Matrix","visualization",".","It","is","recommend","to","use",":","func",":","`","~sklearn.metrics.ConfusionMatrixDisplay.from_estimator","`","or",":","func",":","`","~sklearn.metrics.ConfusionMatrixDisplay.from_predictions","`","to","create","a",":","class",":","`","ConfusionMatrixDisplay","`",".","All","parameters","are","stored","as","attributes",".","Read","more","in","the",":","ref",":","`","User","Guide","<","visualizations",">","`",".","Parameters","--","--","--","--","--","confusion_matrix",":","ndarray","of","shape","(","n_classes",",","n_classes",")","Confusion","matrix",".","display_labels",":","ndarray","of","shape","(","n_classes",",",")",",","default=None","Display","labels","for","plot",".","If","None",",","display","labels","are","set","from","0","to","`","n_classes","-","1","`",".","Attributes","--","--","--","--","--","im_",":","matplotlib","AxesImage","Image","representing","the","confusion","matrix",".","text_",":","ndarray","of","shape","(","n_classes",",","n_classes",")",",","dtype=matplotlib","Text",",","or","None","Array","of","matplotlib","axes",".","`","None","`","if","`","include_values","`","is","false",".","ax_",":","matplotlib","Axes","Axes","with","confusion","matrix",".","figure_",":","matplotlib","Figure","Figure","containing","the","confusion","matrix",".","See","Also","--","--","--","--","confusion_matrix",":","Compute","Confusion","Matrix","to","evaluate","the","accuracy","of","a","classification",".","ConfusionMatrixDisplay.from_estimator",":","Plot","the","confusion","matrix","given","an","estimator",",","the","data",",","and","the","label",".","ConfusionMatrixDisplay.from_predictions",":","Plot","the","confusion","matrix","given","the","true","and","predicted","labels",".","Examples","--","--","--","--",">",">",">","import","matplotlib.pyplot","as","plt",">",">",">","from","sklearn.datasets","import","make_classification",">",">",">","from","sklearn.metrics","import","confusion_matrix",",","ConfusionMatrixDisplay",">",">",">","from","sklearn.model_selection","import","train_test_split",">",">",">","from","sklearn.svm","import","SVC",">",">",">","X",",","y","=","make_classification","(","random_state=0",")",">",">",">","X_train",",","X_test",",","y_train",",","y_test","=","train_test_split","(","X",",","y",",","...","random_state=0",")",">",">",">","clf","=","SVC","(","random_state=0",")",">",">",">","clf.fit","(","X_train",",","y_train",")","SVC","(","random_state=0",")",">",">",">","predictions","=","clf.predict","(","X_test",")",">",">",">","cm","=","confusion_matrix","(","y_test",",","predictions",",","labels=clf.classes_",")",">",">",">","disp","=","ConfusionMatrixDisplay","(","confusion_matrix=cm",",","...","display_labels=clf.classes_",")",">",">",">","disp.plot","(",")","<","...",">",">",">",">","plt.show","(",")"]
docstr: Plot visualization.
  
  Parameters
  ----------
  include_values : bool, default=True
      Includes values in confusion matrix.
  
  cmap : str or matplotlib Colormap, default='viridis'
      Colormap recognized by matplotlib.
  
  xticks_rotation : {'vertical', 'horizontal'} or float,                          default='horizontal'
      Rotation of xtick labels.
  
  values_format : str, default=None
      Format specification for values in confusion matrix. If `None`,
      the format specification is 'd' or '.2g' whichever is shorter.
  
  ax : matplotlib axes, default=None
      Axes object to plot on. If `None`, a new figure and axes is
      created.
  
  colorbar : bool, default=True
      Whether or not to add a colorbar to the plot.
  
  im_kw : dict, default=None
      Dict with keywords passed to `matplotlib.pyplot.imshow` call.
  
  text_kw : dict, default=None
      Dict with keywords passed to `matplotlib.pyplot.text` call.
  
      .. versionadded:: 1.2
  
  Returns
  -------
  display : :class:`~sklearn.metrics.ConfusionMatrixDisplay`
      Returns a :class:`~sklearn.metrics.ConfusionMatrixDisplay` instance
      that contains all the information to plot the confusion matrix.
docstr_tok: ["Plot","visualization",".","Parameters","--","--","--","--","--","include_values",":","bool",",","default=True","Includes","values","in","confusion","matrix",".","cmap",":","str","or","matplotlib","Colormap",",","default='viridis'","Colormap","recognized","by","matplotlib",".","xticks_rotation",":","{","'vertical","'",",","'horizontal","'","}","or","float",",","default='horizontal'","Rotation","of","xtick","labels",".","values_format",":","str",",","default=None","Format","specification","for","values","in","confusion","matrix",".","If","`","None","`",",","the","format","specification","is","'d","'","or","'.2g","'","whichever","is","shorter",".","ax",":","matplotlib","axes",",","default=None","Axes","object","to","plot","on",".","If","`","None","`",",","a","new","figure","and","axes","is","created",".","colorbar",":","bool",",","default=True","Whether","or","not","to","add","a","colorbar","to","the","plot",".","im_kw",":","dict",",","default=None","Dict","with","keywords","passed","to","`","matplotlib.pyplot.imshow","`","call",".","text_kw",":","dict",",","default=None","Dict","with","keywords","passed","to","`","matplotlib.pyplot.text","`","call",".","..","versionadded",":",":","1.2","Returns","--","--","--","-","display",":",":","class",":","`","~sklearn.metrics.ConfusionMatrixDisplay","`","Returns","a",":","class",":","`","~sklearn.metrics.ConfusionMatrixDisplay","`","instance","that","contains","all","the","information","to","plot","the","confusion","matrix","."]
code: def plot(
      self,
      *,
      include_values=True,
      cmap="viridis",
      xticks_rotation="horizontal",
      values_format=None,
      ax=None,
      colorbar=True,
      im_kw=None,
      text_kw=None,
  ):
      """Plot visualization.
  
          Parameters
          ----------
          include_values : bool, default=True
              Includes values in confusion matrix.
  
          cmap : str or matplotlib Colormap, default='viridis'
              Colormap recognized by matplotlib.
  
          xticks_rotation : {'vertical', 'horizontal'} or float, \
                           default='horizontal'
              Rotation of xtick labels.
  
          values_format : str, default=None
              Format specification for values in confusion matrix. If `None`,
              the format specification is 'd' or '.2g' whichever is shorter.
  
          ax : matplotlib axes, default=None
              Axes object to plot on. If `None`, a new figure and axes is
              created.
  
          colorbar : bool, default=True
              Whether or not to add a colorbar to the plot.
  
          im_kw : dict, default=None
              Dict with keywords passed to `matplotlib.pyplot.imshow` call.
  
          text_kw : dict, default=None
              Dict with keywords passed to `matplotlib.pyplot.text` call.
  
              .. versionadded:: 1.2
  
          Returns
          -------
          display : :class:`~sklearn.metrics.ConfusionMatrixDisplay`
              Returns a :class:`~sklearn.metrics.ConfusionMatrixDisplay` instance
              that contains all the information to plot the confusion matrix.
          """
      check_matplotlib_support("ConfusionMatrixDisplay.plot")
      import matplotlib.pyplot as plt
  
      if ax is None:
          fig, ax = plt.subplots()
      else:
          fig = ax.figure
  
      cm = self.confusion_matrix
      n_classes = cm.shape[0]
  
      default_im_kw = dict(interpolation="nearest", cmap=cmap)
      im_kw = im_kw or {}
      im_kw = {**default_im_kw, **im_kw}
      text_kw = text_kw or {}
  
      self.im_ = ax.imshow(cm, **im_kw)
      self.text_ = None
      cmap_min, cmap_max = self.im_.cmap(0), self.im_.cmap(1.0)
  
      if include_values:
          self.text_ = np.empty_like(cm, dtype=object)
  
          # print text with appropriate color depending on background
          thresh = (cm.max() + cm.min()) / 2.0
  
          for i, j in product(range(n_classes), range(n_classes)):
              color = cmap_max if cm[i, j] < thresh else cmap_min
  
              if values_format is None:
                  text_cm = format(cm[i, j], ".2g")
                  if cm.dtype.kind != "f":
                      text_d = format(cm[i, j], "d")
                      if len(text_d) < len(text_cm):
                          text_cm = text_d
              else:
                  text_cm = format(cm[i, j], values_format)
  
              default_text_kwargs = dict(
                  ha="center", va="center", color=color
              )
              text_kwargs = {**default_text_kwargs, **text_kw}
  
              self.text_[i, j] = ax.text(j, i, text_cm, **text_kwargs)
  
      if self.display_labels is None:
          display_labels = np.arange(n_classes)
      else:
          display_labels = self.display_labels
      if colorbar:
          fig.colorbar(self.im_, ax=ax)
      ax.set(
          xticks=np.arange(n_classes),
          yticks=np.arange(n_classes),
          xticklabels=display_labels,
          yticklabels=display_labels,
          ylabel="True label",
          xlabel="Predicted label",
      )
  
      ax.set_ylim((n_classes - 0.5, -0.5))
      plt.setp(ax.get_xticklabels(), rotation=xticks_rotation)
  
      self.figure_ = fig
      self.ax_ = ax
      return self
  
file_path: scikit-learn/sklearn/metrics/_plot/confusion_matrix.py
imports: from itertools import product
  import numpy
  from ...base import is_classifier
  from ...utils import check_matplotlib_support
  from ...utils.multiclass import unique_labels
  from ..None import confusion_matrix
label_desc: Use image node_id 2 for calling the ConfusionMatrixDisplay obj's underlying member method code with example usage: obj.plot() and returns: self