Ë
    8Ò^j�ˆ  ã                   ór   — d dl Zd dlmZmZ d dlmZmZ d dlm	Z	m
Z
mZmZmZmZmZ d dlmZ  G d„ de	«      Zy)é    N)Úaverage_precision_scoreÚprecision_recall_curve)Ú_safe_indexingÚcheck_array)Ú"_BinaryClassifierCurveDisplayMixinÚ_check_param_lengthsÚ_convert_to_list_leaving_noneÚ_deprecate_estimator_nameÚ_deprecate_y_pred_parameterÚ_despineÚ_validate_style_kwargs)Ú_get_response_values_binaryc                   óÊ   ‡ — e Zd ZdZddddddœd„Zˆ fd„Z	 dddddddœd	„Zeddd
ddddddddœ
d„«       Ze	 ddddddddddddœ
d„«       Z	eddd
ddddddddœ
d„«       Z
ˆ xZS )ÚPrecisionRecallDisplaya  Precision Recall visualization.

    It is recommended to use
    :func:`~sklearn.metrics.PrecisionRecallDisplay.from_estimator` or
    :func:`~sklearn.metrics.PrecisionRecallDisplay.from_predictions` to create
    a :class:`~sklearn.metrics.PrecisionRecallDisplay`. 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 <precision_recall_f_measure_metrics>`.

    Parameters
    ----------
    precision : ndarray or list of ndarrays
        Precision values. Each ndarray should contain values for a single curve.
        If plotting multiple curves, list should be of same length as `recall`.

        .. versionchanged:: 1.9
            Now accepts a list for plotting multiple curves.

    recall : ndarray or list of ndarrays
        Recall values. Each ndarray should contain values for a single curve.
        If plotting multiple curves, list should be of same length as `precision`.

        .. versionchanged:: 1.9
            Now accepts a list for plotting multiple curves.

    average_precision : float or list of floats, default=None
        Average precision, used for labeling each curve in the legend.
        If plotting multiple curves, should be a list of the same length as `precision`
        and `recall`. If `None`, average precision values are not shown in the legend.

        .. versionchanged:: 1.9
            Now accepts a list for plotting multiple curves.

    name : str or list of str, default=None
        Name for labeling legend entries. The number of legend entries is determined
        by the `curve_kwargs` passed to `plot`, and is not affected by `name`.

        If a string is provided, it will be used to either label the single legend
        entry or if there are multiple legend entries, label each individual curve
        with the same name.

        If a list is provided, it will be used to label each curve individually.
        Passing a list will raise an error if `curve_kwargs` is not a list to avoid
        labeling individual curves that have the same appearance.

        If `None`, no name is shown in the legend.

        .. versionchanged:: 1.8
            `estimator_name` was deprecated in favor of `name`.

        .. versionchanged:: 1.9
            `name` can now take a list of str for multiple curves.

    pos_label : int, float, bool or str, default=None
        The class considered the positive class when precision and recall metrics
        computed. If not `None`, this value is displayed in the x- and y-axes labels.

        .. versionadded:: 0.24

    prevalence_pos_label : float or list of floats, default=None
        The prevalence of the positive label. It is used for plotting the
        chance level lines. If None, no chance level line will be plotted
        even if `plot_chance_level` is set to True when plotting.

        .. versionadded:: 1.3

        .. versionchanged:: 1.9
            May now be list of floats for when multiple curves plotted.

    estimator_name : str, default=None
        Name of estimator. If None, the estimator name is not shown.

        .. deprecated:: 1.8
            `estimator_name` is deprecated and will be removed in 1.10. Use `name`
            instead.

    Attributes
    ----------
    line_ : matplotlib Artist or list of Artists
        Precision recall curve(s).

        .. versionchanged:: 1.9
            This attribute can now be a list of Artists, for when multiple curves
            are plotted.

    chance_level_ : matplotlib Artist or list of Artists or None
        Chance level line(s). It is `None` if the chance level is not plotted.

        .. versionadded:: 1.3

        .. versionchanged:: 1.9
            This attribute can now be a list of Artists, for when multiple curves
            are plotted.

    ax_ : matplotlib Axes
        Axes with precision recall curve.

    figure_ : matplotlib Figure
        Figure containing the curve.

    See Also
    --------
    precision_recall_curve : Compute precision-recall pairs for different
        probability thresholds.
    PrecisionRecallDisplay.from_estimator : Plot Precision Recall Curve given
        a binary classifier.
    PrecisionRecallDisplay.from_predictions : Plot Precision Recall Curve
        using predictions from a binary classifier.

    Notes
    -----
    The average precision (cf. :func:`~sklearn.metrics.average_precision_score`) in
    scikit-learn is computed without any interpolation. To be consistent with
    this metric, the precision-recall curve is plotted without any
    interpolation as well (step-wise style).

    To enable interpolation, pass `curve_kwargs={"drawstyle": "default"}` to
    meth:`plot`, :meth:`from_estimator`, or :meth:`from_predictions`.
    However, the curve will not be strictly consistent with the reported
    average precision.

    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> from sklearn.datasets import make_classification
    >>> from sklearn.metrics import (precision_recall_curve,
    ...                              PrecisionRecallDisplay)
    >>> 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)
    >>> precision, recall, _ = precision_recall_curve(y_test, predictions)
    >>> disp = PrecisionRecallDisplay(precision=precision, recall=recall)
    >>> disp.plot()
    <...>
    >>> plt.show()
    NÚ
deprecated)Úaverage_precisionÚnameÚ	pos_labelÚprevalence_pos_labelÚestimator_namec                ón   — || _         || _        || _        t        ||d«      | _        || _        || _        y )Nú1.8)Ú	precisionÚrecallr   r
   r   r   r   )Úselfr   r   r   r   r   r   r   s           úw/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/sklearn/metrics/_plot/precision_recall_curve.pyÚ__init__zPrecisionRecallDisplay.__init__¨   s9   € ð #ˆŒØˆŒØ!2ˆÔÜ-¨n¸dÀEÓJˆŒ	Ø"ˆŒØ$8ˆÕ!ó    c                óœ  •— t         ‰| �  ||¬«      \  | _        | _        }t	        | j
                  «      }t	        | j                  «      }t	        | j                  «      }t	        | j                  «      }t	        |«      }||dœ}t        |t        «      r!t        |«      dk7  r|j                  d|i«       t        ||dœ|d¬«       |||||fS )N©Úaxr   )zself.average_precisionzself.prevalence_pos_labelé   z'name' (or self.name))zself.precisionzself.recallr   )ÚrequiredÚoptionalÚ
class_name)ÚsuperÚ_validate_plot_paramsÚax_Úfigure_r	   r   r   r   r   Ú
isinstanceÚlistÚlenÚupdater   )	r   r!   r   r   r   r   r   r$   Ú	__class__s	           €r   r'   z,PrecisionRecallDisplay._validate_plot_paramsº   sÍ   ø€ Ü',¡wÑ'DÈÐQUÐ'DÓ'VÑ$ˆŒ�$”, ä1°$·.±.ÓAˆ	Ü.¨t¯{©{Ó;ˆÜ9¸$×:PÑ:PÓQÐÜ<¸T×=VÑ=VÓWÐÜ,¨TÓ2ˆð '8Ø)=ñ
ˆô �dœDÔ!¤c¨$£i°1¢nØ�O‰OÐ4°dÐ;Ô<ÜØ(1À&ÑIØØ/õ	
ð
 ˜&Ð"3°TÐ;OÐOÐOr   F)r   Úcurve_kwargsÚplot_chance_levelÚchance_level_kwÚdespinec          	      ó  — | j                  ||¬«      \  }}	}
}}t        |«      }| j                  |||
«      \  }
} | j                  |||df|ddiddddœd	d
œ|¤Ž}g | _        t        |	||«      D ]=  \  }}}| j                  j                   | j                  j                  ||fi |¤Ž«       Œ? t        | j                  «      dk(  r| j                  d   | _        | j                  �d| j                  › d�nd}d|z   }d|z   }| j                  j                  |d|dd¬«       |rù| j                  €t        d«      ‚dddœ}|dkD  rd|d<   |€i }t        ||«      }g | _        |D ];  }| j                  j                   | j                  j                  d||ffi |¤Ž«       Œ= d|vr^|dk(  r
d|d   d›d�n0dt        j                   |«      d›dt        j"                  |«      d›d�}| j                  d   j%                  |«       |dk(  r| j                  d   | _        nd| _        |rt'        | j                  «       |d   j)                  d«      €|r-|j)                  d«      �| j                  j+                  d ¬!«       | S )"a,  Plot visualization.

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

        name : str or list of str, default=None
            Name for labeling legend entries. The number of legend entries
            is determined by `curve_kwargs`, and is not affected by `name`.

            If a string is provided, it will be used to either label the single legend
            entry or if there are multiple legend entries, label each individual curve
            with the same name.

            If a list is provided, it will be used to label each curve individually.
            Passing a list will raise an error if `curve_kwargs` is not a list to avoid
            labeling individual curves that have the same appearance.

            If `None`, set to `name` provided at `PrecisionRecallDisplay`
            initialization. If still `None`, no name is shown in the legend.

            .. versionchanged:: 1.9
                Now accepts a list for plotting multiple curves.

        curve_kwargs : dict or list of dict, default=None
            Keywords arguments to be passed to matplotlib's `plot` function
            to draw individual precision-recall curves. For single curve plotting, this
            should be a dictionary. For multi-curve plotting, if a list is provided,
            the parameters are applied to each precision-recall curve
            sequentially and a legend entry is added for each curve.
            If a single dictionary is provided, the same parameters are applied
            to all curves and a single legend entry for all curves is added,
            labeled with the mean average precision.

            .. versionadded:: 1.9

        plot_chance_level : bool, default=False
            Whether to plot the chance level. The chance level is the prevalence
            of the positive label computed from the data passed during
            :meth:`from_estimator` or :meth:`from_predictions` call.

            .. versionadded:: 1.3

        chance_level_kw : dict, default=None
            Keyword arguments to be passed to matplotlib's `plot` for rendering
            the chance level line.

            .. versionadded:: 1.3

        despine : bool, default=False
            Whether to remove the top and right spines from the plot.

            .. versionadded:: 1.6

        **kwargs : dict
            Keyword arguments to be passed to matplotlib's `plot`.

            .. deprecated:: 1.9
                kwargs is deprecated and will be removed in 1.11. Pass matplotlib
                arguments to `curve_kwargs` as a dictionary instead.

        Returns
        -------
        display : :class:`~sklearn.metrics.PrecisionRecallDisplay`
            Object that stores computed values.

        Notes
        -----
        The average precision (cf. :func:`~sklearn.metrics.average_precision_score`)
        in scikit-learn is computed without any interpolation. To be consistent
        with this metric, the precision-recall curve is plotted without any
        interpolation as well (step-wise style).

        To enable interpolation, pass `curve_kwargs={"drawstyle": "default"}`.
        However, the curve will not be strictly consistent with the reported
        average precision.
        r    ÚAPÚ	drawstylez
steps-postg      à?z--Úblue)ÚalphaÚ	linestyleÚcolorz1.11)r/   Údefault_curve_kwargsÚdefault_multi_curve_kwargsÚremoved_versionr"   r   Nz (Positive label: ú)Ú ÚRecallÚ	Precision)g{®Gáz„¿g)\�Âõ(ð?Úequal)ÚxlabelÚxlimÚylabelÚylimÚaspecta  You must provide prevalence_pos_label when constructing the PrecisionRecallDisplay object in order to plot the chance level line. Alternatively, you may use PrecisionRecallDisplay.from_estimator or PrecisionRecallDisplay.from_predictions to automatically set prevalence_pos_labelÚk)r9   r8   g333333Ó?r7   )r   r"   ÚlabelzChance level (AP = z0.2fz +/- z
lower left)Úloc)r'   r,   Ú_get_legend_metricÚ_validate_curve_kwargsÚline_ÚzipÚextendr(   Úplotr   Úsetr   Ú
ValueErrorr   Úchance_level_ÚnpÚmeanÚstdÚ	set_labelr   ÚgetÚlegend)r   r!   r   r/   r0   r1   r2   Úkwargsr   r   r   r   Ún_curvesÚlegend_metricÚ
recall_valÚprecision_valÚcurve_kwargÚinfo_pos_labelrB   rD   Údefault_chance_level_kwargsÚ
prevalencerH   s                          r   rO   zPrecisionRecallDisplay.plotÐ   s  € ðv ×&Ñ&¨"°4Ð&Ó8ñ 	Iˆ	�6Ð,¨dÐ4Hô �y“>ˆØ+/×+BÑ+BØ˜(Ð$5ó,
Ñ(Ð˜=ð 3�t×2Ñ2ØØØØð	
ð
 &Ø"-¨|Ð!<àØ!Øñ(ð
 #ñ
ð ñ
ˆð ˆŒ
Ü69Ø�I˜|ó7
ò 	WÑ2ˆJ˜ {ð �J‰J×Ñ˜m˜dŸh™hŸm™m¨J¸ÑUÈÑUÕVð	Wô
 ˆt�z‰z‹?˜aÒØŸ™ A™ˆDŒJð 7;·n±nÐ6PÐ  §¡Ð 0°Ñ2ÐVXð 	ð ˜NÑ*ˆØ˜~Ñ-ˆØ�‰�‰ØØØØØð 	ô 	
ñ Ø×(Ñ(Ð0Ü ð@óð ð Ø!ñ+Ð'ð ˜!Š|Ø7:Ð+¨GÑ4àÐ&Ø"$�ä4Ø+¨_óˆOð "$ˆDÔØ2ò �
Ø×"Ñ"×)Ñ)Ø!�D—H‘H—M‘MØØ# ZÐ0ñð *ñõðð ˜oÑ-ð   1’}ð *Ð*>¸qÑ*AÀ$Ð)GÀqÑIà.¬r¯w©wÐ7KÓ/LÈTÐ.Rð SÜŸ6™6Ð"6Ó7¸Ð=¸Qð@ð ð ×"Ñ" 1Ñ%×/Ñ/°Ô6à˜1Š}à%)×%7Ñ%7¸Ñ%:�Õ"à!%ˆDÔáÜ�T—X‘XÔð ˜‰?×Ñ˜wÓ'Ð3Ù /×"5Ñ"5°gÓ">Ð"Jà�H‰H�O‰O ˆOÔ-àˆr   Úauto)
Úsample_weightÚdrop_intermediateÚresponse_methodr   r   r!   r/   r0   r1   r2   c       
         ót   — | j                  ||||||¬«      \  }}} | j                  ||f|||||	|
|||dœ	|¤ŽS )aÛ  Plot precision-recall curve 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 <precision_recall_f_measure_metrics>`.

        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.

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

        drop_intermediate : bool, default=False
            Whether to drop some suboptimal thresholds which would not appear
            on a plotted precision-recall curve. This is useful in order to
            create lighter precision-recall curves.

            .. versionadded:: 1.3

        response_method : {'predict_proba', 'decision_function', 'auto'},             default='auto'
            Specifies whether to use :term:`predict_proba` or
            :term:`decision_function` as the target response. If set to 'auto',
            :term:`predict_proba` is tried first and if it does not exist
            :term:`decision_function` is tried next.

        pos_label : int, float, bool or str, default=None
            The class considered as the positive class when computing the
            precision and recall metrics. By default, `estimators.classes_[1]`
            is considered as the positive class.

        name : str, default=None
            Name for labeling curve. If `None`, no name is used.

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

        curve_kwargs : dict, default=None
            Keywords arguments to be passed to matplotlib's `plot` function.

            .. versionadded:: 1.9

        plot_chance_level : bool, default=False
            Whether to plot the chance level. The chance level is the prevalence
            of the positive label computed from the data passed during
            :meth:`from_estimator` or :meth:`from_predictions` call.

            .. versionadded:: 1.3

        chance_level_kw : dict, default=None
            Keyword arguments to be passed to matplotlib's `plot` for rendering
            the chance level line.

            .. versionadded:: 1.3

        despine : bool, default=False
            Whether to remove the top and right spines from the plot.

            .. versionadded:: 1.6

        **kwargs : dict
            Keyword arguments to be passed to matplotlib's `plot`.

            .. deprecated:: 1.9
                kwargs is deprecated and will be removed in 1.11. Pass matplotlib
                arguments to `curve_kwargs` as a dictionary instead.

        Returns
        -------
        display : :class:`~sklearn.metrics.PrecisionRecallDisplay`

        See Also
        --------
        PrecisionRecallDisplay.from_predictions : Plot precision-recall curve
            using estimated probabilities or output of decision function.

        Notes
        -----
        The average precision (cf. :func:`~sklearn.metrics.average_precision_score`)
        in scikit-learn is computed without any interpolation. To be consistent
        with this metric, the precision-recall curve is plotted without any
        interpolation as well (step-wise style).

        To enable interpolation, pass `curve_kwargs={"drawstyle": "default"}`.
        However, the curve will not be strictly consistent with the reported
        average precision.

        Examples
        --------
        >>> import matplotlib.pyplot as plt
        >>> from sklearn.datasets import make_classification
        >>> from sklearn.metrics import PrecisionRecallDisplay
        >>> from sklearn.model_selection import train_test_split
        >>> from sklearn.linear_model import LogisticRegression
        >>> X, y = make_classification(random_state=0)
        >>> X_train, X_test, y_train, y_test = train_test_split(
        ...         X, y, random_state=0)
        >>> clf = LogisticRegression()
        >>> clf.fit(X_train, y_train)
        LogisticRegression()
        >>> PrecisionRecallDisplay.from_estimator(
        ...    clf, X_test, y_test)
        <...>
        >>> plt.show()
        )re   r   r   )	rc   rd   r   r   r!   r/   r0   r1   r2   )Ú!_validate_and_get_response_valuesÚfrom_predictions)ÚclsÚ	estimatorÚXÚyrc   rd   re   r   r   r!   r/   r0   r1   r2   rY   Úy_scores                   r   Úfrom_estimatorz%PrecisionRecallDisplay.from_estimator•  s}   € ðL $'×#HÑ#HØØØØ+ØØð $Ió $
Ñ ˆ�˜Dð $ˆs×#Ñ#ØØð
ð (Ø/ØØØØ%Ø/Ø+Øñ
ð ñ
ð 	
r   )
rc   rd   r   r   r!   r/   r0   r1   r2   Úy_predc       
   
      ó<  — t        |dd¬«      }t        ||d«      }| j                  |||||¬«      \  }}t        |||||¬«      \  }}}t	        ||||¬«      }||k(  j                  «       t        |«      z  } | ||||||¬«      } |j                  d
||||	|
|d	œ|¤ŽS )a”  Plot precision-recall curve given binary class predictions.

        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 <precision_recall_f_measure_metrics>`.

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

        y_score : array-like of shape (n_samples,)
            Estimated probabilities or output of decision function.

            .. versionadded:: 1.8
                `y_pred` has been renamed to `y_score`.

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

        drop_intermediate : bool, default=False
            Whether to drop some suboptimal thresholds which would not appear
            on a plotted precision-recall curve. This is useful in order to
            create lighter precision-recall curves.

            .. versionadded:: 1.3

        pos_label : int, float, bool or str, default=None
            The class considered as the positive class when computing the
            precision and recall metrics. When `pos_label=None`, if `y_true` is
            in {-1, 1} or {0, 1}, `pos_label` is set to 1, otherwise an error
            will be raised.

        name : str, default=None
            Name for labeling curve. If `None`, name will be set to
            `"Classifier"`.

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

        curve_kwargs : dict, default=None
            Keywords arguments to be passed to matplotlib's `plot` function.

            .. versionadded:: 1.9

        plot_chance_level : bool, default=False
            Whether to plot the chance level. The chance level is the prevalence
            of the positive label computed from the data passed during
            :meth:`from_estimator` or :meth:`from_predictions` call.

            .. versionadded:: 1.3

        chance_level_kw : dict, default=None
            Keyword arguments to be passed to matplotlib's `plot` for rendering
            the chance level line.

            .. versionadded:: 1.3

        despine : bool, default=False
            Whether to remove the top and right spines from the plot.

            .. versionadded:: 1.6

        y_pred : array-like of shape (n_samples,)
            Estimated probabilities or output of decision function.

            .. deprecated:: 1.8
                `y_pred` is deprecated and will be removed in 1.10. Use
                `y_score` instead.

        **kwargs : dict
            Keyword arguments to be passed to matplotlib's `plot`.

            .. deprecated:: 1.9
                kwargs is deprecated and will be removed in 1.11. Pass matplotlib
                arguments to `curve_kwargs` as a dictionary instead.

        Returns
        -------
        display : :class:`~sklearn.metrics.PrecisionRecallDisplay`

        See Also
        --------
        PrecisionRecallDisplay.from_estimator : Plot precision-recall curve
            using an estimator.

        Notes
        -----
        The average precision (cf. :func:`~sklearn.metrics.average_precision_score`)
        in scikit-learn is computed without any interpolation. To be consistent
        with this metric, the precision-recall curve is plotted without any
        interpolation as well (step-wise style).

        To enable interpolation, pass `curve_kwargs={"drawstyle": "default"}`.
        However, the curve will not be strictly consistent with the reported
        average precision.

        Examples
        --------
        >>> import matplotlib.pyplot as plt
        >>> from sklearn.datasets import make_classification
        >>> from sklearn.metrics import PrecisionRecallDisplay
        >>> from sklearn.model_selection import train_test_split
        >>> from sklearn.linear_model import LogisticRegression
        >>> X, y = make_classification(random_state=0)
        >>> X_train, X_test, y_train, y_test = train_test_split(
        ...         X, y, random_state=0)
        >>> clf = LogisticRegression()
        >>> clf.fit(X_train, y_train)
        LogisticRegression()
        >>> y_score = clf.predict_proba(X_test)[:, 1]
        >>> PrecisionRecallDisplay.from_predictions(
        ...    y_test, y_score)
        <...>
        >>> plt.show()
        FN)Ú	ensure_2dÚdtyper   )rc   r   r   ©r   rc   rd   ©r   rc   ©r   r   r   r   r   r   )r!   r   r/   r0   r1   r2   © )r   r   Ú!_validate_from_predictions_paramsr   r   Úsumr,   rO   )ri   Úy_truerm   rc   rd   r   r   r!   r/   r0   r1   r2   ro   rY   r   r   Ú_r   r   Úvizs                       r   rh   z'PrecisionRecallDisplay.from_predictions3  sð   € ôP ˜V¨u¸DÔAˆÜ-¨g°v¸uÓEˆØ×?Ñ?Ø�G¨=ÀIÐTXð @ó 
‰ˆ	�4ô  6ØØØØ'Ø/ô 
Ñˆ	�6˜1ô 4Ø�G yÀô
Ðð !'¨)Ñ 3×8Ñ8Ó:¼SÀ»[ÑHÐáØØØ/ØØØ!5ô
ˆð ˆs�x‰xð 
ØØØ%Ø/Ø+Øñ
ð ñ
ð 	
r   T)
rc   rd   re   r   r   r!   r/   r0   Úchance_level_kwargsr2   c       
         óL  — | j                  ||||¬«       g g }}g g }}t        |d   |d   d   «      D ]Ì  \  }}t        ||«      }t        |t        ||«      ||¬«      \  }}|€dnt        ||«      }t	        |||||¬«      \  }}}t        ||||¬«      }t        j                  ||k(  «      |j                  d	   z  }|j                  |«       |j                  |«       |j                  |«       |j                  |«       ŒÎ  | |||||¬
«      }|j                  |	|
|||¬«      S )ad  Plot multi-fold precision-recall curves given cross-validation results.

        .. versionadded:: 1.9

        Parameters
        ----------
        cv_results : dict
            Dictionary as returned by :func:`~sklearn.model_selection.cross_validate`
            using `return_estimator=True` and `return_indices=True` (i.e., dictionary
            should contain the keys "estimator" and "indices").

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

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

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

        drop_intermediate : bool, default=True
            Whether to drop some suboptimal thresholds which would not appear
            on a plotted precision-recall curve. This is useful in order to
            create lighter precision-recall curves.

        response_method : {'predict_proba', 'decision_function', 'auto'}                 default='auto'
            Specifies whether to use :term:`predict_proba` or
            :term:`decision_function` as the target response. If set to 'auto',
            :term:`predict_proba` is tried first and if it does not exist
            :term:`decision_function` is tried next.

        pos_label : int, float, bool or str, default=None
            The class considered as the positive class when computing the precision
            and recall metrics. By default, `estimators.classes_[1]` is considered
            as the positive class.

        name : str or list of str, default=None
            Name for labeling legend entries. The number of legend entries
            is determined by `curve_kwargs`, and is not affected by `name`.

            If a string is provided, it will be used to either label the single legend
            entry or if there are multiple legend entries, label each individual curve
            with the same name.

            If a list is provided, it will be used to label each curve individually.
            Passing a list will raise an error if `curve_kwargs` is not a list to avoid
            labeling individual curves that have the same appearance.

            If `None`, no name is shown in the legend.

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

        curve_kwargs : dict or list of dict, default=None
            Dictionary with keywords passed to the matplotlib's `plot` function
            to draw the individual precision-recall curves. If a list is provided, the
            parameters are applied to the precision-recall curves of each CV fold
            sequentially. If a single dictionary is provided, the same
            parameters are applied to all precision-recall curves.

        plot_chance_level : bool, default=False
            Whether to plot the chance level lines.

        chance_level_kwargs : dict, default=None
            Keyword arguments to be passed to matplotlib's `plot` for rendering
            the chance level lines.

        despine : bool, default=False
            Whether to remove the top and right spines from the plot.

        Returns
        -------
        display : :class:`~sklearn.metrics.PrecisionRecallDisplay`

        See Also
        --------
        PrecisionRecallDisplay.from_predictions : Plot precision-recall curve
            using estimated probabilities or output of decision function.
        PrecisionRecallDisplay.from_estimator : Plot precision-recall curve
            using an estimator.
        precision_recall_curve : Compute precision-recall pairs for different
            probability thresholds.
        average_precision_score : Compute average precision (AP) from prediction scores.

        Notes
        -----
        The average precision (cf. :func:`~sklearn.metrics.average_precision_score`)
        in scikit-learn is computed without any interpolation. To be consistent
        with this metric, the precision-recall curve is plotted without any
        interpolation as well (step-wise style).

        To enable interpolation, pass `curve_kwargs={"drawstyle": "default"}`.
        However, the curve will not be strictly consistent with the reported
        average precision.

        Examples
        --------
        >>> import matplotlib.pyplot as plt
        >>> from sklearn.datasets import make_classification
        >>> from sklearn.metrics import PrecisionRecallDisplay
        >>> from sklearn.model_selection import cross_validate
        >>> from sklearn.svm import SVC
        >>> X, y = make_classification(random_state=0)
        >>> clf = SVC(random_state=0)
        >>> cv_results = cross_validate(
        ...     clf, X, y, cv=3, return_estimator=True, return_indices=True)
        >>> PrecisionRecallDisplay.from_cv_results(cv_results, X, y)
        <...>
        >>> plt.show()
        )rc   rj   ÚindicesÚtest)re   r   Nrs   rt   r   ru   )r!   r/   r0   r1   r2   )Ú _validate_from_cv_results_paramsrM   r   r   r   r   rS   Úcount_nonzeroÚshapeÚappendrO   )ri   Ú
cv_resultsrk   rl   rc   rd   re   r   r   r!   r/   r0   r|   r2   Úprecision_foldsÚrecall_foldsÚap_foldsÚprevalence_pos_label_foldsrj   Útest_indicesry   ro   Ú
pos_label_Úsample_weight_foldr   r   rz   r   r   r{   s                                 r   Úfrom_cv_resultsz&PrecisionRecallDisplay.from_cv_resultsá  s’  € ðD 	×,Ñ,Ø˜˜1¨Mð 	-ô 	
ð )+¨B˜ˆØ/1°2Ð,ˆä'*Ø�{Ñ# Z°	Ñ%:¸6Ñ%Bó(
ò #	DÑ#ˆI�|ô $ A |Ó4ˆFÜ!<ØÜ˜q ,Ó/Ø /Ø#ô	"ÑˆF�Jð !Ð(ñ ä# M°<Ó@ð ô
 $:ØØØ$Ø0Ø"3ô$Ñ ˆI�v˜qô !8Ø˜¨*ÐDVô!Ðô × Ñ  ¨:Ñ!5Ó6¸¿¹Àa¹ÑHð !ð ×"Ñ" 9Ô-Ø×Ñ Ô'Ø�O‰OÐ-Ô.Ø&×-Ñ-Ð.BÕCðG#	DñJ Ø%ØØ&ØØ Ø!;ô
ˆð �x‰xØØ%Ø/Ø/Øð ó 
ð 	
r   )N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r'   rO   Úclassmethodrn   rh   rŒ   Ú__classcell__)r.   s   @r   r   r      sø   ø„ ñQðp ØØØ!Ø#ô9ô$Pð0 ðCð ØØØØôCðJ ð ØØØØØØØØØó[
ó ð[
ðz ð ðk
ð
 ØØØØØØØØØók
ó ðk
ðZ ð ØØØØØØØØ Øó{
ó ô{
r   r   )ÚnumpyrS   Úsklearn.metrics._rankingr   r   Úsklearn.utilsr   r   Úsklearn.utils._plottingr   r   r	   r
   r   r   r   Úsklearn.utils._responser   r   rv   r   r   ú<module>r˜      s4   ðó ç Tß 5÷÷ ñ õ @ôI
Ð?õ I
r   