
    -i}                     h   S SK Jr  S SKJrJr  S SKrSSKJrJ	r	J
r
JrJr  SSKJr  SSKJrJr  SSKJrJr  SS	KJrJr  SS
KJrJrJrJr  SSKJr  SSKJ r J!r!J"r"J#r#  SSK$J%r%  SSK&J'r'  SSK(J)r)J*r*  SSK+J,r,J-r-J.r.J/r/J0r0  SSK1J2r2J3r3  S r4 " S S\	\
\5      r5 " S S\55      r6S r7S r8 " S S\55      r9g)    )MutableMapping)IntegralRealN   )BaseEstimatorClassifierMixinMetaEstimatorMixin_fit_contextclone)NotFittedError)check_scoringget_scorer_names)_CurveScorer!_threshold_scores_to_class_labels)_safe_indexingget_tags)
HasMethodsInterval
RealNotInt
StrOptions)_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	indexable   )StratifiedShuffleSplitcheck_cvc                 h     [        U R                  5        g ! [         a    [        U S5         g f = f)N
estimator_)r#   	estimatorr   )r*   s    d/var/www/html/venv/lib/python3.13/site-packages/sklearn/model_selection/_classification_threshold.py_check_is_fittedr,   /   s.    1	++, 1	<01s    11c                   ,  ^  \ rS rSr% Sr\" SS/5      \" SS/5      /\" 1 Sk5      /S.r\\	S'   S	S
.S jr
S r\" SS9S 5       r\S 5       r\" \" S5      5      S 5       r\" \" S5      5      S 5       r\" \" S5      5      S 5       rU 4S jrSrU =r$ )BaseThresholdClassifier6   a  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>   autor1   r2   r*   response_method_parameter_constraintsr3   r5   c                    Xl         X l        g Nr4   )selfr*   r5   s      r+   __init__ BaseThresholdClassifier.__init__Y   s    ".    c                 J    U R                   S:X  a  SS/nU$ U R                   nU$ )zDefine the response method.r3   r1   r2   r7   )r:   r5   s     r+   _get_response_method,BaseThresholdClassifier._get_response_method]   s6    6).0CDO  #22Or=   F)prefer_skip_nested_validationc                 r   [        X0S5        [        X5      u  p[        USS9nUS:w  a  [        SU 35      eU R                  " X40 UD6  [        U R                  S5      (       a  U R                  R                  U l        [        U R                  S5      (       a  U R                  R                  U l        U $ )V  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)   rG   rH   )r:   XrD   paramsy_types        r+   r0   BaseThresholdClassifier.fite   s    0 	&-c2XOPVxX  			!!&!4??$455"&//"@"@D4??$788%)__%F%FD"r=   c                 .    U R                   R                  $ )zClasses labels.)r)   classes_)r:   s    r+   rQ    BaseThresholdClassifier.classes_   s     '''r=   c                 h    [        U 5        [        U SU R                  5      nUR                  U5      $ )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*   r1   r:   rL   r*   s      r+   r1   %BaseThresholdClassifier.predict_proba   s/     	D,?	&&q))r=   predict_log_probac                 h    [        U 5        [        U SU R                  5      nUR                  U5      $ )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,   rT   r*   rW   rU   s      r+   rW   )BaseThresholdClassifier.predict_log_proba   /     	D,?	**1--r=   c                 h    [        U 5        [        U SU R                  5      nUR                  U5      $ )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,   rT   r*   r2   rU   s      r+   r2   )BaseThresholdClassifier.decision_function   rZ   r=   c                    > [         TU ]  5       nSUR                  l        [	        U R
                  5      R                  R                  UR                  l        U$ )NF)super__sklearn_tags__classifier_tagsmulti_classr   r*   
input_tagssparse)r:   tags	__class__s     r+   r_   (BaseThresholdClassifier.__sklearn_tags__   sD    w')+0(!)$..!9!D!D!K!Kr=   )r*   rH   rG   r5   )__name__
__module____qualname____firstlineno____doc__r   r   r6   dict__annotations__r;   r?   r
   r0   propertyrQ   r   r!   r1   rW   r2   r_   __static_attributes____classcell__re   s   @r+   r.   r.   6   s    8 /0234
 ''UVW$D  6< / &+%	%N ( ( .12* 3*$ .!456. 7.$ .!456. 7.$ r=   r.   c                      ^  \ rS rSr% Sr0 \R                  E\" S15      \/\\	SS/S.Er\
\S'   SSSS.U 4S	 jjr\S
 5       rS rS rS rSrU =r$ )FixedThresholdClassifier   a  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]]
r3   booleanN)	threshold	pos_labelr6   )rv   rw   r5   c                8   > [         TU ]  XS9  X0l        X l        g Nr4   )r^   r;   rw   rv   )r:   r*   rv   rw   r5   re   s        r+   r;   !FixedThresholdClassifier.__init__3  s     	9N""r=   c                     [        U SS 5      =n(       a  UR                  $  [        U R                  5        U R                  R                  $ ! [         a    [        S5      [        ef = f)Nr)   z+The underlying estimator is not fitted yet.)rT   rQ   r#   r*   r   AttributeError)r:   r*   s     r+   rQ   !FixedThresholdClassifier.classes_?  se    lD9999%%%	"DNN+>>*** 	" =!"	"s   *A A(c                     [        U S40 UD6n[        U R                  5      R                  " X40 UR                  R                  D6U l        U $ )rC   r0   )r   r   r*   r0   r)   )r:   rL   rD   rM   routed_paramss        r+   rJ   FixedThresholdClassifier._fitK  sF    ( (e>v>/33AXM<S<S<W<WXr=   c                 &   [        U 5        [        U SU R                  5      n[        UUU R	                  5       U R
                  SS9u  p4nU R                  S:X  a  US:X  a  SOSnOU R                  n[        X6U R                  U R
                  5      $ )  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)rw   return_response_method_usedr3   r1   g      ?        )	r,   rT   r*   r   r?   rw   rv   r   rQ   )r:   rL   r*   y_score_response_method_useddecision_thresholds          r+   predict FixedThresholdClassifier.predictc  s     	D,?	+F%%'nn(,,
(( >>V#(<(OUX!%0
 	
r=   c                     [        U R                  R                  S9R                  U R                  [        5       R                  SSS9S9nU$ )  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.
ownerr0   calleecallerr*   method_mapping)r   re   rg   addr*   r   r:   routers     r+   get_metadata_routing-FixedThresholdClassifier.get_metadata_routing  sL      dnn&=&=>BBnn(?..eE.J C 
 r=   )r)   rw   rv   )rg   rh   ri   rj   rk   r.   r6   r   r   strrl   rm   r;   rn   rQ   rJ   r   r   ro   rp   rq   s   @r+   rs   rs      s    Un$
!
8
8$ &*D1CD1$D  
# 
# 	" 	"0 
D r=   rs   c                    UbR  [        X5      [        X5      p[        X$5      [        X%5      p[        XUS9n[        XUS9nU R                  " X40 UD6  OXUpn	U" X	U40 UD6$ )a7  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.
indices)r   r    r0   )
classifierrL   rD   
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     sv    p '5~a7Q'5~a7Q/yQ/Qw<+;<)*|&
5E4DEEr=   c                     [         R                  " [        X5       VVs/ s H  u  p4[         R                  " XU5      PM     snnSS9$ s  snnf )a8  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.
r   )axis)npmeanzipinterp)target_thresholdscv_thresholds	cv_scoressplit_thresholdssplit_scores        r+   _mean_interpolated_scorer     sQ    & 77 25]1N	
1N-  II';G1N	
  	
s   #A	
c                      ^  \ rS rSr% Sr0 \R                  E\" \" \	" 5       5      5      \
\/\" \SSSS9S/S\" S	15      \" \S
SSS9/S/\S/S/S/S.Er\\S'   SSSSSSSSS.U 4S jjrS rS rS rS rSrU =r$ )TunedThresholdClassifierCVi  ax  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 a another metric.

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

.. 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>
r%   Nleft)closedz
array-like	cv_objectprefitr   g      ?neitherru   random_state)scoring
thresholdscvrefitn_jobsr   store_cv_resultsr6   balanced_accuracyr3   d   TF)r   r5   r   r   r   r   r   r   c                t   > [         T
U ]  XS9  X l        X@l        XPl        X`l        Xpl        Xl        Xl        g ry   )	r^   r;   r   r   r   r   r   r   r   )r:   r*   r   r5   r   r   r   r   r   r   re   s             r+   r;   #TunedThresholdClassifierCV.__init__  s:     	9N$
( 0r=   c           
      0  ^ ^^^^^ [        T R                  [        5      (       a:  ST R                  s=:  a  S:  a#  O  O [        ST R                  T R                  S9mOT R                  S:X  a>  T R
                  SL a  [        S5      e [        T R                  S5        T R                  mOC[        T R                  TSS
9mT R
                  SL a  TR                  5       S:  a  [        S5      e[        T S40 UD6mT R                  5       T l        TS:X  a6  T R                  T l        T R                  mS	[!        [#        T5      5      4/nGO	[%        T R                  5      T l        [%        T R                  5      mTR&                  " TT40 TR(                  R&                  D6nT R
                  (       a  TTTR                  R*                  pnOj[-        TR&                  " TT40 TR(                  R&                  D65      u  p[/        TU	5      n[/        TU	5      n[1        TTR                  R*                  U	S9nT R                  R*                  " Xg40 UD6  [3        [5        T R6                  S9" UUUUU U4S jU 5       5      6 u  p[9        S U 5       5      (       a  [        S5      e[;        S U 5       5      n[=        S U 5       5      n[        T R>                  [@        5      (       a   [B        RD                  " XT R>                  S9nO [B        RF                  " T R>                  5      n[I        XU5      nURK                  5       nUU   T l&        UU   T l'        T RP                  (       a
  UUS.T l)        T $ ! [         a  n[        S5      UeS	nAff = f)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.rQ   z-When cv='prefit', `estimator` must be fitted.N)rD   r   Fz1When cv has several folds, refit cannot be False.r0   r   )r   c              3      >#    U  Hd  u  p[        [        5      " TS :w  a  [        T5      OTTTTR                  R                  UUTR
                  TR                  R                  S9v   Mf     g7f)r   )r   r   r   r   r   N)r   r   r   r*   r0   _curve_scorerscorerscore)	.0r   r   rL   r   r   r   r:   rD   s	      r+   	<genexpr>2TunedThresholdClassifierCV._fit.<locals>.<genexpr>  sm      * +1&I 67)+xE*%Z,66::'#!%!3!3!.!5!5!;!;	 +1s   A,A/c              3   \   #    U  H"  n[         R                  " US    US   5      v   M$     g7f)r   N)r   isclose)r   ths     r+   r   r     s&     A=Rrzz"Q%B((=s   *,zrThe provided estimator makes constant predictions. Therefore, it is impossible to optimize the decision threshold.c              3   @   #    U  H  oR                  5       v   M     g 7fr9   )minr   r   s     r+   r   r   !        
;H'7  ""=   c              3   @   #    U  H  oR                  5       v   M     g 7fr9   )maxr   s     r+   r   r   $  r   r   )num)r   scores)*
isinstancer   r   r&   r   r   rI   r#   r*   r   r'   get_n_splitsr   _get_curve_scorerr   r)   ranger"   r   splitsplitterr0   nextr   r    r   r   r   anyr   r   r   r   r   linspaceasarrayr   argmaxbest_score_best_threshold_r   cv_results_)r:   rL   rD   rM   excsplitsr   r   r   r   r   r   r   min_thresholdmax_thresholddecision_thresholdsobjective_scoresbest_idxr   r   r   s   ```               @@@r+   rJ   TunedThresholdClassifierCV._fit  s5   ( dggt$$TWWq'dggD<M<MB WW zzT! !JKK
;
 B$''Q48BzzU"r'81'< !TUU'e>v>!335 >"nnDOJU<?345F#DNN3DOt~~.JXXaCm&<&<&B&BCFzz56=;R;R;V;V"2"2  $BHHQ$R]5K5K5Q5Q$RS	(I6(I6#7}..22I$  OOE4DE#&T[[) * * +1* $
 	  A=AAAA   
;H
 
  
;H
 
 doox00"$++$//# #%**T__"=3	
 $**,+H528<  1* D
 q " $Gs   M: :
NNNc                     [        U S5        U R                  R                  5       n[        U R                  UU R                  5       US9u  p4[        X0R                  U R                  U5      $ )r   r)   )rw   )	r#   r   _get_pos_labelr   r)   r?   r   r   rQ   )r:   rL   rw   r   r   s        r+   r   "TunedThresholdClassifierCV.predict<  sg     	l+&&557	0OO%%'	

 1))4==)
 	
r=   c                 \   [        U R                  R                  S9R                  U R                  [        5       R                  SSS9S9R                  U R                  [        5       R                  SSS9S9R                  U R                  5       [        5       R                  SSS9S9nU$ )	r   r   r0   r   r   r   )r   r   r   )r   r   )r   re   rg   r   r*   r   r   r   r   s     r+   r   /TunedThresholdClassifierCV.get_metadata_routingV  s     !8!89S..,22%2N   S,22'%2P   S--/,22'%2P   	 r=   c                     [        U R                  U R                  S9n[        R                  " XR                  5       U R                  5      nU$ )z8Get the curve scorer based on the objective metric used.)r   )r   r*   r   r   from_scorerr?   r   )r:   r   r   s      r+   r   ,TunedThresholdClassifierCV._get_curve_scorers  s@    E#//..0$//
 r=   )r   r   r   r   r   r)   r   r   r   r   r   r   )rg   rh   ri   rj   rk   r.   r6   r   setr   callabler   r   r   r   rl   rm   r;   rJ   r   r   r   ro   rp   rq   s   @r+   r   r     s    aF$
!
8
8$ s+-./

  !T&A<Pz"Zc)<

 T"'(&K!$D . $1 1,un
4: r=   r   ):collections.abcr   numbersr   r   numpyr   baser   r   r	   r
   r   
exceptionsr   metricsr   r   metrics._scorerr   r   utilsr   r   utils._param_validationr   r   r   r   utils._responser   utils.metadata_routingr   r   r   r   utils.metaestimatorsr   utils.multiclassr   utils.parallelr   r   utils.validationr    r!   r"   r#   r$   _splitr&   r'   r,   r.   rs   r   r   r    r=   r+   <module>r     s    + "   ( - R R 9  0 - .  51\o/A= \~@6 @FAFH8A!8 Ar=   