Ë
    ÷Q(hJ<  ã                   óŠ   — d dl ZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZmZmZmZmZ d
„ Z G d„ d«      Zy)é    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                 ó  — t        | d«      }|r%t        | j                  d   «      rd}t        |«      ‚|r8t	        | j                  «      dkD  r |dvr|€d}t        |«      ‚|dk(  rd}|S |}|S |dk(  rt        | «      rd}|S g d	¢}|S |}|S )
aŠ  Validate the response methods to be used with the fitted estimator.

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

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

    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ÚpredictzµMulticlass classifiers are only supported when `response_method` is 'predict' or 'auto'. Else you must provide `class_of_interest` to plot the decision boundary of a specific class.r   r   )Údecision_functionÚpredict_probar   )Úhasattrr
   r   Ú
ValueErrorÚlenr   )Ú	estimatorÚresponse_methodÚclass_of_interestÚhas_classesÚmsgÚprediction_methods         úh/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sklearn/inspection/_plot/decision_boundary.pyÚ_check_boundary_response_methodr       sÖ   € ô2 ˜) ZÓ0€KÙÔ/°	×0BÑ0BÀ1Ñ0EÔFØVˆÜ˜‹oÐá”s˜9×-Ñ-Ó.°Ò2ØÐ"5Ñ5Ð:KÐ:SðBð ô
 ˜S“/Ð!Ø)8¸FÒ)B˜IÐð Ðð IXÐð Ðð 
˜FÒ	"Ü˜	Ô"Ø )Ðð Ðò	 !RÐð Ðð ,ÐàÐó    c            
       óJ   — e Zd ZdZdddœd„Zdd„Zedddd	ddddd
œd„«       Zy)ÚDecisionBoundaryDisplaya…	  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>`.

    .. 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)
        Values of the response function.

    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`
        If `plot_method` is 'contour' or 'contourf', `surface_` is a
        :class:`QuadContourSet <matplotlib.contour.QuadContourSet>`. If
        `plot_method` is 'pcolormesh', `surface_` is a
        :class:`QuadMesh <matplotlib.collections.QuadMesh>`.

    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)ÚxlabelÚylabelc                óJ   — || _         || _        || _        || _        || _        y )N©Úxx0Úxx1Úresponser$   r%   )Úselfr(   r)   r*   r$   r%   s         r   Ú__init__z DecisionBoundaryDisplay.__init__‘   s%   € ØˆŒØˆŒØ ˆŒØˆŒØˆ�r!   Úcontourfc                 óà  — t        d«       ddlm} |dvrt        d«      ‚|€|j	                  «       \  }}t        ||«      } || j                  | j                  | j                  fi |¤Ž| _	        |€|j                  «       s!|€| j                  n|}|j                  |«       |€|j                  «       s!|€| j                  n|}|j                  |«       || _        |j"                  | _        | S )aó  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')r   Úmatplotlib.pyplotÚpyplotr   ÚsubplotsÚgetattrr(   r)   r*   Úsurface_Ú
get_xlabelr$   Ú
set_xlabelÚ
get_ylabelr%   Ú
set_ylabelÚax_ÚfigureÚfigure_)	r+   Úplot_methodÚaxr$   r%   ÚkwargsÚpltÚ_Ú	plot_funcs	            r   ÚplotzDecisionBoundaryDisplay.plot˜   sÕ   € ô< 	!Ð!?Ô@Ý'àÐCÑCÜØLóð ð ˆ:Ø—L‘L“N‰EˆAˆrä˜B Ó,ˆ	Ù! $§(¡(¨D¯H©H°d·m±mÑNÀvÑNˆŒàÐ R§]¡]¤_Ø$* N�T—[’[¸ˆFØ�M‰M˜&Ô!ØÐ R§]¡]¤_Ø$* N�T—[’[¸ˆFØ�M‰M˜&Ô!àˆŒØ—y‘yˆŒØˆr!   éd   g      ð?r   )Úgrid_resolutionÚepsr>   r   r   r$   r%   r?   c                ó*  — t        | j                  › d�«       t        |«       |dkD  st        d|› d�«      ‚|dk\  st        d|› d�«      ‚d}||vr#dj	                  |«      }t        d	|› d
|› d�«      ‚t        |«      }|dk7  rt        d|› d�«      ‚t        |dd¬«      t        |dd¬«      }}|j                  «       |z
  |j                  «       |z   }}|j                  «       |z
  |j                  «       |z   }}t        j                  t        j                  |||«      t        j                  |||«      «      \  }}t        j                  |j                  «       |j                  «       f   }t        |«      st        |«      r)t!        |«      }|j#                  |||j$                  ¬«      }t'        |||«      }	 t)        ||||d¬«      \  }}}|dk(  r8t/        |d«      r,t1        «       }|j,                  |_        |j3                  |«      }|j4                  dk7  rDt7        |«      rt        d«      ‚t        j8                  |j,                  |k(  «      d   }|dd…|f   }|€t/        |d«      r|j$                  d   nd}|	€t/        |d«      r|j$                  d   nd}	 | |||j;                  |j<                  «      ||	¬«      }  | j>                  d|
|dœ|¤ŽS # t        $ r/}dt+        |«      v rt        d|› d|j,                  › �«      |‚‚ d}~ww xY w)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', 'predict_proba', 'decision_function',                 'predict'}, default='auto'
            Specifies whether to use :term:`predict_proba`,
            :term:`decision_function`, :term:`predict` as the target response.
            If set to 'auto', the response method is tried in the following order:
            :term:`decision_function`, :term:`predict_proba`, :term:`predict`.
            For multiclass problems, :term:`predict` is selected when
            `response_method="auto"`.

        class_of_interest : int, float, bool or str, default=None
            The class considered when plotting the decision. If None,
            `estimator.classes_[1]` is considered as the positive class
            for binary classifiers. Must have an explicit value for
            multiclass classifiers when `response_method` is 'predict_proba'
            or 'decision_function'.

            .. versionadded:: 1.4

        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_estimatoré   z,grid_resolution must be greater than 1. Got z	 instead.r   z,eps must be greater than or equal to 0. Got r/   z, zplot_method must be one of z. Got r   z#n_features must be equal to 2. Got )Úaxis)Ú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 Nr   r   z)Multi-output regressors are not supportedrK   Ú r'   )r?   r>   © ) r   Ú__name__r   r   Újoinr   r   ÚminÚmaxÚnpÚmeshgridÚlinspaceÚc_Úravelr   r   r	   Úcreate_containerrK   r    r   Ústrr   r   r   Ú	transformÚndimr   ÚflatnonzeroÚreshapeÚshaperD   )!Úclsr   ÚXrF   rG   r>   r   r   r$   r%   r?   r@   Úpossible_plot_methodsÚavailable_methodsÚnum_featuresÚx0Úx1Úx0_minÚx0_maxÚx1_minÚx1_maxr(   r)   ÚX_gridÚadapterr   r*   rB   Úresponse_method_usedÚexcÚencoderÚcol_idxÚdisplays!                                    r   Úfrom_estimatorz&DecisionBoundaryDisplay.from_estimatorÏ   s]  € ô^ 	! C§L¡L >°Ð!AÔBÜ˜	Ô"à Ò"ÜðØ#Ð$ Ið/óð ð
 �aŠxÜØ>¸s¸eÀ9ÐMóð ð !FÐØÐ3Ñ3Ø $§	¡	Ð*?Ó @ÐÜØ-Ð.?Ð-@ð AØ"�m 9ð.óð ô
 % QÓ'ˆØ˜1ÒÜØ5°l°^À9ÐMóð ô    1¨1Ô-¬~¸aÀÈÔ/KˆBˆàŸ™› C™¨¯©«°C©�ˆØŸ™› C™¨¯©«°C©�ˆä—;‘;Ü�K‰K˜ ¨Ó8Ü�K‰K˜ ¨Ó8ó
‰ˆˆSô
 —‘�s—y‘y“{ C§I¡I£KÐ/Ñ0ˆÜ˜Ôœ}¨QÔ/Ü1°!Ó4ˆGØ×-Ñ-ØØØŸ	™	ð .ó ˆFô <Ø�Ð(9ó
Ðð	Ü0DØØØ 1Ø+Ø,0ô1Ñ-ˆH�aÐ-ð&   9Ò,´¸ÀJÔ1OÜ"“nˆGØ(×1Ñ1ˆGÔØ×(Ñ(¨Ó2ˆHà�=‰=˜AÒÜ˜IÔ&Ü Ð!LÓMÐMô
 —n‘n Y×%7Ñ%7Ð;LÑ%LÓMÈaÑPˆGØ¢ 7 
Ñ+ˆHàˆ>Ü%,¨Q°	Ô%:�Q—Y‘Y˜q’\ÀˆFàˆ>Ü%,¨Q°	Ô%:�Q—Y‘Y˜q’\ÀˆFáØØØ×%Ñ% c§i¡iÓ0ØØô
ˆð ˆw�|‰|ÐE˜r¨{ÑE¸fÑEÐEøôQ ò 		Ø%¬¨S«Ñ1ô !Ø(Ð):Ð(;ð <(Ø(1×(:Ñ(:Ð';ð=óð ðð ûð		ús   Æ=K Ë	LË#*LÌL)r-   NNN)rP   Ú
__module__Ú__qualname__Ú__doc__r,   rD   Úclassmethodrr   rO   r!   r   r#   r#   G   sM   „ ñGðR 6:À$ô ó5ðn ð ØØØØØØØóPFó ñPFr!   r#   )ÚnumpyrT   Úbaser   Úpreprocessingr   Úutilsr   Úutils._optional_dependenciesr   Úutils._responser   Úutils._set_outputr	   Úutils.validationr
   r   r   r   r   r    r#   rO   r!   r   ú<module>r      s:   ðó å  Ý )Ý #Ý DÝ 3Ý <÷õ ò/÷dYFò YFr!   