
    -iC                     h    S SK Jr  S SKrSSKJr  SSKJr  SSKJ	r	  SSK
Jr  SS	KJr   " S
 S5      rg)    )productN   )is_classifier)check_matplotlib_support)_validate_style_kwargs)unique_labels   )confusion_matrixc                       \ rS rSrSrSS.S jrSSSSSSSSS	.S
 jr\SSSSSSSSSSSSS.S j5       r\SSSSSSSSSSSSS.S j5       r	Sr
g)ConfusionMatrixDisplay   a  Confusion Matrix visualization.

It is recommended 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.

For general information regarding `scikit-learn` visualization tools, see
the :ref:`Visualization Guide <visualizations>`.
For guidance on interpreting these plots, refer to the
:ref:`Model Evaluation Guide <confusion_matrix>`.

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()
N)display_labelsc                    Xl         X l        g )Nr
   r   )selfr
   r   s      Y/var/www/html/venv/lib/python3.13/site-packages/sklearn/metrics/_plot/confusion_matrix.py__init__ConfusionMatrixDisplay.__init__T   s     0,    Tviridis
horizontal)include_valuescmapxticks_rotationvalues_formataxcolorbarim_kwtext_kwc          	         [        S5        SSKJn	  Uc  U	R                  5       u  pOUR                  n
U R
                  nUR                  S   n[        SUS9nU=(       d    0 n[        X5      nU=(       d    0 nUR                  " U40 UD6U l
        SU l        U R                  R                  S5      U R                  R                  S5      pU(       Ga  [        R                  " U[        S9U l        UR!                  5       UR#                  5       -   S-  n[%        ['        U5      ['        U5      5       H  u  nnUUU4   U:  a  UOUnUcW  [)        UUU4   S	5      nUR*                  R,                  S
:w  a+  [)        UUU4   S5      n[/        U5      [/        U5      :  a  UnO[)        UUU4   U5      n[        SSUS9n[        UU5      nUR0                  " UUU40 UD6U R                  UU4'   M     U R2                  c  [        R4                  " U5      nOU R2                  nU(       a  U
R7                  U R                  US9  UR9                  [        R4                  " U5      [        R4                  " U5      UUSSS9  UR;                  US-
  S45        U	R=                  UR?                  5       US9  Xl         XPl!        U $ )at  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.
zConfusionMatrixDisplay.plotr   Nnearest)interpolationr   g      ?)dtypeg       @z.2gfdcenter)havacolor)r   z
True labelzPredicted label)xticksyticksxticklabelsyticklabelsylabelxlabelg      ?g      )rotation)"r   matplotlib.pyplotpyplotsubplotsfigurer
   shapedictr   imshowim_text_r   np
empty_likeobjectmaxminr   rangeformatr#   kindlentextr   aranger   setset_ylimsetpget_xticklabelsfigure_ax_)r   r   r   r   r   r   r   r   r   pltfigcm	n_classesdefault_im_kwcmap_mincmap_maxthreshijr)   text_cmtext_ddefault_text_kwargstext_kwargsr   s                            r   plotConfusionMatrixDisplay.plotX   sm   f 	!!>?':llnGC))C""HHQK	94@&}<-R99R)5)
!XX]]1-txx}}S/A(r8DJ ffh)S0Fi 0%	2BC1$&q!tHv$58 ($R1Xu5Gxx}}+!'1a4#!6v;W5&,G$R1X}=G&*h85&Q#45H'R#%771a#HK#H

1a4  D" &YYy1N!00NLLbL)
99Y'99Y'&&$ 	 	
 	Y_d+,##%@r   )labelssample_weight	normalizer   r   r   r   r   r   r   r   r   c                    U R                    S3n[        U5        [        U5      (       d  [        U S35      eUR	                  U5      nU R                  UUUUUUUUUU	U
UUUS9$ )a  Plot Confusion Matrix given an estimator and some data.

For general information regarding `scikit-learn` visualization tools, see
the :ref:`Visualization Guide <visualizations>`.
For guidance on interpreting these plots, refer to the
:ref:`Model Evaluation Guide <confusion_matrix>`.

.. versionadded:: 1.0

Parameters
----------
estimator : estimator instance
    Fitted classifier or a fitted :class:`~sklearn.pipeline.Pipeline`
    in which the last estimator is a classifier.

X : {array-like, sparse matrix} of shape (n_samples, n_features)
    Input values.

y : array-like of shape (n_samples,)
    Target values.

labels : array-like of shape (n_classes,), default=None
    List of labels to index the confusion matrix. This may be used to
    reorder or select a subset of labels. If `None` is given, those
    that appear at least once in `y_true` or `y_pred` are used in
    sorted order.

sample_weight : array-like of shape (n_samples,), default=None
    Sample weights.

normalize : {'true', 'pred', 'all'}, default=None
    Either to normalize the counts display in the matrix:

    - if `'true'`, the confusion matrix is normalized over the true
      conditions (e.g. rows);
    - if `'pred'`, the confusion matrix is normalized over the
      predicted conditions (e.g. columns);
    - if `'all'`, the confusion matrix is normalized by the total
      number of samples;
    - if `None` (default), the confusion matrix will not be normalized.

display_labels : array-like of shape (n_classes,), default=None
    Target names used for plotting. By default, `labels` will be used
    if it is defined, otherwise the unique labels of `y_true` and
    `y_pred` will be used.

include_values : bool, default=True
    Includes values in confusion matrix.

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.

cmap : str or matplotlib Colormap, default='viridis'
    Colormap recognized by matplotlib.

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`

See Also
--------
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 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)
>>> ConfusionMatrixDisplay.from_estimator(
...     clf, X_test, y_test)
<...>
>>> plt.show()

For a detailed example of using a confusion matrix to evaluate a
Support Vector Classifier, please see
:ref:`sphx_glr_auto_examples_model_selection_plot_confusion_matrix.py`
z.from_estimatorz only supports classifiers)r\   r[   r]   r   r   r   r   r   r   r   r   r   )__name__r   r   
ValueErrorpredictfrom_predictions)cls	estimatorXyr[   r\   r]   r   r   r   r   r   r   r   r   r   method_namey_preds                     r   from_estimator%ConfusionMatrixDisplay.from_estimator   s    | o6 -Y''},FGHH""1%##'))+' $ 
 	
r   c                    [        U R                   S35        Uc  Uc  [        X5      nOUn[        UUUUUS9nU " XS9nUR	                  UU
UUU	UUUS9$ )a  Plot Confusion Matrix given true and predicted labels.

For general information regarding `scikit-learn` visualization tools, see
the :ref:`Visualization Guide <visualizations>`.
For guidance on interpreting these plots, refer to the
:ref:`Model Evaluation Guide <confusion_matrix>`.

.. versionadded:: 1.0

Parameters
----------
y_true : array-like of shape (n_samples,)
    True labels.

y_pred : array-like of shape (n_samples,)
    The predicted labels given by the method `predict` of an
    classifier.

labels : array-like of shape (n_classes,), default=None
    List of labels to index the confusion matrix. This may be used to
    reorder or select a subset of labels. If `None` is given, those
    that appear at least once in `y_true` or `y_pred` are used in
    sorted order.

sample_weight : array-like of shape (n_samples,), default=None
    Sample weights.

normalize : {'true', 'pred', 'all'}, default=None
    Either to normalize the counts display in the matrix:

    - if `'true'`, the confusion matrix is normalized over the true
      conditions (e.g. rows);
    - if `'pred'`, the confusion matrix is normalized over the
      predicted conditions (e.g. columns);
    - if `'all'`, the confusion matrix is normalized by the total
      number of samples;
    - if `None` (default), the confusion matrix will not be normalized.

display_labels : array-like of shape (n_classes,), default=None
    Target names used for plotting. By default, `labels` will be used
    if it is defined, otherwise the unique labels of `y_true` and
    `y_pred` will be used.

include_values : bool, default=True
    Includes values in confusion matrix.

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.

cmap : str or matplotlib Colormap, default='viridis'
    Colormap recognized by matplotlib.

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`

See Also
--------
ConfusionMatrixDisplay.from_estimator : Plot the confusion matrix
    given an estimator, the data, and the label.

Examples
--------
>>> import matplotlib.pyplot as plt
>>> from sklearn.datasets import make_classification
>>> from sklearn.metrics import 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)
>>> y_pred = clf.predict(X_test)
>>> ConfusionMatrixDisplay.from_predictions(
...    y_test, y_pred)
<...>
>>> plt.show()
z.from_predictions)r\   r[   r]   r   )r   r   r   r   r   r   r   r   )r   r_   r   r
   rY   )rc   y_truerh   r[   r\   r]   r   r   r   r   r   r   r   r   r   rM   disps                    r   rb   'ConfusionMatrixDisplay.from_predictionsa  s    n 	!CLL>1B!CD!~!.v!>!''
 BFyy)+'  	
 		
r   )rJ   r
   r   rI   r8   r9   )r_   
__module____qualname____firstlineno____doc__r   rY   classmethodri   rb   __static_attributes__ r   r   r   r      s    BH <@ - $rh  $#R
 R
h  $!Q
 Q
r   r   )	itertoolsr   numpyr:   baser   utils._optional_dependenciesr   utils._plottingr   utils.multiclassr    r
   r   ru   r   r   <module>r}      s(      ! D 5 - d
 d
r   