§
    rŠtj�  ã                   óˆ  — d dl mZ d dlmZmZ d dlZd dlmZm	Z	m
Z
mZmZ d dlmZ d dlmZmZ d dlmZm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 d dl m!Z! d dl"m#Z# d dl$m%Z%m&Z&m'Z'm(Z( d dl)m*Z* d dl+m,Z, d dl-m.Z.m/Z/ d dl0m1Z1m2Z2m3Z3m4Z4m5Z5 d„ Z6 G d„ de	e
e¦  «        Z7 G d„ de7¦  «        Z8d„ Z9d„ Z: G d„ de7¦  «        Z;dS )é    )ÚMutableMapping)ÚIntegralÚRealN)ÚBaseEstimatorÚClassifierMixinÚMetaEstimatorMixinÚ_fit_contextÚclone)ÚNotFittedError)Úcheck_scoringÚget_scorer_names)Ú_CurveScorerÚ!_threshold_scores_to_class_labels)ÚStratifiedShuffleSplitÚcheck_cv)Ú_safe_indexingÚget_tags)Ú
HasMethodsÚIntervalÚ
RealNotIntÚ
StrOptions)Ú_VisualBlock)Ú_get_response_values_binary)ÚMetadataRouterÚMethodMappingÚ_raise_for_paramsÚprocess_routing)Úavailable_if)Útype_of_target)ÚParallelÚdelayed)Ú_check_method_paramsÚ_estimator_hasÚ_num_samplesÚcheck_is_fittedÚ	indexablec                 ór   — 	 t          | j        ¦  «         d S # t          $ r t          | d¦  «         Y d S w xY w)NÚ
estimator_)r%   Ú	estimatorr   )r)   s    úo/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sklearn/model_selection/_classification_threshold.pyÚ_check_is_fittedr+   *   sR   € ð1Ý˜	Ô+Ñ,Ô,Ð,Ð,Ð,øÝð 1ð 1ð 1Ý˜	 <Ñ0Ô0Ð0Ð0Ð0Ð0ð1øøøs   ‚ ˜6µ6c                   ó€  ‡ — e Zd ZU dZ eddg¦  «         eddg¦  «        g eh d£¦  «        gdœZeed<   dd	œd
„Z	d„ Z
 ed¬¦  «        d„ ¦   «         Zed„ ¦   «         Z e ed¦  «        ¦  «        d„ ¦   «         Z e ed¦  «        ¦  «        d„ ¦   «         Z e ed¦  «        ¦  «        d„ ¦   «         Zˆ fd„Zˆ xZS )ÚBaseThresholdClassifiera  Base class for binary classifiers that set a non-default decision threshold.

    In this base class, we define the following interface:

    - the validation of common parameters in `fit`;
    - the different prediction methods that can be used with the classifier.

    .. versionadded:: 1.5

    Parameters
    ----------
    estimator : estimator instance
        The binary classifier, fitted or not, for which we want to optimize
        the decision threshold used during `predict`.

    response_method : {"auto", "decision_function", "predict_proba"}, default="auto"
        Methods by the classifier `estimator` corresponding to the
        decision function for which we want to find a threshold. It can be:

        * if `"auto"`, it will try to invoke, for each classifier,
          `"predict_proba"` or `"decision_function"` in that order.
        * otherwise, one of `"predict_proba"` or `"decision_function"`.
          If the method is not implemented by the classifier, it will raise an
          error.
    ÚfitÚpredict_probaÚdecision_function>   Úautor/   r0   ©r)   Úresponse_methodÚ_parameter_constraintsr1   ©r3   c                ó"   — || _         || _        d S ©Nr2   )Úselfr)   r3   s      r*   Ú__init__z BaseThresholdClassifier.__init__T   s   € Ø"ˆŒØ.ˆÔÐÐó    c                 ó4   — | j         dk    rddg}n| j         }|S )zDefine the response method.r1   r/   r0   r5   )r8   r3   s     r*   Ú_get_response_methodz,BaseThresholdClassifier._get_response_methodX   s+   € àÔ 6Ò)Ð)Ø.Ð0CÐDˆOˆOà"Ô2ˆOØÐr:   F)Úprefer_skip_nested_validationc                 óV  — t          || d¦  «         t          ||¦  «        \  }}t          |d¬¦  «        }|dk    rt          d|› �¦  «        ‚ | j        ||fi |¤Ž t          | j        d¦  «        r| j        j        | _        t          | j        d¦  «        r| j        j        | _        | S )áÆ  Fit the classifier.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training data.

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

        **params : dict
            Parameters to pass to the `fit` method of the underlying
            classifier.

        Returns
        -------
        self : object
            Returns an instance of self.
        NÚy)Ú
input_nameÚbinaryz=Only binary classification is supported. Unknown label type: Ún_features_in_Úfeature_names_in_)	r   r&   r   Ú
ValueErrorÚ_fitÚhasattrr(   rC   rD   )r8   ÚXr@   ÚparamsÚy_types        r*   r.   zBaseThresholdClassifier.fit`   sË   € õ0 	˜& $¨Ñ-Ô-Ð-å˜˜A‰Œ‰ˆˆ1å ¨cÐ2Ñ2Ô2ˆØ�XÒÐÝØXÐPVÐXÐXñô ð ð 	ˆŒ	�!�QÐ!Ð!˜&Ð!Ð!Ð!å�4”?Ð$4Ñ5Ô5ð 	AØ"&¤/Ô"@ˆDÔÝ�4”?Ð$7Ñ8Ô8ð 	GØ%)¤_Ô%FˆDÔ"àˆr:   c                 ó   — | j         j        S )zClasses labels.)r(   Úclasses_)r8   s    r*   rL   z BaseThresholdClassifier.classes_‹   s   € ð ŒÔ'Ð'r:   c                 óv   — t          | ¦  «         t          | d| j        ¦  «        }|                     |¦  «        S )aÔ  Predict class probabilities for `X` using the fitted estimator.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training vectors, where `n_samples` is the number of samples and
            `n_features` is the number of features.

        Returns
        -------
        probabilities : ndarray of shape (n_samples, n_classes)
            The class probabilities of the input samples.
        r(   )r+   Úgetattrr)   r/   ©r8   rH   r)   s      r*   r/   z%BaseThresholdClassifier.predict_proba�   s9   € õ 	˜ÑÔÐÝ˜D ,°´Ñ?Ô?ˆ	Ø×&Ò& qÑ)Ô)Ð)r:   Úpredict_log_probac                 óv   — t          | ¦  «         t          | d| j        ¦  «        }|                     |¦  «        S )aì  Predict logarithm class probabilities for `X` using the fitted estimator.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training vectors, where `n_samples` is the number of samples and
            `n_features` is the number of features.

        Returns
        -------
        log_probabilities : ndarray of shape (n_samples, n_classes)
            The logarithm class probabilities of the input samples.
        r(   )r+   rN   r)   rP   rO   s      r*   rP   z)BaseThresholdClassifier.predict_log_proba£   ó9   € õ 	˜ÑÔÐÝ˜D ,°´Ñ?Ô?ˆ	Ø×*Ò*¨1Ñ-Ô-Ð-r:   c                 óv   — t          | ¦  «         t          | d| j        ¦  «        }|                     |¦  «        S )aÎ  Decision function for samples in `X` using the fitted estimator.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training vectors, where `n_samples` is the number of samples and
            `n_features` is the number of features.

        Returns
        -------
        decisions : ndarray of shape (n_samples,)
            The decision function computed the fitted estimator.
        r(   )r+   rN   r)   r0   rO   s      r*   r0   z)BaseThresholdClassifier.decision_function¶   rR   r:   c                 ó°   •— t          ¦   «                              ¦   «         }d|j        _        t	          | j        ¦  «        j        j        |j        _        |S )NF)ÚsuperÚ__sklearn_tags__Úclassifier_tagsÚmulti_classr   r)   Ú
input_tagsÚsparse)r8   ÚtagsÚ	__class__s     €r*   rV   z(BaseThresholdClassifier.__sklearn_tags__É   sB   ø€ Ý‰wŒw×'Ò'Ñ)Ô)ˆØ+0ˆÔÔ(Ý!)¨$¬.Ñ!9Ô!9Ô!DÔ!KˆŒÔØˆr:   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r4   ÚdictÚ__annotations__r9   r<   r	   r.   ÚpropertyrL   r   r#   r/   rP   r0   rV   Ú__classcell__©r\   s   @r*   r-   r-   1   s´  ø€ € € € € € ðð ð8 ˆJ˜˜Ð/Ñ0Ô0ØˆJ˜Ð2Ð3Ñ4Ô4ð
ð '˜JÐ'UÐ'UÐ'UÑVÔVÐWð$ð $Ð˜Dð ð ñ ð 6<ð /ð /ð /ð /ð /ðð ð ð €\à&+ðñ ô ð%ð %ñ	ô ð%ðN ð(ð (ñ „Xð(ð €\�.�. Ñ1Ô1Ñ2Ô2ð*ð *ñ 3Ô2ð*ð$ €\�.�.Ð!4Ñ5Ô5Ñ6Ô6ð.ð .ñ 7Ô6ð.ð$ €\�.�.Ð!4Ñ5Ô5Ñ6Ô6ð.ð .ñ 7Ô6ð.ð$ð ð ð ð ð ð ð ð r:   r-   c                   óœ   ‡ — e Zd ZU dZi ej        ¥ edh¦  «        egeeddgdœ¥Ze	e
d<   ddddœˆ fd„
Zed	„ ¦   «         Zd
„ Zd„ Zd„ Zˆ xZS )ÚFixedThresholdClassifiera§  Binary classifier that manually sets the decision threshold.

    This classifier allows to change the default decision threshold used for
    converting posterior probability estimates (i.e. output of `predict_proba`) or
    decision scores (i.e. output of `decision_function`) into a class label.

    Here, the threshold is not optimized and is set to a constant value.

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

    .. versionadded:: 1.5

    Parameters
    ----------
    estimator : estimator instance
        The binary classifier, fitted or not, for which we want to optimize
        the decision threshold used during `predict`.

    threshold : {"auto"} or float, default="auto"
        The decision threshold to use when converting posterior probability estimates
        (i.e. output of `predict_proba`) or decision scores (i.e. output of
        `decision_function`) into a class label. When `"auto"`, the threshold is set
        to 0.5 if `predict_proba` is used as `response_method`, otherwise it is set to
        0 (i.e. the default threshold for `decision_function`).

    pos_label : int, float, bool or str, default=None
        The label of the positive class. Used to process the output of the
        `response_method` method. 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.

    response_method : {"auto", "decision_function", "predict_proba"}, default="auto"
        Methods by the classifier `estimator` corresponding to the
        decision function for which we want to find a threshold. It can be:

        * if `"auto"`, it will try to invoke `"predict_proba"` or `"decision_function"`
          in that order.
        * otherwise, one of `"predict_proba"` or `"decision_function"`.
          If the method is not implemented by the classifier, it will raise an
          error.

    Attributes
    ----------
    estimator_ : estimator instance
        The fitted classifier used when predicting.

    classes_ : ndarray of shape (n_classes,)
        The class labels.

    n_features_in_ : int
        Number of features seen during :term:`fit`. Only defined if the
        underlying estimator exposes such an attribute when fit.

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Only defined if the
        underlying estimator exposes such an attribute when fit.

    See Also
    --------
    sklearn.model_selection.TunedThresholdClassifierCV : Classifier that post-tunes
        the decision threshold based on some metrics and using cross-validation.
    sklearn.calibration.CalibratedClassifierCV : Estimator that calibrates
        probabilities.

    Examples
    --------
    >>> from sklearn.datasets import make_classification
    >>> from sklearn.linear_model import LogisticRegression
    >>> from sklearn.metrics import confusion_matrix
    >>> from sklearn.model_selection import FixedThresholdClassifier, train_test_split
    >>> X, y = make_classification(
    ...     n_samples=1_000, weights=[0.9, 0.1], class_sep=0.8, random_state=42
    ... )
    >>> X_train, X_test, y_train, y_test = train_test_split(
    ...     X, y, stratify=y, random_state=42
    ... )
    >>> classifier = LogisticRegression(random_state=0).fit(X_train, y_train)
    >>> print(confusion_matrix(y_test, classifier.predict(X_test)))
    [[217   7]
     [ 19   7]]
    >>> classifier_other_threshold = FixedThresholdClassifier(
    ...     classifier, threshold=0.1, response_method="predict_proba"
    ... ).fit(X_train, y_train)
    >>> print(confusion_matrix(y_test, classifier_other_threshold.predict(X_test)))
    [[184  40]
     [  6  20]]
    r1   ÚbooleanN)Ú	thresholdÚ	pos_labelr4   )ri   rj   r3   c                ój   •— t          ¦   «                              ||¬¦  «         || _        || _        d S ©Nr2   )rU   r9   rj   ri   )r8   r)   ri   rj   r3   r\   s        €r*   r9   z!FixedThresholdClassifier.__init__.  s4   ø€ õ 	‰Œ×Ò 9¸oÐÑNÔNÐNØ"ˆŒØ"ˆŒˆˆr:   c                 ó¾   — t          | dd ¦  «        x}r|j        S 	 t          | j        ¦  «         | j        j        S # t          $ r t          d¦  «        t          ‚w xY w)Nr(   z+The underlying estimator is not fitted yet.)rN   rL   r%   r)   r   ÚAttributeError©r8   r)   s     r*   rL   z!FixedThresholdClassifier.classes_:  sw   € å  l°DÑ9Ô9Ð9ˆ9ð 	&ØÔ%Ð%ð	"Ý˜DœNÑ+Ô+Ð+Ø”>Ô*Ð*øÝð 	"ð 	"ð 	"Ý Ø=ñô å!ð"ð	"øøøs	   œ< ¼ Ac                 ó‚   — t          | dfi |¤Ž} t          | j        ¦  «        j        ||fi |j        j        ¤Ž| _        | S )r?   r.   )r   r
   r)   r.   r(   )r8   rH   r@   rI   Úrouted_paramss        r*   rF   zFixedThresholdClassifier._fitF  sN   € õ( (¨¨eÐ>Ð>°vÐ>Ð>ˆØ3�% ¤Ñ/Ô/Ô3°A°qÐXÐX¸MÔ<SÔ<WÐXÐXˆŒØˆr:   c                 ó  — t          | ¦  «         t          | d| j        ¦  «        }t          |||                      ¦   «         | j        d¬¦  «        \  }}}| j        dk    r|dk    rdnd}n| j        }t          ||| j        | j        ¦  «        S )áO  Predict the target of new samples.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            The samples, as accepted by `estimator.predict`.

        Returns
        -------
        class_labels : ndarray of shape (n_samples,)
            The predicted class.
        r(   T)rj   Úreturn_response_method_usedr1   r/   g      à?ç        )	r+   rN   r)   r   r<   rj   ri   r   rL   )r8   rH   r)   Úy_scoreÚ_Úresponse_method_usedÚdecision_thresholds          r*   Úpredictz FixedThresholdClassifier.predict^  s­   € õ 	˜ÑÔÐå˜D ,°´Ñ?Ô?ˆ	å+FØØØ×%Ò%Ñ'Ô'Ø”nØ(,ð,
ñ ,
ô ,
Ñ(ˆ�Ð(ð Œ>˜VÒ#Ð#Ø(<ÀÒ(OÐ(O  ÐUXÐÐà!%¤Ðå0ØÐ'¨¬¸¼ñ
ô 
ð 	
r:   c                 óœ   — t          | ¬¦  «                             | j        t          ¦   «                              dd¬¦  «        ¬¦  «        }|S )áK  Get metadata routing of this object.

        Please check :ref:`User Guide <metadata_routing>` on how the routing
        mechanism works.

        Returns
        -------
        routing : MetadataRouter
            A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating
            routing information.
        ©Úownerr.   ©ÚcalleeÚcaller©r)   Úmethod_mapping)r   Úaddr)   r   ©r8   Úrouters     r*   Úget_metadata_routingz-FixedThresholdClassifier.get_metadata_routing€  sO   € õ   dÐ+Ñ+Ô+×/Ò/Ø”nÝ(™?œ?×.Ò.°eÀEÐ.ÑJÔJð 0ñ 
ô 
ˆð ˆr:   )r]   r^   r_   r`   r-   r4   r   r   Ústrra   rb   r9   rc   rL   rF   rz   r‡   rd   re   s   @r*   rg   rg   Ð   sø   ø€ € € € € € ðUð Uðn$Ø
!Ô
8ð$à �j & Ñ*Ô*¨DÐ1Ø˜C ¨DÐ1ð$ð $ð $Ð˜Dð ð ñ ð ØØð
#ð 
#ð 
#ð 
#ð 
#ð 
#ð 
#ð ð	"ð 	"ñ „Xð	"ðð ð ð0 
ð  
ð  
ðDð ð ð ð ð ð r:   rg   c                ó  — |�tt          ||¦  «        t          ||¦  «        }	}t          ||¦  «        t          ||¦  «        }}
t          |||¬¦  «        }t          |||¬¦  «        } | j        ||
fi |¤Ž n|||}}}	 || |	|fi |¤ŽS )a»  Fit a classifier and compute the scores for different decision thresholds.

    Parameters
    ----------
    classifier : estimator instance
        The classifier to fit and use for scoring. If `classifier` is already fitted,
        it will be used as is.

    X : {array-like, sparse matrix} of shape (n_samples, n_features)
        The entire dataset.

    y : array-like of shape (n_samples,)
        The entire target vector.

    fit_params : dict
        Parameters to pass to the `fit` method of the underlying classifier.

    train_idx : ndarray of shape (n_train_samples,) or None
        The indices of the training set. If `None`, `classifier` is expected to be
        already fitted.

    val_idx : ndarray of shape (n_val_samples,)
        The indices of the validation set used to score `classifier`. If `train_idx`,
        the entire set will be used.

    curve_scorer : scorer instance
        The scorer taking `classifier` and the validation set as input and outputting
        decision thresholds and scores as a curve. Note that this is different from
        the usual scorer that outputs a single score value as `curve_scorer`
        outputs a single score value for each threshold.

    score_params : dict
        Parameters to pass to the `score` method of the underlying scorer.

    Returns
    -------
    scores : ndarray of shape (thresholds,) or tuple of such arrays
        The scores computed for each decision threshold. When TPR/TNR or precision/
        recall are computed, `scores` is a tuple of two arrays.

    potential_thresholds : ndarray of shape (thresholds,)
        The decision thresholds used to compute the scores. They are returned in
        ascending order.
    N©Úindices)r   r"   r.   )Ú
classifierrH   r@   Ú
fit_paramsÚ	train_idxÚval_idxÚcurve_scorerÚscore_paramsÚX_trainÚX_valÚy_trainÚy_valÚfit_params_trainÚscore_params_vals                 r*   Ú_fit_and_score_over_thresholdsr˜   “  sº   € ðp ÐÝ'¨¨9Ñ5Ô5µ~ÀaÈÑ7QÔ7Q�ˆÝ'¨¨9Ñ5Ô5µ~ÀaÈÑ7QÔ7Q�ˆÝ/°°:ÀyÐQÑQÔQÐÝ/°°<ÈÐQÑQÔQÐØˆ
Œ�w Ð<Ð<Ð+;Ð<Ð<Ð<Ð<à)*¨A¨|Ð&ˆuˆàˆ<˜
 E¨5ÐEÐEÐ4DÐEÐEÐEr:   c                 ód   ‡ — t          j        ˆ fd„t          ||¦  «        D ¦   «         d¬¦  «        S )al  Compute the mean interpolated score across folds by defining common thresholds.

    Parameters
    ----------
    target_thresholds : ndarray of shape (thresholds,)
        The thresholds to use to compute the mean score.

    cv_thresholds : ndarray of shape (n_folds, thresholds_fold)
        The thresholds used to compute the scores for each fold.

    cv_scores : ndarray of shape (n_folds, thresholds_fold)
        The scores computed for each threshold for each fold.

    Returns
    -------
    mean_score : ndarray of shape (thresholds,)
        The mean score across all folds for each target threshold.
    c                 óB   •— g | ]\  }}t          j        ‰||¦  «        ‘ŒS © )ÚnpÚinterp)Ú.0Úsplit_thresholdsÚsplit_scoreÚtarget_thresholdss      €r*   ú
<listcomp>z,_mean_interpolated_score.<locals>.<listcomp>ë  s>   ø€ ð 	
ð 	
ð 	
á-Ð  +õ ŒIÐ'Ð)9¸;ÑGÔGð	
ð 	
ð 	
r:   r   )Úaxis)rœ   ÚmeanÚzip)r¡   Úcv_thresholdsÚ	cv_scoress   `  r*   Ú_mean_interpolated_scorer¨   ×  sS   ø€ õ& Œ7ð	
ð 	
ð 	
ð 	
å14°]ÀIÑ1NÔ1Nð	
ñ 	
ô 	
ð ðñ ô ð r:   c                   ó  ‡ — e Zd ZU dZi ej        ¥ e e e¦   «         ¦  «        ¦  «        e	e
g eeddd¬¦  «        dgd edh¦  «         eed	d
d¬¦  «        gdgedgdgdgdœ¥Zeed<   dddddddddœˆ fd„
Zd„ Zd„ Zd„ Zd„ Zd„ Zˆ xZS )ÚTunedThresholdClassifierCVa„  Classifier that post-tunes the decision threshold using cross-validation.

    This estimator post-tunes the decision threshold (cut-off point) that is
    used for converting posterior probability estimates (i.e. output of
    `predict_proba`) or decision scores (i.e. output of `decision_function`)
    into a class label. The tuning is done by optimizing a binary metric,
    potentially constrained by another metric.

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

    .. versionadded:: 1.5

    Parameters
    ----------
    estimator : estimator instance
        The classifier, fitted or not, for which we want to optimize
        the decision threshold used during `predict`.

    scoring : str or callable, default="balanced_accuracy"
        The objective metric to be optimized. Can be one of:

        - str: string associated to a scoring function for binary classification,
          see :ref:`scoring_string_names` for options.
        - callable: a scorer callable object (e.g., function) with signature
          ``scorer(estimator, X, y)``. See :ref:`scoring_callable` for details.

    response_method : {"auto", "decision_function", "predict_proba"}, default="auto"
        Methods by the classifier `estimator` corresponding to the
        decision function for which we want to find a threshold. It can be:

        * if `"auto"`, it will try to invoke, for each classifier,
          `"predict_proba"` or `"decision_function"` in that order.
        * otherwise, one of `"predict_proba"` or `"decision_function"`.
          If the method is not implemented by the classifier, it will raise an
          error.

    thresholds : int or array-like, default=100
        The number of decision threshold to use when discretizing the output of the
        classifier `method`. Pass an array-like to manually specify the thresholds
        to use.

    cv : int, float, cross-validation generator, iterable or "prefit", default=None
        Determines the cross-validation splitting strategy to train classifier.
        Possible inputs for cv are:

        * `None`, to use the default 5-fold stratified K-fold cross validation;
        * An integer number, to specify the number of folds in a stratified k-fold;
        * A float number, to specify a single shuffle split. The floating number should
          be in (0, 1) and represent the size of the validation set;
        * An object to be used as a cross-validation generator;
        * An iterable yielding train, test splits;
        * `"prefit"`, to bypass the cross-validation.

        Refer :ref:`User Guide <cross_validation>` for the various
        cross-validation strategies that can be used here.

        .. warning::
            Using `cv="prefit"` and passing the same dataset for fitting `estimator`
            and tuning the cut-off point is subject to undesired overfitting. You can
            refer to :ref:`TunedThresholdClassifierCV_no_cv` for an example.

            This option should only be used when the set used to fit `estimator` is
            different from the one used to tune the cut-off point (by calling
            :meth:`TunedThresholdClassifierCV.fit`).

    refit : bool, default=True
        Whether or not to refit the classifier on the entire training set once
        the decision threshold has been found.
        Note that forcing `refit=False` on cross-validation having more
        than a single split will raise an error. Similarly, `refit=True` in
        conjunction with `cv="prefit"` will raise an error.

    n_jobs : int, default=None
        The number of jobs to run in parallel. When `cv` represents a
        cross-validation strategy, the fitting and scoring on each data split
        is done in parallel. ``None`` means 1 unless in a
        :obj:`joblib.parallel_backend` context. ``-1`` means using all
        processors. See :term:`Glossary <n_jobs>` for more details.

    random_state : int, RandomState instance or None, default=None
        Controls the randomness of cross-validation when `cv` is a float.
        See :term:`Glossary <random_state>`.

    store_cv_results : bool, default=False
        Whether to store all scores and thresholds computed during the cross-validation
        process.

    Attributes
    ----------
    estimator_ : estimator instance
        The fitted classifier used when predicting.

    best_threshold_ : float
        The new decision threshold.

    best_score_ : float or None
        The optimal score of the objective metric, evaluated at `best_threshold_`.

    cv_results_ : dict or None
        A dictionary containing the scores and thresholds computed during the
        cross-validation process. Only exist if `store_cv_results=True`. The
        keys are `"thresholds"` and `"scores"`.

    classes_ : ndarray of shape (n_classes,)
        The class labels.

    n_features_in_ : int
        Number of features seen during :term:`fit`. Only defined if the
        underlying estimator exposes such an attribute when fit.

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Only defined if the
        underlying estimator exposes such an attribute when fit.

    See Also
    --------
    sklearn.model_selection.FixedThresholdClassifier : Classifier that uses a
        constant threshold.
    sklearn.calibration.CalibratedClassifierCV : Estimator that calibrates
        probabilities.

    Examples
    --------
    >>> from sklearn.datasets import make_classification
    >>> from sklearn.ensemble import RandomForestClassifier
    >>> from sklearn.metrics import classification_report
    >>> from sklearn.model_selection import TunedThresholdClassifierCV, train_test_split
    >>> X, y = make_classification(
    ...     n_samples=1_000, weights=[0.9, 0.1], class_sep=0.8, random_state=42
    ... )
    >>> X_train, X_test, y_train, y_test = train_test_split(
    ...     X, y, stratify=y, random_state=42
    ... )
    >>> classifier = RandomForestClassifier(random_state=0).fit(X_train, y_train)
    >>> print(classification_report(y_test, classifier.predict(X_test)))
                  precision    recall  f1-score   support
    <BLANKLINE>
               0       0.94      0.99      0.96       224
               1       0.80      0.46      0.59        26
    <BLANKLINE>
        accuracy                           0.93       250
       macro avg       0.87      0.72      0.77       250
    weighted avg       0.93      0.93      0.92       250
    <BLANKLINE>
    >>> classifier_tuned = TunedThresholdClassifierCV(
    ...     classifier, scoring="balanced_accuracy"
    ... ).fit(X_train, y_train)
    >>> print(
    ...     f"Cut-off point found at {classifier_tuned.best_threshold_:.3f}"
    ... )
    Cut-off point found at 0.342
    >>> print(classification_report(y_test, classifier_tuned.predict(X_test)))
                  precision    recall  f1-score   support
    <BLANKLINE>
               0       0.96      0.95      0.96       224
               1       0.61      0.65      0.63        26
    <BLANKLINE>
        accuracy                           0.92       250
       macro avg       0.78      0.80      0.79       250
    weighted avg       0.92      0.92      0.92       250
    <BLANKLINE>
    é   NÚleft)Úclosedz
array-likeÚ	cv_objectÚprefitru   g      ð?Úneitherrh   Úrandom_state)ÚscoringÚ
thresholdsÚcvÚrefitÚn_jobsr±   Ústore_cv_resultsr4   Úbalanced_accuracyr1   éd   TF)r²   r3   r³   r´   rµ   r¶   r±   r·   c                ó°   •— t          ¦   «                              ||¬¦  «         || _        || _        || _        || _        || _        || _        |	| _        d S rl   )	rU   r9   r²   r³   r´   rµ   r¶   r±   r·   )r8   r)   r²   r3   r³   r´   rµ   r¶   r±   r·   r\   s             €r*   r9   z#TunedThresholdClassifierCV.__init__ª  s[   ø€ õ 	‰Œ×Ò 9¸oÐÑNÔNÐNØˆŒØ$ˆŒØˆŒØˆŒ
ØˆŒØ(ˆÔØ 0ˆÔÐÐr:   c           
      óÔ  ‡ ‡‡‡‡‡— t          ‰ j        t          ¦  «        r2d‰ j        cxk     rdk     r n nt          d‰ j        ‰ j        ¬¦  «        Šn«‰ j        dk    rY‰ j        du rt          d¦  «        ‚	 t          ‰ j        d¦  «         n"# t          $ r}t          d¦  «        |‚d	}~ww xY w‰ j        ŠnGt          ‰ j        ‰d¬
¦  «        Š‰ j        du r'‰                     ¦   «         dk    rt          d¦  «        ‚t          ‰ dfi |¤ŽŠ‰                      ¦   «         ‰ _        ‰dk    r3‰ j        ‰ _        ‰ j        Šd	t!          t#          ‰¦  «        ¦  «        fg}n×t%          ‰ j        ¦  «        ‰ _        t%          ‰ j        ¦  «        Š ‰j        ‰‰fi ‰j        j        ¤Ž}‰ j        r‰‰‰j        j        }}}net-           ‰j        ‰‰fi ‰j        j        ¤Ž¦  «        \  }	}
t/          ‰|	¦  «        }t/          ‰|	¦  «        }t1          ‰‰j        j        |	¬¦  «        } ‰ j        j        ||fi |¤Ž t3           t5          ‰ j        ¬¦  «        ˆˆˆˆˆ ˆfd„|D ¦   «         ¦  «        Ž \  }}t9          d„ |D ¦   «         ¦  «        rt          d¦  «        ‚t;          d„ |D ¦   «         ¦  «        }t=          d„ |D ¦   «         ¦  «        }t          ‰ j        t@          ¦  «        rtC          j"        ||‰ j        ¬¦  «        }ntC          j#        ‰ j        ¦  «        }tI          |||¦  «        }| %                    ¦   «         }||         ‰ _&        ||         ‰ _'        ‰ j(        r
||dœ‰ _)        ‰ S )a  Fit the classifier and post-tune the decision threshold.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training data.

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

        **params : dict
            Parameters to pass to the `fit` method of the underlying
            classifier and to the `scoring` scorer.

        Returns
        -------
        self : object
            Returns an instance of self.
        r   r«   )Ún_splitsÚ	test_sizer±   r¯   Tz'When cv='prefit', refit cannot be True.rL   z-When cv='prefit', `estimator` must be fitted.N)r@   rŒ   Fz1When cv has several folds, refit cannot be False.r.   rŠ   )r¶   c              3   óÄ   •K  — | ]Z\  }} t          t          ¦  «        ‰d k    rt          ‰¦  «        n‰‰‰‰j        j        ||‰j        ‰j        j        ¬¦  «        V — Œ[dS )r¯   )r�   rŽ   r�   r�   r‘   N)r!   r˜   r
   r)   r.   Ú_curve_scorerÚscorerÚscore)	rž   rŽ   r�   rH   rŒ   r´   rq   r8   r@   s	      €€€€€€r*   ú	<genexpr>z2TunedThresholdClassifierCV._fit.<locals>.<genexpr>  s“   øè è € ð *ð *ñ '�I˜wð 8•Õ6Ñ7Ô7Ø)+¨xª¨•E˜*Ñ%Ô%Ð%¸ZØØØ,Ô6Ô:Ø'Ø#Ø!%Ô!3Ø!.Ô!5Ô!;ð	ñ 	ô 	ð*ð *ð *ð *ð *ð *r:   c              3   óX   K  — | ]%}t          j        |d          |d         ¦  «        V — Œ&dS )r   éÿÿÿÿN)rœ   Úisclose)rž   Úths     r*   rÂ   z2TunedThresholdClassifierCV._fit.<locals>.<genexpr>  s6   è è € ÐAÐA¨R�rŒz˜"˜Qœ%  B¤Ñ(Ô(ÐAÐAÐAÐAÐAÐAr:   zrThe provided estimator makes constant predictions. Therefore, it is impossible to optimize the decision threshold.c              3   ó>   K  — | ]}|                      ¦   «         V — Œd S r7   )Úmin©rž   rŸ   s     r*   rÂ   z2TunedThresholdClassifierCV._fit.<locals>.<genexpr>  ó@   è è € ð 
ð 
Ø'7Ð× Ò Ñ"Ô"ð
ð 
ð 
ð 
ð 
ð 
r:   c              3   ó>   K  — | ]}|                      ¦   «         V — Œd S r7   )ÚmaxrÉ   s     r*   rÂ   z2TunedThresholdClassifierCV._fit.<locals>.<genexpr>  rÊ   r:   )Únum)r³   Úscores)*Ú
isinstancer´   r   r   r±   rµ   rE   r%   r)   r   r   Úget_n_splitsr   Ú_get_curve_scorerr¿   r(   Úranger$   r
   ÚsplitÚsplitterr.   Únextr   r"   r¥   r    r¶   ÚanyrÈ   rÌ   r³   r   rœ   ÚlinspaceÚasarrayr¨   ÚargmaxÚbest_score_Úbest_threshold_r·   Úcv_results_)r8   rH   r@   rI   ÚexcÚsplitsr’   r”   r–   rŽ   rw   r§   r¦   Úmin_thresholdÚmax_thresholdÚdecision_thresholdsÚobjective_scoresÚbest_idxrŒ   r´   rq   s   ```               @@@r*   rF   zTunedThresholdClassifierCV._fitÀ  s4  øøøøøø€ õ( �d”g�tÑ$Ô$ð 	V¨¨T¬W¨¨ª¨°qª¨¨¨¨Ý'Ø d¤g¸DÔ<Mðñ ô ˆBˆBð ŒW˜Ò Ð ØŒz˜TÐ!Ð!Ý Ð!JÑKÔKÐKðÝ ¤°
Ñ;Ô;Ð;Ð;øÝ!ð ð ð Ý$ØGñô àðøøøøðøøøð ”ˆBˆBå˜$œ' Q°4Ð8Ñ8Ô8ˆBØŒz˜UÐ"Ð" r§¢Ñ'8Ô'8¸1Ò'<Ð'<Ý Ð!TÑUÔUÐUå'¨¨eÐ>Ð>°vÐ>Ð>ˆØ!×3Ò3Ñ5Ô5ˆÔð �Š>ˆ>Ø"œnˆDŒOØœˆJØ�U¥<°¡?¤?Ñ3Ô3Ð4Ð5ˆFˆFå# D¤NÑ3Ô3ˆDŒOÝ˜tœ~Ñ.Ô.ˆJØ�R”X˜a ÐCÐC mÔ&<Ô&BÐCÐCˆFàŒzð 
à56¸¸=Ô;RÔ;VÐ"2˜��õ  $ H B¤H¨Q°Ð$RÐ$R°]Ô5KÔ5QÐ$RÐ$RÑSÔS‘�	˜1Ý(¨¨IÑ6Ô6�Ý(¨¨IÑ6Ô6�Ý#7Ø�}Ô.Ô2¸Ið$ñ $ô $Ð ð  ˆDŒOÔ ¨ÐEÐEÐ4DÐEÐEÐEå#&Ø)�X˜Tœ[Ð)Ñ)Ô)ð *ð *ð *ð *ð *ð *ð *ð *ð *ð +1ð*ñ *ô *ñ ô ð$
Ñ ˆ	�=õ  ÐAÐA°=ÐAÑAÔAÑAÔAð 	ÝðAñô ð õ ð 
ð 
Ø;Hð
ñ 
ô 
ñ 
ô 
ˆõ ð 
ð 
Ø;Hð
ñ 
ô 
ñ 
ô 
ˆõ �d”o¥xÑ0Ô0ð 	>Ý"$¤+Ø˜}°$´/ð#ñ #ô #ÐÐõ #%¤*¨T¬_Ñ"=Ô"=Ðå3Ø °	ñ
ô 
Ðð $×*Ò*Ñ,Ô,ˆØ+¨HÔ5ˆÔØ2°8Ô<ˆÔØÔ ð 	à1Ø*ð ð  ˆDÔð
 ˆs   Á7B Â
B,ÂB'Â'B,c                 óæ   — t          | d¦  «         | j                             ¦   «         }t          | j        ||                      ¦   «         |¬¦  «        \  }}t          || j        | j        |¦  «        S )rs   r(   )rj   )	r%   r¿   Ú_get_pos_labelr   r(   r<   r   rÛ   rL   )r8   rH   rj   rv   rw   s        r*   rz   z"TunedThresholdClassifierCV.predict7  s|   € õ 	˜˜lÑ+Ô+Ð+ØÔ&×5Ò5Ñ7Ô7ˆ	Ý0ØŒOØØ×%Ò%Ñ'Ô'Øð	
ñ 
ô 
‰
ˆ�õ 1Ø�TÔ)¨4¬=¸)ñ
ô 
ð 	
r:   c                 ó¢  — t          | ¬¦  «                             | j        t          ¦   «                              dd¬¦  «        ¬¦  «                             | j        t          ¦   «                              dd¬¦  «        ¬¦  «                             |                      ¦   «         t          ¦   «                              dd¬¦  «        ¬¦  «        }|S )	r|   r}   r.   r   r‚   rÓ   )rÔ   rƒ   rÁ   )rÀ   rƒ   )r   r„   r)   r   r´   rÑ   r…   s     r*   r‡   z/TunedThresholdClassifierCV.get_metadata_routingQ  sÅ   € õ  Ð&Ñ&Ô&ßŠSØœ.Ý,™œ×2Ò2¸%ÈÐ2ÑNÔNð ñ ô ÷ ŠSØœÝ,™œ×2Ò2¸'È%Ð2ÑPÔPð ñ ô ÷ ŠSØ×-Ò-Ñ/Ô/Ý,™œ×2Ò2¸'È%Ð2ÑPÔPð ñ ô ð 	ð ˆr:   c                 ó–   — t          | j        | j        ¬¦  «        }t          j        ||                      ¦   «         | j        ¦  «        }|S )z8Get the curve scorer based on the objective metric used.)r²   )r   r)   r²   r   Úfrom_scorerr<   r³   )r8   r²   r�   s      r*   rÑ   z,TunedThresholdClassifierCV._get_curve_scorern  sG   € å ¤¸¼ÐEÑEÔEˆÝ#Ô/Ø�T×.Ò.Ñ0Ô0°$´/ñ
ô 
ˆð Ðr:   c                 óŠ   — t          | d| j        ¦  «        }t          d|g|j        j        gt          |¦  «        gd¬¦  «        S )Nr(   ÚserialF)ÚnamesÚname_detailsÚdash_wrapped)rN   r)   r   r\   r]   rˆ   ro   s     r*   Ú_sk_visual_block_z,TunedThresholdClassifierCV._sk_visual_block_v  sO   € Ý˜D ,°´Ñ?Ô?ˆ	ÝØØˆKØÔ&Ô/Ð0Ý˜i™.œ.Ð)Øð
ñ 
ô 
ð 	
r:   )r]   r^   r_   r`   r-   r4   r   Úsetr   Úcallabler   r   r   r   ra   rb   r9   rF   rz   r‡   rÑ   rî   rd   re   s   @r*   rª   rª   ó  s  ø€ € € € € € ðað aðF$Ø
!Ô
8ð$ð ˆJ�s�sÐ+Ð+Ñ-Ô-Ñ.Ô.Ñ/Ô/ØØð
ð
  �x ¨!¨T¸&ÐAÑAÔAÀ<ÐPàØˆJ˜�zÑ"Ô"ØˆH�Z  c°)Ð<Ñ<Ô<ð
ð
 �Ø˜TÐ"Ø'Ð(Ø&˜Kð!$ð $ð $Ð˜Dð ð ñ ð. $ØØØØØØØð1ð 1ð 1ð 1ð 1ð 1ð 1ð,uð uð uðn
ð 
ð 
ð4ð ð ð:ð ð ð
ð 
ð 
ð 
ð 
ð 
ð 
r:   rª   )<Úcollections.abcr   Únumbersr   r   Únumpyrœ   Úsklearn.baser   r   r   r	   r
   Úsklearn.exceptionsr   Úsklearn.metricsr   r   Úsklearn.metrics._scorerr   r   Úsklearn.model_selection._splitr   r   Úsklearn.utilsr   r   Úsklearn.utils._param_validationr   r   r   r   Ú"sklearn.utils._repr_html.estimatorr   Úsklearn.utils._responser   Úsklearn.utils.metadata_routingr   r   r   r   Úsklearn.utils.metaestimatorsr   Úsklearn.utils.multiclassr   Úsklearn.utils.parallelr    r!   Úsklearn.utils.validationr"   r#   r$   r%   r&   r+   r-   rg   r˜   r¨   rª   r›   r:   r*   ú<module>r     sÞ  ðð +Ð *Ð *Ð *Ð *Ð *Ø "Ð "Ð "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð ðð ð ð ð ð ð ð ð ð ð ð ð ð ð .Ð -Ð -Ð -Ð -Ð -Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø SÐ SÐ SÐ SÐ SÐ SÐ SÐ SØ KÐ KÐ KÐ KÐ KÐ KÐ KÐ KØ 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XØ ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø ?Ð ?Ð ?Ð ?Ð ?Ð ?ðð ð ð ð ð ð ð ð ð ð ð ð 6Ð 5Ð 5Ð 5Ð 5Ð 5Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4ðð ð ð ð ð ð ð ð ð ð ð ð ð ð1ð 1ð 1ð\ð \ð \ð \ð \˜oÐ/AÀ=ñ \ô \ð \ð~@ð @ð @ð @ð @Ð6ñ @ô @ð @ðFAFð AFð AFðHð ð ð8K
ð K
ð K
ð K
ð K
Ð!8ñ K
ô K
ð K
ð K
ð K
r:   