
    -i8V                         S SK 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KJr  SS	KJrJrJrJrJr  S
 r " S S5      rg)    N   )is_regressor)LabelEncoder)_safe_indexing)check_matplotlib_support)_get_response_values)_get_adapter_from_container)_is_arraylike_not_scalar_is_pandas_df_is_polars_df_num_featurescheck_is_fittedc                     [        U S5      nU(       a*  [        U R                  S   5      (       a  Sn[        U5      eUS:X  a  [	        U 5      (       a  SnU$ / SQn U$ UnU$ )a  Validate the response methods to be used with the fitted estimator.

Parameters
----------
estimator : object
    Fitted estimator to check.

response_method : {'auto', 'decision_function', 'predict_proba', 'predict'}
    Specifies whether to use :term:`decision_function`, :term:`predict_proba`,
    :term:`predict` as the target response. If set to 'auto', the response method is
    tried in the before mentioned order.

class_of_interest : int, float, bool, str or None
    The class considered when plotting the decision. Cannot be None if
    multiclass and `response_method` is 'predict_proba' or 'decision_function'.

    .. versionadded:: 1.4

Returns
-------
prediction_method : list of str or str
    The name or list of names of the response methods to use.
classes_r   zFMulti-label and multi-output multi-class classifiers are not supportedautopredict)decision_functionpredict_probar   )hasattrr
   r   
ValueErrorr   )	estimatorresponse_methodclass_of_interesthas_classesmsgprediction_methods         ]/var/www/html/venv/lib/python3.13/site-packages/sklearn/inspection/_plot/decision_boundary.py_check_boundary_response_methodr      sx    0 )Z0K/	0B0B10EFFVo& 	"" ) 	 !R  ,    c                   \    \ rS rSrSrSSSS.S jrSS jr\SS	SS
SSSSSS.	S j5       rSr	g)DecisionBoundaryDisplay?   aY  Decisions boundary visualization.

It is recommended to use
:func:`~sklearn.inspection.DecisionBoundaryDisplay.from_estimator`
to create a :class:`DecisionBoundaryDisplay`. All parameters are stored as
attributes.

Read more in the :ref:`User Guide <visualizations>`.

For a detailed example comparing the decision boundaries of multinomial and
one-vs-rest logistic regression, please see
:ref:`sphx_glr_auto_examples_linear_model_plot_logistic_multinomial.py`.

.. versionadded:: 1.1

Parameters
----------
xx0 : ndarray of shape (grid_resolution, grid_resolution)
    First output of :func:`meshgrid <numpy.meshgrid>`.

xx1 : ndarray of shape (grid_resolution, grid_resolution)
    Second output of :func:`meshgrid <numpy.meshgrid>`.

response : ndarray of shape (grid_resolution, grid_resolution) or             (grid_resolution, grid_resolution, n_classes)
    Values of the response function.

multiclass_colors : list of str or str, default=None
    Specifies how to color each class when plotting all classes of multiclass
    problem. Ignored for binary problems and multiclass problems when plotting a
    single prediction value per point.
    Possible inputs are:

    * list: list of Matplotlib
      `color <https://matplotlib.org/stable/users/explain/colors/colors.html#colors-def>`_
      strings, of length `n_classes`
    * str: name of :class:`matplotlib.colors.Colormap`
    * None: 'viridis' colormap is used to sample colors

    Single color colormaps will be generated from the colors in the list or
    colors taken from the colormap and passed to the `cmap` parameter of
    the `plot_method`.

    .. versionadded:: 1.7

xlabel : str, default=None
    Default label to place on x axis.

ylabel : str, default=None
    Default label to place on y axis.

Attributes
----------
surface_ : matplotlib `QuadContourSet` or `QuadMesh` or list of such objects
    If `plot_method` is 'contour' or 'contourf', `surface_` is
    :class:`QuadContourSet <matplotlib.contour.QuadContourSet>`. If
    `plot_method` is 'pcolormesh', `surface_` is
    :class:`QuadMesh <matplotlib.collections.QuadMesh>`.

multiclass_colors_ : array of shape (n_classes, 4)
    Colors used to plot each class in multiclass problems.
    Only defined when `color_of_interest` is None.

    .. versionadded:: 1.7

ax_ : matplotlib Axes
    Axes with decision boundary.

figure_ : matplotlib Figure
    Figure containing the decision boundary.

See Also
--------
DecisionBoundaryDisplay.from_estimator : Plot decision boundary given an estimator.

Examples
--------
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from sklearn.datasets import load_iris
>>> from sklearn.inspection import DecisionBoundaryDisplay
>>> from sklearn.tree import DecisionTreeClassifier
>>> iris = load_iris()
>>> feature_1, feature_2 = np.meshgrid(
...     np.linspace(iris.data[:, 0].min(), iris.data[:, 0].max()),
...     np.linspace(iris.data[:, 1].min(), iris.data[:, 1].max())
... )
>>> grid = np.vstack([feature_1.ravel(), feature_2.ravel()]).T
>>> tree = DecisionTreeClassifier().fit(iris.data[:, :2], iris.target)
>>> y_pred = np.reshape(tree.predict(grid), feature_1.shape)
>>> display = DecisionBoundaryDisplay(
...     xx0=feature_1, xx1=feature_2, response=y_pred
... )
>>> display.plot()
<...>
>>> display.ax_.scatter(
...     iris.data[:, 0], iris.data[:, 1], c=iris.target, edgecolor="black"
... )
<...>
>>> plt.show()
N)multiclass_colorsxlabelylabelc                L    Xl         X l        X0l        X@l        XPl        X`l        g Nxx0xx1responser#   r$   r%   )selfr)   r*   r+   r#   r$   r%   s          r   __init__ DecisionBoundaryDisplay.__init__   s#      !2r   contourfc                 "   [        S5        SSKnSSKJn  US;  a  [	        SU S35      eUc  UR                  5       u  p[        X!5      n	U R                  R                  S:X  a0  U	" U R                  U R                  U R                  40 UD6U l        GOU R                  R                  S   n
S	 H&  nX;   d  M
  [        R                  " S
U S35        X[	 M(     U R                  b  [!        U R                  ["        5      (       a  U R                  c  U
S::  a  SOSnOU R                  nUS:X  a&  U
S::  a   UR%                  SS5      R&                  SU
 nOUS:X  a&  U
S::  a   UR%                  SS5      R&                  SU
 nOUR%                  X5      n[)        US5      (       d  U" [*        R,                  " SSU
5      5      nOlUR&                  nO_[!        U R                  [.        5      (       a5  U R                   Vs/ s H  oR&                  R1                  U5      PM     nnO[	        S5      eXl        US:X  a@  U R                  R5                  SS9nU	" U R                  U R                  U4SU0UD6U l        O[7        U5       VVVVVs/ s H:  u  nu  nnnnUR&                  R8                  R;                  SU 3SUUUS4/5      PM<     nnnnnn/ U l        [7        U5       H  u  nn[*        R<                  R?                  U R                  SS2SS2U4   U R                  R5                  SS9U:H  ) S9nU R                  RA                  U	" U R                  U R                  U4SU0UD65        M     Uc  URC                  5       (       d"  Uc  U RD                  OUnURG                  U5        Uc  URI                  5       (       d"  Uc  U RJ                  OUnURM                  U5        X l'        URP                  U l)        U $ s  snf s  snnnnnf )aC  Plot visualization.

Parameters
----------
plot_method : {'contourf', 'contour', 'pcolormesh'}, default='contourf'
    Plotting method to call when plotting the response. Please refer
    to the following matplotlib documentation for details:
    :func:`contourf <matplotlib.pyplot.contourf>`,
    :func:`contour <matplotlib.pyplot.contour>`,
    :func:`pcolormesh <matplotlib.pyplot.pcolormesh>`.

ax : Matplotlib axes, default=None
    Axes object to plot on. If `None`, a new figure and axes is
    created.

xlabel : str, default=None
    Overwrite the x-axis label.

ylabel : str, default=None
    Overwrite the y-axis label.

**kwargs : dict
    Additional keyword arguments to be passed to the `plot_method`.

Returns
-------
display: :class:`~sklearn.inspection.DecisionBoundaryDisplay`
    Object that stores computed values.
zDecisionBoundaryDisplay.plotr   Nr/   contour
pcolormeshz@plot_method must be 'contourf', 'contour', or 'pcolormesh'. Got 	 instead.   )cmapcolors'z' is ignored in favor of 'multiclass_colors' in the multiclass case when the response method is 'decision_function' or 'predict_proba'.
   tab10gist_rainbowtab20   r8      z,'multiclass_colors' must be a list or a str.r2   axis	colormap_)      ?rC   rC   rC   rC   )maskr7   )*r   
matplotlibmatplotlib.pyplotpyplotr   subplotsgetattrr+   ndimr)   r*   surface_shapewarningswarnr#   
isinstancestrget_cmapr8   r   nplinspacelistto_rgbamulticlass_colors_argmax	enumerateLinearSegmentedColormap	from_listmaarrayappend
get_xlabelr$   
set_xlabel
get_ylabelr%   
set_ylabelax_figurefigure_)r,   plot_methodaxr$   r%   kwargsmplplt_	plot_funcn_responseskwargr7   r8   color	class_map	class_idxrgbmulticlass_cmapsr+   s                         r   plotDecisionBoundaryDisplay.plot   s   < 	!!?@ 'CC"m9. 
 :LLNEAB,	=="%dhh$--R6RDM----b1K+?MME7 #B B
  , %%-&&2 2 ))1&1R&77^D11D
 7?{b'8 \\'26==l{KFW_): \\'26==l{KF<<:D"422!%bkk!Q&D!E!%D22D99AEAWAWXAW**,,U3AWX !OPP&,#i' MM00a08	 )HHdhh	!:@!DJ! 4=V3D	$ 4E/	<Aq!Q JJ66@@#I;/2FAqRU1W 4E	 ! $ !#'01A'BOIt!uu{{aIo6#}}333;yHI  +  H MM((!$((DHHhTTTVT (C R]]__$*NT[[FMM&!R]]__$*NT[[FMM&!yyM Y$s   =$PAPd   rC   r   )	grid_resolutionepsre   r   r   r#   r$   r%   rf   c       	   	        ^# [        U R                   S35        [        U5        SSKm#US:  d  [	        SU S35      eUS:  d  [	        SU S35      eSnX];  a#  S	R                  U5      n[	        S
U SU S35      e[        U5      nUS:w  a  [	        SU S35      eUS;   a  Ub  [        US5      (       a  [        UR                  5      =nS:  a  [        U[        5      (       aR  [        U5      U:w  a  [	        SU S[        U5       S35      e[        U#4S jU 5       5      (       a  [	        SU 35      e[        U[        5      (       a,  UT#R                  R                  5       ;  a  [	        SU 35      e[!        USSS9[!        USSS9nnUR#                  5       U-
  UR%                  5       U-   nnUR#                  5       U-
  UR%                  5       U-   nn[&        R(                  " [&        R*                  " UUU5      [&        R*                  " UUU5      5      u  nn[&        R,                  UR/                  5       UR/                  5       4   n[1        U5      (       d  [3        U5      (       a&  [5        U5      nUR7                  UUUR8                  S9n[;        XU5      n [=        UUUUSS9u  nnnUS:X  a=  [        US5      (       a,  [?        5       n UR                  U l	        U RA                  U5      nURB                  S:X  a  URD                  " URF                  6 nO[I        U5      (       a  [	        S5      eUbG  [&        RJ                  " UR                  U:H  5      S   n!USS2U!4   RD                  " URF                  6 nO+URD                  " / URF                  QURF                  S   P76 nU	c"  [        US 5      (       a  UR8                  S   OS!n	U
c"  [        US 5      (       a  UR8                  S   OS!n
U " UUUUU	U
S"9n"U"RL                  " S$XS#.UD6$ ! [         a1  nS[        U5      ;   a  [	        SU SUR                   35      Uee SnAff = f)%a	  Plot decision boundary given an estimator.

Read more in the :ref:`User Guide <visualizations>`.

Parameters
----------
estimator : object
    Trained estimator used to plot the decision boundary.

X : {array-like, sparse matrix, dataframe} of shape (n_samples, 2)
    Input data that should be only 2-dimensional.

grid_resolution : int, default=100
    Number of grid points to use for plotting decision boundary.
    Higher values will make the plot look nicer but be slower to
    render.

eps : float, default=1.0
    Extends the minimum and maximum values of X for evaluating the
    response function.

plot_method : {'contourf', 'contour', 'pcolormesh'}, default='contourf'
    Plotting method to call when plotting the response. Please refer
    to the following matplotlib documentation for details:
    :func:`contourf <matplotlib.pyplot.contourf>`,
    :func:`contour <matplotlib.pyplot.contour>`,
    :func:`pcolormesh <matplotlib.pyplot.pcolormesh>`.

response_method : {'auto', 'decision_function', 'predict_proba',                 'predict'}, default='auto'
    Specifies whether to use :term:`decision_function`,
    :term:`predict_proba` or :term:`predict` as the target response.
    If set to 'auto', the response method is tried in the order as
    listed above.

    .. versionchanged:: 1.6
        For multiclass problems, 'auto' no longer defaults to 'predict'.

class_of_interest : int, float, bool or str, default=None
    The class to be plotted when `response_method` is 'predict_proba'
    or 'decision_function'. If None, `estimator.classes_[1]` is considered
    the positive class for binary classifiers. For multiclass
    classifiers, if None, all classes will be represented in the
    decision boundary plot; the class with the highest response value
    at each point is plotted. The color of each class can be set via
    `multiclass_colors`.

    .. versionadded:: 1.4

multiclass_colors : list of str, or str, default=None
    Specifies how to color each class when plotting multiclass
    'predict_proba' or 'decision_function' and `class_of_interest` is
    None. Ignored in all other cases.

    Possible inputs are:

    * list: list of Matplotlib
      `color <https://matplotlib.org/stable/users/explain/colors/colors.html#colors-def>`_
      strings, of length `n_classes`
    * str: name of :class:`matplotlib.colors.Colormap`
    * None: 'tab10' colormap is used to sample colors if the number of
        classes is less than or equal to 10, otherwise 'gist_rainbow'
        colormap.

    Single color colormaps will be generated from the colors in the list or
    colors taken from the colormap, and passed to the `cmap` parameter of
    the `plot_method`.

    .. versionadded:: 1.7

xlabel : str, default=None
    The label used for the x-axis. If `None`, an attempt is made to
    extract a label from `X` if it is a dataframe, otherwise an empty
    string is used.

ylabel : str, default=None
    The label used for the y-axis. If `None`, an attempt is made to
    extract a label from `X` if it is a dataframe, otherwise an empty
    string is used.

ax : Matplotlib axes, default=None
    Axes object to plot on. If `None`, a new figure and axes is
    created.

**kwargs : dict
    Additional keyword arguments to be passed to the
    `plot_method`.

Returns
-------
display : :class:`~sklearn.inspection.DecisionBoundaryDisplay`
    Object that stores the result.

See Also
--------
DecisionBoundaryDisplay : Decision boundary visualization.
sklearn.metrics.ConfusionMatrixDisplay.from_estimator : Plot the
    confusion matrix given an estimator, the data, and the label.
sklearn.metrics.ConfusionMatrixDisplay.from_predictions : Plot the
    confusion matrix given the true and predicted labels.

Examples
--------
>>> import matplotlib.pyplot as plt
>>> from sklearn.datasets import load_iris
>>> from sklearn.linear_model import LogisticRegression
>>> from sklearn.inspection import DecisionBoundaryDisplay
>>> iris = load_iris()
>>> X = iris.data[:, :2]
>>> classifier = LogisticRegression().fit(X, iris.target)
>>> disp = DecisionBoundaryDisplay.from_estimator(
...     classifier, X, response_method="predict",
...     xlabel=iris.feature_names[0], ylabel=iris.feature_names[1],
...     alpha=0.5,
... )
>>> disp.ax_.scatter(X[:, 0], X[:, 1], c=iris.target, edgecolor="k")
<...>
>>> plt.show()
z.from_estimatorr   Nr?   z,grid_resolution must be greater than 1. Got r4   z,eps must be greater than or equal to 0. Got r1   z, zplot_method must be one of z. Got r5   z#n_features must be equal to 2. Got )r   r   r   r   z[When 'multiclass_colors' is a list, it must be of the same length as 'estimator.classes_' (z), got: .c              3   d   >#    U  H%  nTR                   R                  U5      (       + v   M'     g 7fr'   )r8   is_color_like).0colrh   s     r   	<genexpr>9DecisionBoundaryDisplay.from_estimator.<locals>.<genexpr>  s*      AR#

00555ARs   -0z[When 'multiclass_colors' is a list, it can only contain valid Matplotlib color names. Got: zSWhen 'multiclass_colors' is a string, it must be a valid Matplotlib colormap. Got: r@   )columnsT)r   	pos_labelreturn_response_method_usedzis not a valid labelzclass_of_interest=z+ is not a valid label: It should be one of r   z)Multi-output regressors are not supportedr6   r    r(   )rf   re    )'r   __name__r   rE   r   joinr   r   lenr   rO   rT   anyrP   rG   	colormapsr   minmaxrR   meshgridrS   c_ravelr   r   r	   create_containerr   r   r   r   	transformrJ   reshaperL   r   flatnonzeroru   )$clsr   Xrx   ry   re   r   r   r#   r$   r%   rf   rg   possible_plot_methodsavailable_methodsnum_features	n_classesx0x1x0_minx0_maxx1_minx1_maxr)   r*   X_gridadapterr   r+   rj   response_method_usedexcencodercol_idxdisplayrh   s$                                      @r   from_estimator&DecisionBoundaryDisplay.from_estimator(  s   P 	!CLL>!AB	" "#$I/ 
 ax>se9M  !F3 $		*? @-.?-@ A"m9. 
 %Q'15l^9M 
 MM!-	:..!)"4"455:+T22()Y6$;;D+X012!5 
  AR   %99J8KM  +S11$CJJ,@,@,BB$55F4GI 
  11-~a/KBCCCC;;KK8KK8
S
 syy{CIIK/0}Q//1!4G--		 . F <(9
	0D 1+,01-Ha-&  9,J1O1O"nG(11G((2H==A''3HI&& !LMM , ..););?P)PQRST#AwJ/77C#++KSYYKr8JK>%,Q	%:%:QYYq\F>%,Q	%:%:QYYq\F/
 ||ErEfEE]  		%S1 !():(; <((1(:(:';=  		s   &P 
Q',QQ)
rb   rd   r#   rV   r+   rK   r$   r)   r*   r%   )r/   NNN)
r   
__module____qualname____firstlineno____doc__r-   ru   classmethodr   __static_attributes__r   r   r   r!   r!   ?   sT    dN 8<DQUvp  KF KFr   r!   )rM   numpyrR   baser   preprocessingr   utilsr   utils._optional_dependenciesr   utils._responser   utils._set_outputr	   utils.validationr
   r   r   r   r   r   r!   r   r   r   <module>r      s=        ) # D 3 < %PuF uFr   