Ë
    8Ò^j]  ã            	       óÆ  — d dl Zd dl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 d dlm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mZ d dl m!Z! d dl"m#Z# d dl$m%Z% d dl&m'Z' d dl(m)Z) d dl*m+Z+ d dl,m-Z-m.Z.m/Z/ d„ Z0d„ Z1 ed¬«      d„ «       Z2ejf                  ji                  dddg«       ed¬«      d„ «       «       Z5ejf                  ji                  d e
ddd ¬«       ed ¬ «      g«      d!„ «       Z6ejf                  ji                  d"d#dd$œe7d%fd&d'd$œe7d(fd#d'd$œed)fg«      d*„ «       Z8ejf                  ji                  d+ e«        e'«        ed,¬-«      g«      ejf                  ji                  d.g d/¢«      ejf                  ji                  d0eeg«      d1„ «       «       «       Z9ejf                  ji                  d.g d2¢«      d3„ «       Z:d4„ Z;ejf                  ji                  d.g d2¢«      ejf                  ji                  d5 ee«       eed6¬7«      g«      d8„ «       «       Z<ejf                  ji                  d9dd'g«       ed¬«      d:„ «       «       Z=ejf                  ji                  dddg«       ed¬«      d;„ «       «       Z> ed¬«      d<„ «       Z?d=„ Z@ejf                  ji                  d>dd'g«      d?„ «       ZAd@„ ZBdA„ ZCejf                  ji                  d.g dB¢«      dC„ «       ZDejf                  ji                  dDdEdFg«      ejf                  ji                  dGd dg«      dH„ «       «       ZE ed¬«      dI„ «       ZFejf                  ji                  dJg dK¢«      dL„ «       ZGdM„ ZHy)Né    N)Úconfig_context)Úclone)Úload_breast_cancerÚ	load_irisÚmake_classificationÚmake_multilabel_classification)ÚDummyClassifier)ÚGradientBoostingClassifier)ÚNotFittedError)ÚLogisticRegression)Úbalanced_accuracy_scoreÚf1_scoreÚfbeta_scoreÚ
get_scorerÚmake_scorer)Ú_CurveScorer)ÚFixedThresholdClassifierÚStratifiedShuffleSplitÚTunedThresholdClassifierCV)Ú_fit_and_score_over_thresholds)Úmake_pipeline)ÚStandardScaler)ÚSVC)ÚDecisionTreeClassifier)ÚCheckingClassifier)Ú_convert_containerÚassert_allcloseÚassert_array_equalc            
      ó²  — t        dd¬«      \  } }t        j                  d«      t        j                  dd«      }}t        «       }t	        t
        dddi ¬«      }t        || |i |||i ¬	«      \  }}t        j                  |d
d |dd
 k  «      sJ ‚t        |t        j                  «      sJ ‚t        j                  |dk\  |dk  «      j                  «       sJ ‚y
)zCheck that `_fit_and_score_over_thresholds` returns thresholds in ascending order
    for the different accepted curve scorers.éd   r   ©Ú	n_samplesÚrandom_stateé2   é   Úpredict_probaé
   ©Ú
score_funcÚsignÚresponse_methodÚ
thresholdsÚkwargs©Ú
fit_paramsÚ	train_idxÚval_idxÚcurve_scorerÚscore_paramsNéÿÿÿÿ)r   ÚnpÚaranger   r   r   r   ÚallÚ
isinstanceÚndarrayÚlogical_and©ÚXÚyr0   r1   Ú
classifierr2   Úscoresr,   s           ú†/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/sklearn/model_selection/tests/test_classification_threshold.pyÚ0test_fit_and_score_over_thresholds_curve_scorersrA   ,   sØ   € ô ¨¸1Ô=�D€A€qÜŸ™ 2›¬¯	©	°"°cÓ(:ˆw€IÜ#Ó%€JäÜ*ØØ'ØØô€Lô 8ØØ	Ø	ØØØØ!Øô	Ñ€FˆJô �6‰6�*˜S˜b�/ Z°° ^Ñ3Ô4Ð4Ð4Ü�fœbŸj™jÔ)Ð)Ð)Ü�>‰>˜& A™+ v°¡{Ó3×7Ñ7Ô9Ð9Ñ9ó    c            
      óœ  — t        dd¬«      \  } }dt        j                  dd«      }}t        d¬«      j	                  | |«      }|j                  | |   ||   «      t        j                  d«      k(  sJ ‚t        t        dd	d
i ¬«      }t        || |i |||i ¬«      \  }}t        j                  |dd |dd k  «      sJ ‚t        |ddg«       y)z-Check the behaviour with a prefit classifier.r    r   r!   Nr$   ©r#   g      ð?r%   r&   é   r(   r.   r4   ç      à?)r   r5   r6   r   ÚfitÚscoreÚpytestÚapproxr   r   r   r7   r   r;   s           r@   Ú)test_fit_and_score_over_thresholds_prefitrK   J   sâ   € ä¨¸1Ô=�D€A€qð œrŸy™y¨¨SÓ1ˆw€IÜ'°QÔ7×;Ñ;¸A¸qÓA€Jð ×Ñ˜A˜g™J¨¨'©
Ó3´v·}±}ÀSÓ7IÒIÐIÐIäÜ*ØØ'ØØô€Lô 8ØØ	Ø	ØØØØ!Øô	Ñ€FˆJô �6‰6�*˜S˜b�/ Z°° ^Ñ3Ô4Ð4Ð4Ü�F˜S #˜JÕ'rB   T)Úenable_metadata_routingc                  ó  — t        d¬«      \  } }| dd |dd }} t        j                  | | |dk(     g«      t        j                  |||dk(     g«      }}t        j                  |«      }|ddxxx dz  ccc t        «       }t        j                  |j                  d   «      }t        j                  |j                  d   «      }t        t        dd	d
i ¬«      }t        |||i |||i ¬«      \  }	}
t        j                  | j                  d   «      t        j                  | j                  d   «      }}t        |j                  d¬«      | |d|i|||j                  d¬«      d|i¬«      \  }}t        |
|«       t        |	|«       y)zICheck that we dispatch the sample-weight to fit and score the classifier.T©Ú
return_X_yNr    r   r$   rE   r%   r&   r'   r(   r.   ©Úsample_weightrQ   )r   r5   ÚvstackÚhstackÚ	ones_liker   r6   Úshaper   r   r   Úset_fit_requestÚset_score_requestr   )r<   r=   Ú
X_repeatedÚ
y_repeatedrQ   r>   Útrain_repeated_idxÚval_repeated_idxr2   Úscores_repeatedÚthresholds_repeatedr0   r1   r?   r,   s                  r@   Ú0test_fit_and_score_over_thresholds_sample_weightr^   j   sŒ  € ô  Ô%�D€A€qØˆTˆcˆ7�A�d�s�G€q€Aô  ŸY™Y¨¨1¨Q°!©V©9 ~Ó6¼¿	¹	À1ÀaÈÈQÉÁiÀ.Ó8Q�
€Jä—L‘L “O€MØ�#�2Ó˜!ÑÓä#Ó%€JÜŸ™ :×#3Ñ#3°AÑ#6Ó7ÐÜ—y‘y ×!1Ñ!1°!Ñ!4Ó5ÐÜÜ*ØØ'ØØô€Lô ,JØØØØØ$Ø Ø!Øô	,Ñ(€OÐ(ô Ÿ™ 1§7¡7¨1¡:Ó.´·	±	¸!¿'¹'À!¹*Ó0Eˆw€IÜ7Ø×"Ñ"°Ð"Ó6Ø	Ø	Ø# ]Ð3ØØØ!×3Ñ3À$Ð3ÓGØ% }Ð5ô	Ñ€FˆJô Ð'¨Ô4Ü�O VÕ,rB   Úfit_params_typeÚlistÚarrayc           
      ó>  — t        dd¬«      \  }}t        || «      t        || «      dœ}t        ddgd¬«      }|j                  dd¬«       t	        j
                  d	«      t	        j
                  d	d«      }}t        t        d
ddi ¬«      }t        |||||||i ¬«       y)úECheck that we pass `fit_params` to the classifier when calling `fit`.r    r   r!   ©ÚaÚbre   rf   ©Úexpected_fit_paramsr#   Tr$   r%   r&   r'   r(   r.   N)	r   r   r   rV   r5   r6   r   r   r   )r_   r<   r=   r/   r>   r0   r1   r2   s           r@   Ú-test_fit_and_score_over_thresholds_fit_paramsri   ›   s¬   € ô ¨¸1Ô=�D€A€qä  ?Ó3Ü  ?Ó3ñ€Jô
 $¸¸c¸
ÐQRÔS€JØ×Ñ ¨ÐÔ.ÜŸ™ 2›¬¯	©	°"°cÓ(:ˆw€IäÜ*ØØ'ØØô€Lô #ØØ	Ø	ØØØØ!Øö	rB   Údataé   r%   )Ú	n_classesÚn_clusters_per_classr#   rD   c                 ó¨   — d}t        j                  t        |¬«      5   t        t	        «       «      j
                  | Ž  ddd«       y# 1 sw Y   yxY w)zHCheck that we raise an informative error message for non-binary problem.z(Only binary classification is supported.©ÚmatchN)rI   ÚraisesÚ
ValueErrorr   r   rG   )rj   Úerr_msgs     r@   Ú)test_tuned_threshold_classifier_no_binaryrt   ¼   sJ   € ð 9€GÜ	�‰”z¨Ô	1ñ DØ<Ô"Ô#5Ó#7Ó8×<Ñ<¸dÑC÷D÷ Dñ Dús   ž!AÁAzparams, err_type, err_msgÚprefit)ÚcvÚrefitz'When cv='prefit', refit cannot be True.r'   Fz1When cv has several folds, refit cannot be False.z`estimator` must be fitted.c                 óÄ   — t        dd¬«      \  }}t        j                  ||¬«      5  t        t	        «       fi | ¤Žj                  ||«       ddd«       y# 1 sw Y   yxY w)zhCheck that we raise an informative error message when `cv` and `refit`
    cannot be used together.
    r    r   r!   ro   N)r   rI   rq   r   r   rG   )ÚparamsÚerr_typers   r<   r=   s        r@   Ú1test_tuned_threshold_classifier_conflict_cv_refitr{   Ê   sY   € ô0 ¨¸1Ô=�D€A€qÜ	�‰�x wÔ	/ñ MÜ"Ô#5Ó#7ÑB¸6ÑB×FÑFÀqÈ!ÔL÷M÷ Mñ Mús   ¨%AÁAÚ	estimatoré   )Ún_estimatorsr+   ©r&   Úpredict_log_probaÚdecision_functionÚThresholdClassifierc                 óT  — t        dd¬«      \  }} | |¬«      }t        ||«      t        ||«      k(  sJ ‚|j                  ||«       t        ||«      t        ||«      k(  sJ ‚t        ||«      r; t        ||«      |«      } t        |j                  |«      |«      }t        ||«       yy)zoCheck that `TunedThresholdClassifierCV` exposes the same response methods as the
    underlying estimator.
    r    r   r!   ©r|   N)r   ÚhasattrrG   ÚgetattrÚ
estimator_r   )r‚   r|   r+   r<   r=   ÚmodelÚy_pred_cutoffÚy_pred_underlying_estimators           r@   Ú4test_threshold_classifier_estimator_response_methodsr‹   ç   s«   € ô  ¨¸1Ô=�D€A€qá¨)Ô4€EÜ�5˜/Ó*¬g°iÀÓ.QÒQÐQÐQà	‡I�Iˆa�„OÜ�5˜/Ó*¬g°iÀÓ.QÒQÐQÐQäˆu�oÔ&Ø7œ  Ó7¸Ó:ˆØ&P¤g¨e×.>Ñ.>ÀÓ&PÐQRÓ&SÐ#ä˜Ð'BÕCð	 'rB   )Úautor�   r&   c                 óÂ  — t        d¬«      \  }}|dd…dd…f   }t        j                  |dk(  «      }|d|j                  dz   }t        j                  |dk(  «      }t        j                  ||   ||   g«      }t        j
                  ||   ||   g«      }t        t        «       t        «       «      j                  ||«      }d}t        |d	| |d¬
«      }t        ||j                  ||«      j                  |«      «      }t        ||j                  |«      «      }	||	kD  sJ ‚|j                  d   j                  |fk(  sJ ‚|j                  d   j                  |fk(  sJ ‚y)zSCheck that `TunedThresholdClassifierCV` is optimizing a given objective
    metric.TrN   Né   r%   r$   r   r    Úbalanced_accuracy)r|   Úscoringr+   r,   Ústore_cv_resultsr,   r?   )r   r5   ÚflatnonzeroÚsizerR   rS   r   r   r   rG   r   r   ÚpredictÚcv_results_rU   )
r+   r<   r=   Úindices_posÚindices_negÚlrr,   rˆ   Úscore_optimizedÚscore_baselines
             r@   Ú8test_tuned_threshold_classifier_without_constraint_valuer›     s\  € ô ¨Ô.�D€A€qà	Š!ˆRˆaˆRˆ%‰€Aô —.‘.  a¡Ó(€KØÐ6 × 0Ñ 0°BÑ 6Ð7€KÜ—.‘.  a¡Ó(€Kä
�	‰	�1�[‘> 1 [¡>Ð2Ó3€AÜ
�	‰	�1�[‘> 1 [¡>Ð2Ó3€Aä	”~Ó'Ô);Ó)=Ó	>×	BÑ	BÀ1ÀaÓ	H€BØ€JÜ&ØØ#Ø'ØØô€Eô .¨a°·±¸1¸a³×1HÑ1HÈÓ1KÓL€OÜ,¨Q°·
±
¸1³Ó>€NØ˜^Ò+Ð+Ð+Ø×Ñ˜\Ñ*×0Ñ0°Z°MÒAÐAÐAØ×Ñ˜XÑ&×,Ñ,°°Ò=Ð=Ñ=rB   c                  ó6  — t        d¬«      \  } }t        t        «       t        «       «      j	                  | |«      }t        |t        t        d¬«      ¬«      j	                  | |«      }t        |t        t        d¬«      ¬«      j	                  | |«      }t        |t        t        «      ¬«      j	                  | |«      }|j                  t        j                  |j                  «      k(  sJ ‚|j                  t        j                  |j                  «      k7  sJ ‚y)z¬Check that we can pass a metric with a parameter in addition check that
    `f_beta` with `beta=1` is equivalent to `f1` and different from `f_beta` with
    `beta=2`.
    TrN   r%   )Úbeta)r|   r�   rE   N)r   r   r   r   rG   r   r   r   r   Úbest_threshold_rI   rJ   )r<   r=   r˜   Úmodel_fbeta_1Úmodel_fbeta_2Úmodel_f1s         r@   Ú5test_tuned_threshold_classifier_metric_with_parameterr¢   (  sè   € ô
 ¨Ô.�D€A€qÜ	”~Ó'Ô);Ó)=Ó	>×	BÑ	BÀ1ÀaÓ	H€BÜ.Øœk¬+¸AÔ>ôç	�cˆ!ˆQƒið ô /Øœk¬+¸AÔ>ôç	�cˆ!ˆQƒið ô *Øœk¬(Ó3ôç	�cˆ!ˆQƒið ð ×(Ñ(¬F¯M©M¸(×:RÑ:RÓ,SÒSÐSÐSØ×(Ñ(¬F¯M©M¸-×:WÑ:WÓ,XÒXÐXÑXrB   ÚmetricÚcancer)Ú	pos_labelc                 ó°  — t        d¬«      \  }}t        j                  ddgt        ¬«      }||   }t	        t        t        «       t        «       «      || d¬«      j                  ||«      }t        |j                  t        j                  |«      «       |j                  |«      }t        t        j                  |«      t        j                  |«      «       y)	z�Check that targets represented by str are properly managed.
    Also, check with several metrics to be sure that `pos_label` is properly
    dispatched.
    TrN   r¤   Úhealthy)Údtyper    )r|   r�   r+   r,   N)r   r5   ra   Úobjectr   r   r   r   rG   r   Úclasses_Úsortr”   Úunique)r+   r£   r<   r=   Úclassesrˆ   Úy_preds          r@   Ú3test_tuned_threshold_classifier_with_string_targetsr¯   =  s©   € ô ¨Ô.�D€A€qô �h‰h˜ )Ð,´FÔ;€GØ�‰
€AÜ&Ü¤Ó 0Ô2DÓ2FÓGØØ'Øô	÷
 
�cˆ!ˆQƒið 
ô �u—~‘~¤r§w¡w¨wÓ'7Ô8Ø�]‰]˜1Ó€FÜ”r—y‘y Ó(¬"¯'©'°'Ó*:Õ;rB   Úwith_sample_weightc                 ó°  — t         j                  j                  |«      }t        dd¬«      \  }}| r6|j	                  |j
                  d   «      }t        j                  ||¬«      }nd}t        «       j                  d¬«      }t        |dt        d«      j                  d¬«      ¬	«      j                  |||¬«      }|j                  |usJ ‚|j                  |||¬«       t        |j                  j                  |j                  «       t        |j                  j                   |j                   «       t        «       j                  d¬«      }|j                  |||¬«       |j                  j#                  «       }t        |d
dt        d«      j                  d¬«      ¬«      j                  |||¬«      }|j                  |u sJ ‚t        |j                  j                  |«       t        «       j                  d¬«      }t        j$                  d«      t        j$                  dd«      fg}	t        ||	dt        d«      j                  d¬«      ¬«      j                  |||¬«      }|j                  |usJ ‚| r||	d   d      }
nd}
|j                  ||	d   d      ||	d   d      |
¬«       t        |j                  j                  |j                  «       y)z-Check the behaviour of the `refit` parameter.r    r   r!   )ÚoutNTrP   r�   )rw   r�   ru   F)rv   rw   r�   r$   )r5   ÚrandomÚRandomStater   ÚrandnrU   Úabsr   rV   r   r   rW   rG   r‡   r   Úcoef_Ú
intercept_Úcopyr6   )r°   Úglobal_random_seedÚrngr<   r=   rQ   r|   rˆ   Úcoefrv   Úsw_trains              r@   Ú%test_tuned_threshold_classifier_refitr¾   ]  s¢  € ô �)‰)×
Ñ
Ð 2Ó
3€CÜ¨¸1Ô=�D€A€qÙØŸ	™	 !§'¡'¨!¡*Ó-ˆÜŸ™˜}°-Ô@‰àˆô #Ó$×4Ñ4À4Ð4ÓH€IÜ&ØØÜÐ.Ó/×AÑAÐPTÐAÓUô÷ 
�cˆ!ˆQ˜m€cÓ,ð	 
ð ×Ñ 9Ñ,Ð,Ð,Ø‡M�M�!�Q m€MÔ4Ü�E×$Ñ$×*Ñ*¨I¯O©OÔ<Ü�E×$Ñ$×/Ñ/°×1EÑ1EÔFô #Ó$×4Ñ4À4Ð4ÓH€IØ‡M�M�!�Q m€MÔ4Ø�?‰?×ÑÓ!€DÜ&ØØØÜÐ.Ó/×AÑAÐPTÐAÓUô	÷
 
�cˆ!ˆQ˜m€cÓ,ð 
ð ×Ñ˜yÑ(Ð(Ð(Ü�E×$Ñ$×*Ñ*¨DÔ1ô #Ó$×4Ñ4À4Ð4ÓH€Iä	�‰�2‹œŸ	™	 " cÓ*Ð+ð
€Bô 'ØØØÜÐ.Ó/×AÑAÐPTÐAÓUô	÷
 
�cˆ!ˆQ˜m€cÓ,ð 
ð ×Ñ 9Ñ,Ð,Ð,ÙØ   A¡ q¡Ñ*‰àˆØ‡M�M�!�B�q‘E˜!‘H‘+˜q  A¡ q¡™{¸(€MÔCÜ�E×$Ñ$×*Ñ*¨I¯O©OÕ<rB   c                 óØ   — t        dd¬«      \  }}t        || «      t        || «      dœ}t        ddgd¬«      }|j                  dd¬«       t	        |«      } |j
                  ||fi |¤Ž y	)
rc   r    r   r!   rd   re   rf   rg   TN)r   r   r   rV   r   rG   )r_   r<   r=   r/   r>   rˆ   s         r@   Ú*test_tuned_threshold_classifier_fit_paramsrÀ   ™  st   € ô ¨¸1Ô=�D€A€qä  ?Ó3Ü  ?Ó3ñ€Jô
 $¸¸c¸
ÐQRÔS€JØ×Ñ ¨ÐÔ.Ü& zÓ2€EØ€E‡I�Iˆa�Ñ!�jÓ!rB   c                  óæ  — t        d¬«      \  } }t        «       j                  | «      } t        j                  | dd | dd f«      } t        j
                  |dd |dd f«      }t        j                  |«      }d|ddd…<   t        «       j                  d¬	«      j                  d¬	«      }t        |d¬
«      }t        |dt        d«      j                  d¬	«      ¬«      }|j                  | ||¬	«       |j                  | ddd…   |ddd…   «       t        |j                  j                  |j                  j                  «       |j!                  | «      }|j!                  | «      }t        ||«       y)z|Check that passing removing some sample from the dataset `X` is
    equivalent to passing a `sample_weight` with a factor 0.TrN   Né(   r$   éZ   r%   rE   rP   )rv   r�   )rv   r�   )r   r   Úfit_transformr5   rR   rS   Ú
zeros_liker   rV   rW   r   r   rG   r   r‡   r·   r&   )r<   r=   rQ   r|   Úmodel_without_weightsÚmodel_with_weightsÚy_pred_with_weightsÚy_pred_without_weightss           r@   ÚCtest_tuned_threshold_classifier_cv_zeros_sample_weights_equivalencerÊ   ©  sm  € ô  Ô%�D€A€qäÓ×&Ñ& qÓ)€Aô 	�	‰	�1�S�b�6˜1˜R ˜8Ð$Ó%€AÜ
�	‰	�1�S�b�6˜1˜R ˜8Ð$Ó%€AÜ—M‘M !Ó$€MØ€M‘#�A�#Ñô 	Óß	‰ tˆÓ	,ß	Ñ	¨Ð	Ó	.ð ô
 7°yÀQÔGÐÜ3ØØÜÐ.Ó/×AÑAÐPTÐAÓUôÐð ×Ñ˜1˜a¨}ÐÔ=Ø×Ñ˜a¡ ! ™f a©¨!¨¡fÔ-äØ×%Ñ%×+Ñ+Ð-B×-MÑ-M×-SÑ-Sôð -×:Ñ:¸1Ó=ÐØ2×@Ñ@ÀÓCÐÜÐ'Ð)?Õ@rB   c                  óÔ   — t        d¬«      \  } }t        «       }t        j                  ddd«      }t	        ||dd¬«      j                  | |«      }t        |j                  d   |«       y	)
zeCheck that we can pass an array to `thresholds` and it is used as candidate
    threshold internally.r   rD   r%   é   r&   T)r,   r+   r‘   r,   N)r   r   r5   Úlinspacer   rG   r   r•   )r<   r=   r|   r,   Útuned_models        r@   Ú0test_tuned_threshold_classifier_thresholds_arrayrÏ   Ï  si   € ô ¨AÔ.�D€A€qÜ"Ó$€IÜ—‘˜Q  2Ó&€JÜ,ØØØ'Øô	÷
 
�cˆ!ˆQƒið ô �K×+Ñ+¨LÑ9¸:ÕFrB   r‘   c                 ó®   — t        d¬«      \  }}t        «       }t        || ¬«      j                  ||«      }| rt	        |d«      sJ ‚yt	        |d«      rJ ‚y)zCCheck that if `cv_results_` exists depending on `store_cv_results`.r   rD   )r‘   r•   N)r   r   r   rG   r…   )r‘   r<   r=   r|   rÎ   s        r@   Ú0test_tuned_threshold_classifier_store_cv_resultsrÑ   Þ  s`   € ô ¨AÔ.�D€A€qÜ"Ó$€IÜ,ØÐ$4ôç	�cˆ!ˆQƒið ñ Ü�{ MÔ2Ð2Ñ2ä˜;¨Ô6Ð6Ð6Ð6rB   c                  óX  — t        d¬«      \  } }d}t        «       }t        ||dd¬«      j                  | |«      }|j                  | |«       t	        d|d¬«      }t        |j                  | |«      «      \  }}t        |«      j                  | |   ||   «      }t        |j                  j                  |j                  «       |j                  d¬	«      j                  | |«       t        |«      j                  | |«      }t        |j                  j                  |j                  «       y
)z0Check the behaviour when `cv` is set to a float.r   rD   g333333Ó?F)rv   rw   r#   r%   )Ún_splitsÚ	test_sizer#   T)rw   N)r   r   r   rG   r   ÚnextÚsplitr   r   r‡   r·   Ú
set_params)	r<   r=   rÔ   r|   rÎ   rv   r0   r1   Úcloned_estimators	            r@   Ú(test_tuned_threshold_classifier_cv_floatrÙ   ì  s	  € ä¨AÔ.�D€A€qð
 €IÜ"Ó$€IÜ,Ø�i u¸1ôç	�cˆ!ˆQƒið ð ‡O�O�A�qÔä	¨°iÈaÔ	P€BÜ˜bŸh™h q¨!›nÓ-Ñ€IˆwÜ˜YÓ'×+Ñ+¨A¨i©L¸!¸I¹,ÓGÐä�K×*Ñ*×0Ñ0Ð2B×2HÑ2HÔIð ×Ñ ÐÓ&×*Ñ*¨1¨aÔ0Ü˜YÓ'×+Ñ+¨A¨qÓ1Ðä�K×*Ñ*×0Ñ0Ð2B×2HÑ2HÕIrB   c                  óÞ   — t        d¬«      \  } }t        dd¬«      }t        |d¬«      }d}t        j                  t
        |¬	«      5  |j                  | |«       d
d
d
«       y
# 1 sw Y   y
xY w)z�Check that we raise a ValueError if the underlying classifier returns constant
    probabilities such that we cannot find any threshold.
    r   rD   Úconstantr%   )ÚstrategyrÛ   r&   )r+   z1The provided estimator makes constant predictionsro   N)r   r	   r   rI   rq   rr   rG   )r<   r=   r|   rÎ   rs   s        r@   Ú8test_tuned_threshold_classifier_error_constant_predictorrÝ     s`   € ô ¨AÔ.�D€A€qÜ¨¸aÔ@€IÜ,¨YÈÔX€KØA€GÜ	�‰”z¨Ô	1ñ Ø�‰˜˜1Ô÷÷ ñ ús   ÁA#Á#A,)rŒ   r&   r�   c                 óp  — t        d¬«      \  }}t        «       j                  ||«      }t        t	        |«      | ¬«      }|j                  ||«       | dv r|j                  |«      dd…df   }d}n|j                  |«      }d}||k\  j                  t        «      }t        |j                  |«      |«       y)	z`Check that `FixedThresholdClassifier` has the same behaviour as the vanilla
    classifier.
    r   rD   )r|   r+   )rŒ   r&   Nr%   rF   g        )r   r   rG   r   r   r&   r�   ÚastypeÚintr   r”   )r+   r<   r=   r>   Úclassifier_default_thresholdÚy_scoreÚ	thresholdÚ	y_pred_lrs           r@   Ú3test_fixed_threshold_classifier_equivalence_defaultrå     s·   € ô ¨AÔ.�D€A€qÜ#Ó%×)Ñ)¨!¨QÓ/€JÜ#;Ü˜
Ó#°_ô$Ð ð !×$Ñ$ Q¨Ô*ð Ð3Ñ3Ø.×<Ñ<¸QÓ?ÂÀ1ÀÑEˆØ‰	à.×@Ñ@ÀÓCˆØˆ	à˜IÑ%×-Ñ-¬cÓ2€IÜÐ0×8Ñ8¸Ó;¸YÕGrB   zresponse_method, threshold)r&   gffffffæ?)r�   g       @r¥   c           	      ó  — t        dd¬«      \  }}t        «       j                  ||«      }t        t	        |«      || |¬«      j                  ||«      }t        |j                  j                  |j                  «       | dk(  r|j                  |«      dd…|f   }n|j                  |«      }|dk(  r|n| }|dk(  rt        j                  ddg«      nt        j                  ddg«      }|||k\  j                  t        «         }	t        |j                  |«      |	«       dD ]d  }
t         t        ||
«      |«       t        ||
«      |«      «       t         t        |j                  |
«      |«       t        ||
«      |«      «       Œf y)	z‚Check that applying `predict` lead to the same prediction as applying the
    threshold to the output of the response method.
    r$   r   r!   )r|   rã   r+   r¥   r&   Nr%   r   )r   r   rG   r   r   r   r‡   r·   r&   r�   r5   ra   rß   rà   r”   r†   )r+   rã   r¥   r<   r=   Úlogistic_regressionrˆ   râ   Úmap_to_labelrä   Úmethods              r@   Útest_fixed_threshold_classifierrê   .  sz  € ô ¨¸!Ô<�D€A€qÜ,Ó.×2Ñ2°1°aÓ8ÐÜ$ÜÐ+Ó,ØØ'Øô	÷
 
�cˆ!ˆQƒið 
ô �E×$Ñ$×*Ñ*Ð,?×,EÑ,EÔFð ˜/Ò)Ø×%Ñ% aÓ(ª¨I¨Ñ6‰à×)Ñ)¨!Ó,ˆØ&¨!š^‘'°'°ˆð (1°A¢~”2—8‘8˜Q ˜FÔ#¼2¿8¹8ÀQÈÀFÓ;K€LØ˜g¨Ñ2×:Ñ:¼3Ó?Ñ@€IÜ�E—M‘M !Ó$ iÔ0àMò 
ˆÜØ"ŒG�E˜6Ó" 1Ó%Ð'K¤wÐ/BÀFÓ'KÈAÓ'Nô	
ô 	Ø-ŒG�E×$Ñ$ fÓ-¨aÓ0Ø0ŒGÐ'¨Ó0°Ó3õ	
ñ	
rB   c                  ó^  — t        d¬«      \  } }t        j                  |«      }d|ddd…<   t        «       j	                  d¬«      }|j                  | ||¬«       t        t        |«      ¬«      }|j                  | ||¬«       t        |j                  j                  |j                  «       y)z2Check that everything works with metadata routing.r   rD   rE   NTrP   r„   )r   r5   rT   r   rV   rG   r   r   r   r‡   r·   )r<   r=   rQ   r>   rá   s        r@   Ú0test_fixed_threshold_classifier_metadata_routingrì   X  s—   € ô ¨AÔ.�D€A€qÜ—L‘L “O€MØ€M‘#�A�#ÑÜ#Ó%×5Ñ5ÀDÐ5ÓI€JØ‡N�N�1�a }€NÔ5Ü#;ÄeÈJÓFWÔ#XÐ Ø ×$Ñ$ Q¨¸Ð$ÔGÜÐ0×;Ñ;×AÑAÀ:×CSÑCSÕTrB   ré   )r&   r�   r”   r€   c                 ó’   — t        d¬«      \  }}t        «       j                  ||«      }t        |¬«      } t	        || «      |«       y)zMCheck that if the underlying estimator is already fitted, no fit is required.r   rD   r„   N)r   r   rG   r   r†   )ré   r<   r=   r>   Úfixed_threshold_classifiers        r@   Ú0test_fixed_threshold_classifier_fitted_estimatorrï   e  sD   € ô
 ¨AÔ.�D€A€qÜ#Ó%×)Ñ)¨!¨QÓ/€JÜ!9ÀJÔ!OÐà/„GÐ&¨Ó/°Õ2rB   c                  óJ  — t        d¬«      \  } }t        j                  t        d¬«      5  t	        t        «       ¬«      j                   ddd«       t        «       j                  | |«      }t	        |¬«      }t        |j                  |j                  «       y# 1 sw Y   ŒPxY w)z2Check that the classes_ attribute is properly set.r   rD   z+The underlying estimator is not fitted yet.ro   r„   N)	r   rI   rq   ÚAttributeErrorr   r   rª   rG   r   )r<   r=   r>   rî   s       r@   Ú(test_fixed_threshold_classifier_classes_rò   q  sˆ   € ä¨AÔ.�D€A€qÜ	�‰ÜÐKô
ñ Jô 	!Ô+=Ó+?Ô@×IÒI÷Jô
 $Ó%×)Ñ)¨!¨QÓ/€JÜ!9ÀJÔ!OÐÜÐ1×:Ñ:¸J×<OÑ<OÕP÷Jð Jús   «BÂB")IÚnumpyr5   rI   Úsklearnr   Úsklearn.baser   Úsklearn.datasetsr   r   r   r   Úsklearn.dummyr	   Úsklearn.ensembler
   Úsklearn.exceptionsr   Úsklearn.linear_modelr   Úsklearn.metricsr   r   r   r   r   Úsklearn.metrics._scorerr   Úsklearn.model_selectionr   r   r   Ú1sklearn.model_selection._classification_thresholdr   Úsklearn.pipeliner   Úsklearn.preprocessingr   Úsklearn.svmr   Úsklearn.treer   Úsklearn.utils._mockingr   Úsklearn.utils._testingr   r   r   rA   rK   r^   ÚmarkÚparametrizeri   rt   rr   r{   r‹   r›   r¢   r¯   r¾   rÀ   rÊ   rÏ   rÑ   rÙ   rÝ   rå   rê   rì   rï   rò   © rB   r@   ú<module>r     s  ðÛ Û å "Ý ÷ó õ *Ý 7Ý -Ý 3÷õ õ 1÷ñ õ
õ +Ý 0Ý Ý /Ý 5÷ñ ò:ò<(ñ@ ¨Ô-ñ--ó .ð--ð` ‡�×ÑÐ*¨V°WÐ,=Ó>Ù¨Ô-ñó .ó ?ðð> ‡�×ÑØ
á a¸aÈaÔPÙ&°AÔ6ðóñDóðDð ‡�×ÑØð  dÑ+ØØ5ð	
ð  Ñ&ØØ?ð	
ð  eÑ,ØØ)ð	
ðóñ(Mó)ð(Mð ‡�×ÑØÙÓ™3›5Ñ"<È!Ô"LÐMóð ‡�×ÑØÒRóð ‡�×ÑØÐ4Ð6PÐQóñDóóó	ðDð* ‡�×ÑØÒEóñ>óð>ò>Yð* ‡�×ÑØÒEóð ‡�×ÑØáÐ+Ó,Ù�H¨Ô1ðóñ<óóð<ð, ‡�×ÑÐ-°°e¨}Ó=Ù¨Ô-ñ7=ó .ó >ð7=ðt ‡�×ÑÐ*¨V°WÐ,=Ó>Ù¨Ô-ñ"ó .ó ?ð"ñ ¨Ô-ñ"Aó .ð"AòJGð ‡�×ÑÐ+¨d°E¨]Ó;ñ
7ó <ð
7òJò8	ð ‡�×ÑØÒEóñHóðHð. ‡�×ÑØ Ð#9Ð;UÐ"Vóð ‡�×Ñ˜ q¨! fÓ-ñ#
ó .óð#
ñL ¨Ô-ñ	Uó .ð	Uð ‡�×ÑØÒTóñ3óð3ó
QrB   