o
    `^hF                    @   s
  d dl Z d dlZd dlZd dlZd dlmZ d dlmZ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mZmZmZmZmZmZmZmZ d dlmZ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/m0Z0 d dl1m2Z2m3Z3m4Z4 eeegZ5d?ddZ6dd Z7dd Z8dd Z9dd Z:ej;<dddgdd Z=dd  Z>d!d" Z?d#d$ Z@d%d& ZAd'd( ZBd)d* ZCd+d, ZDd-d. ZEd/d0 ZFd1d2 ZGd3d4 ZHej;<d5eIg d6g d7feIg d6dfg d8g d9fg d8dfgd:d; ZJej;<d5eIg d<g d7feIg d=g d>fgd?d@ ZKej;<d5eIg dAdfg dBdfg dAg d7fg dBg d9fgdCdD ZLej;<dEg dFdGdH ZMdIdJ ZNej;<dKdLeIg dAg dMfdLeIg dBg dNfdOeIg d<dfdPeIg dBg dQfdReIg dAd dSgfdReIg dBdTdUgfdVeIg dAg dWfdVeIg dBg dXfdYeIg dZg d9fdYeIg dXg d9fdYeIg dWg d7fgej;<d[d\d]gd^d_ ZOej;<d`dadbd\dcfdddbd]dcfded\g dffdgd\dhdifdji fgdkdl ZPdmdn ZQej;<doe5dpdq ZRej;<doe5drds ZSej;Tdtej;<doeegej;<dudvdwgdxdy ZUej;<doe5dzd{ ZVej;<dddgd|d} ZWd~d ZXej;<dddgdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_ej;<dg dg dd gd gfg dg dd gd gfg dg dd gd gfg dg dd gd gfg dg ddhgd gfg dg ddhgd gfg dg ddhgd gfg dg ddhgd gfg dg ddgd gfg dg dd gd gfg dg dd gd gfg dg dd gd gfg dg dg dg dfg dg dg dg dfg dg dg dg dfg dg dg dg dfg dg dg dg dfg dg dg dg dfg dg dg dg dfg dg dg dg dfgdd Z`ej;<ddSd gdhdhgdSgd gfd dSgdhdhgdSgd gfg dg ddhgd gfg dg ddhgd gfg dg dd gd gfg dg ddSgd gfg dg ddSgd gfg dg ddSgd gfgdd Zadd Zbej;<dg ddd Zcej;<dg dg dg dg dg dgdd Zdej;<dd dSgg ddfg dd dhgdfg dg ddfg dg ddfg dg ddfgdd Zedd Zfdd Zgdd Zhdd Zidd ZjddĄ ZkddƄ Zl	 d@ddʄZmej;<degekejehfej;<deelfdd΄ ZnddЄ Zoej;<ddҡej;<ddԡej;<depdSddׄ Zqddل Zrddۄ Zsdd݄ Ztej;<dg dg dfg dg dgfg dgg dfgdd Zudd Zvej;<de0dd Zwdd Zxdd Zydd Zzdd Z{dd Z|dd Z}dd Z~dd Zej;<dddgdd Zdd Zdd Zdd Zdd  Zej;<dg dWdSdfg dWddhfg dWddfgdd Zej;<deIg d	dSdSfeIg d
dSdhfeIg d
ddSfeIg ddSdSfeIg ddSdhfeIg dddSfgdd Zej;<deIg ddg dWfeIg ddhg dWfeIg ddhg dWfeIg ddg dfgej;<dddgdd Zdd Zej;<dg dWdSdfg dWddhfg dWddSfgdd Zej;<dg dWdfg dWdfgdd Zej;<d g d!g d"g d#g d$g d%gdd&fg dWg d"g d#g d$g d%gdd'fg d(g d"g d#g d$g d%gg dBd)fg d(g d"g d#g d$g d%gg dQd*fg d+g d"g d#g d$g d%gg dWd,fg d+g d"g d#g d$g d%gg d-d.fd dSgg d/g d0gdd1fgd2d3 Zej;<de0d4d5 Zej;<d6eeeegej;<d7g d8d9d: Zd;d< Zd=d> ZdS (A      N)stats)datasetssvm)make_multilabel_classification)UndefinedMetricWarning)LogisticRegression)accuracy_scoreaucaverage_precision_scorecoverage_error	dcg_score	det_curve%label_ranking_average_precision_scorelabel_ranking_loss
ndcg_scoreprecision_recall_curveroc_auc_score	roc_curvetop_k_accuracy_score)_dcg_sample_scores_ndcg_sample_scores)train_test_split)label_binarize)_sparse_random_matrix)_convert_containerassert_allcloseassert_almost_equalassert_array_almost_equalassert_array_equal)softmax)CSR_CONTAINERS)check_arraycheck_consistent_lengthcheck_random_stateFc                 C   s  | du rt  } | j}| j}|r||dk  ||dk  }}|j\}}t|}td}|| || || }}t	|d }tj
d}tj|||d| f }tjdddd}	|	|d| |d| ||d }
|ry|
ddd	f }
|	||d }||d }|||
fS )
zMake some classification predictions on a toy dataset using a SVC

    If binary is True restrict to a binary classification problem instead of a
    multiclass classification problem
    N   %   r      linearT)kernelprobabilityrandom_state   )r   	load_irisdatatargetshapenparanger#   shuffleintrandomRandomStatec_randnr   SVCfitpredict_probapredict)datasetbinaryXy	n_samples
n_featuresprnghalfclfy_scorey_predy_true rI   `/home/air/shanriGPT/back/venv/lib/python3.10/site-packages/sklearn/metrics/tests/test_ranking.pymake_prediction8   s*   


*
rK   c                 C   sd   t | d }|| |k }|| |k }|dd|dd }t |dk}|tt|t|  S )zKAlternative implementation to check for correctness of
    `roc_auc_score`.r+   r   )r0   uniquereshapesumfloatlen)rH   rF   	pos_labelposnegdiff_matrix	n_correctrI   rI   rJ   _auch   s   rW   c           	      C   s   t | d }t | |k}t |ddd }|| }| | } d}tt|D ](}| | |krPd}td|d D ]}| | |krE|d7 }q9||d  }||7 }q(|| S )a>  Alternative implementation to check for correctness of
    `average_precision_score`.

    Note that this implementation fails on some edge cases.
    For example, for constant predictions e.g. [0.5, 0.5, 0.5],
    y_true = [1, 0, 0] returns an average precision of 0.33...
    but y_true = [0, 0, 1] returns 1.0.
    r+   NrL   r         ?)r0   rM   rO   argsortrangerQ   )	rH   rF   rR   n_posorderscoreiprecjrI   rI   rJ   _average_precisionw   s"   	ra   c                 C   sd   t | |\}}}tt|}tt|}d}tdt|D ]}||| || ||d    7 }q|S )ao  A second alternative implementation of average precision that closely
    follows the Wikipedia article's definition (see References). This should
    give identical results as `average_precision_score` for all inputs.

    References
    ----------
    .. [1] `Wikipedia entry for the Average precision
       <https://en.wikipedia.org/wiki/Average_precision>`_
    r   r+   )r   listreversedrZ   rQ   )rH   rF   	precisionrecall	thresholdaverage_precisionr^   rI   rI   rJ   _average_precision_slow   s   
"rh   c                 C   s^   dd }|| ||\}}t ||}d}|}d||  ||  }	|| }
dd||	 |
|	    S )zcAlternative implementation to check for correctness of `roc_auc_score`
    with `max_fpr` set.
    c                 S   s   t | |\}}}|||k }t||}|||k }t||k}|d }	||	 || g}
||	 || g}t|t||
|}||fS )Nr+   )r   r0   appendargmaxinterp)rH   	y_predictmax_fprfprtpr_new_fprnew_tpridx_outidx_inx_interpy_interprI   rI   rJ   _partial_roc   s   z,_partial_roc_auc_score.<locals>._partial_rocr         ?r+   )r	   )rH   rl   rm   rw   rq   rr   partial_aucfpr1fpr2min_areamax_arearI   rI   rJ   _partial_roc_auc_score   s   
r~   dropTc           	      C   sz   t dd\}}}t||}t||| d\}}}t||}t||dd t|t|| |j|jks3J |j|jks;J d S )NTr=   drop_intermediater$   decimal)rK   rW   r   r	   r   r   r   r/   )	r   rH   rp   rF   expected_aucrn   ro   
thresholdsroc_aucrI   rI   rJ   test_roc_curve   s   

r   c                  C   s   t jd} t dgd dgd  }| jddd}t||dd\}}}|d dks,J |d	 dks4J |j|jks<J |j|jksDJ d S )
Nr   2   r+      d   sizeTr   rL   )r0   r4   r5   arrayrandintr   r/   )rC   rH   rG   rn   ro   thrrI   rI   rJ   test_roc_curve_end_points   s   r   c            
      C   s   t dd\} }}t| |\}}}g }|D ]}t||k| @ }t| }	|d| |	  qt||dd |j|jks=J |j|jksEJ d S )NTr   rX   r$   r   )rK   r   r0   rO   ri   r   r/   )
rH   rp   rF   rn   ro   r   tpr_correctttprB   rI   rI   rJ   test_roc_returns_consistency   s   
r   c                  C   sJ   t dd\} }}tt t| | W d    d S 1 sw   Y  d S )NFr   )rK   pytestraises
ValueErrorr   )rH   rp   rF   rI   rI   rJ   test_roc_curve_multi   s   "r   c                  C   s`   t dd\} }}t| |d \}}}t||}t|ddd |j|jks&J |j|jks.J d S )NTr   rx   ?r$   r   )rK   r   r	   r   r/   )rH   rp   rF   rn   ro   r   r   rI   rI   rJ   test_roc_curve_confidence   s   
r   c                  C   s  t dd\} }}t| j}t| |\}}}t||}t|ddd |j|jks*J |j|jks2J t| j}t| |\}}}t||}t|ddd |j|jksTJ |j|jks\J t| |\}}}t||}t|ddd |j|jksxJ |j|jksJ d S )NTr   rx   r$   r   g(\?)rK   r0   onesr/   r   r	   r   zeros)rH   predrF   trivial_predrn   ro   r   r   rI   rI   rJ   test_roc_curve_hard  s$   


r   c                  C   s  g d} g d}d}t jt|d t| |\}}}W d    n1 s$w   Y  t|tt|tj |j	|j	ks=J |j	|j	ksEJ d}t jt|d tdd | D |\}}}W d    n1 sfw   Y  t|tt|tj |j	|j	ksJ |j	|j	ksJ d S )N)
r+   r+   r+   r+   r+   r+   r+   r+   r+   r+   )
r   r+   r   r+   r   r+   r   r+   r   r+   INo negative samples in y_true, false positive value should be meaninglessmatchHNo positive samples in y_true, true positive value should be meaninglessc                 S   s   g | ]}d | qS )r+   rI   ).0xrI   rI   rJ   
<listcomp>5  s    z,test_roc_curve_one_label.<locals>.<listcomp>)
r   warnsr   r   r   r0   fullrQ   nanr/   )rH   rG   expected_messagern   ro   r   rI   rI   rJ   test_roc_curve_one_label!  s$   r   c                  C   s  ddg} ddg}t | |\}}}t| |}t|g d t|g d t|d ddg} ddg}t | |\}}}t| |}t|g d t|g d t|d ddg} ddg}t | |\}}}t| |}t|ddg t|ddg t|d ddg} ddg}t | |\}}}t| |}t|g d t|g d t|d ddg} ddg}t | |\}}}t| |}t|ddg t|ddg t|d ddg} dd	g}d
}tjt|d t | |\}}}W d    n1 sw   Y  t|g d t|tjtjtjg d}tjt|d t| |}W d    n	1 sw   Y  t	
|s*J ddg} dd	g}d}tjt|d t | |\}}}W d    n	1 sOw   Y  t|tjtjtjg t|g d d}tjt|d t| |}W d    n	1 sw   Y  t	
|sJ tddgddgg} tddgddgg}tjt|d t| |dd W d    n	1 sw   Y  tjt|d t| |dd W d    n	1 sw   Y  tt| |ddd tt| |ddd tddgddgg} tddgddgg}tjt|d t| |dd W d    n	1 s%w   Y  tjt|d t| |dd W d    n	1 sDw   Y  tt| |ddd tt| |ddd tddgddgg} tddgddgg}tt| |ddd tt| |ddd tt| |ddd tt| |ddd tddgddgg} tddgddgg}tt| |ddd tt| |ddd tt| |ddd tt| |ddd d S )Nr   r+   r   r   r+   r   r+   r+   rX           rx         ?      ?r   r   r   rx   rX   OOnly one class is present in y_true. ROC AUC score is not defined in that case.r   macroaverageweightedsamplesmicro)r   r   r   r   r   r   r   r0   r   mathisnanr   )rH   rF   ro   rn   rp   r   r   r	   rI   rI   rJ   test_roc_curve_toydata<  s   









r   c                  C   sx   g d} g d}t | |dd\}}}t|tjdddg g d} g d	}t | |dd\}}}t|tjdd
dddg d S )Nr   r   r   r   r+   r+   r   皙?rx   333333?ffffff?rX   Tr   rX   r   r   r   r   r   r   r   r   r   r+   r+   r+   r+   r+   r+   r   皙?r   r   r   皙?r   r   r   r   r   r   rX   r   r   )r   r   r0   inf)rH   rF   ro   rn   r   rI   rI   rJ    test_roc_curve_drop_intermediate  s   r   c                  C   sh   g d} g d}t dd}t| ||d\}}}t |dk  dks%J t |dk  dks2J d S )Nr   r   r+   r+   r+   )r   r   333333?皙?rx   r      sample_weightr   )r0   repeatr   diffrO   )rH   rF   r   rn   ro   rp   rI   rI   rJ   !test_roc_curve_fpr_tpr_increasing  s   r   c                  C   s   ddg} ddg}t t| |d ddg} ddg}t t| |d g d} g d}t t| |d ddg} ddg}t t| |d g d} g d}t t| |d d S )Nr   r+   rx   r+   r   r   r   r   rx   r+   )r   r	   )r   r?   rI   rI   rJ   test_auc  s   r   c                  C   s   t t tg dddg W d    n1 sw   Y  t t tdgdg W d    n1 s5w   Y  g d} g d}dt| }t jtt|d t| | W d    d S 1 sew   Y  d S )	Nr   r   r   r   )r$   r+   r      )r            z+x is neither increasing nor decreasing : {}r   )	r   r   r   r	   formatr0   r   reescape)r   r?   error_messagerI   rI   rJ   test_auc_errors  s   "r   zy_true, labels)r   r+   r   r$   r   r+   r$   )abr   c)r   r   r   c                 C   sZ  t g dg dg dg dg}tg dg d}tg dg d}|| d	 }tg d
g d}tg dg d}|| d	 }tddgddg}	tddgddg}
|	|
 d	 }|| | d }tt| ||dd| |||g}g d}t j||d}tt| ||ddd| d}tjt|d t| ||dd d W d    d S 1 sw   Y  d S )Nr   r   r   r   r   r   ffffff?rx   333333?r   r   r   r+   r   r+   )r   r   r   r   r+   r   )r   r   rx   r$   r+   r+   r   )r   r   r   r   )r   r   r   r+   r   r   r   r   r   r   ovolabelsmulti_class)r   r   rx   )weightsr   r   r   r   z6average=None is not implemented for multi_class='ovo'.r   )r0   r   r   r   r   r   r   NotImplementedError)rH   r   y_scoresscore_01score_10average_score_01score_02score_20average_score_02score_12score_21average_score_12ovo_unweighted_scorepair_scores
prevalenceovo_weighted_scorer   rI   rI   rJ   #test_multiclass_ovo_roc_auc_toydata  s<   

"r   )r   r$   r   r$   )r   dr   r   )r   r   r   c                 C   s   t g dg dg dg dg}tg dg d}tg dg d}|| d	 }tt| ||d
d| tt| ||d
dd| d S )N)r   r   r   )r   r   r   )皙?r   ?)r   r   r   )r+   r   r+   r   )r   r   r  r   )r   r+   r   r+   )r   r   r  r   r$   r   r   r   r   r0   r   r   r   )rH   r   r   r   r   	ovo_scorerI   rI   rJ   *test_multiclass_ovo_roc_auc_toydata_binary'  s   
r  )r   r+   r$   r$   )r   r   r   r   c                 C   s   t g dg dg dg dg}tg d|d d df }tg d|d d df }tg d	|d d d
f }tt| |d|d d|||g || | d }tt| |d|d| |d |d  |d  }tt| |d|dd| d S )NrX   r   r   )r   rx   r   )r   r   r   )r   r   r   r+   r   r   r   r   )r   r+   r   r   r+   r   r   r+   r+   r$   ovr)r   r   r   g      @)r   r   r   rx   r   r  )rH   r   r   out_0out_1out_2result_unweightedresult_weightedrI   rI   rJ   #test_multiclass_ovr_roc_auc_toydataK  s,   
r  zmulti_class, average))r	  r   )r	  r   )r   r   c                 C   s   t g d}g dg dg dg dg}tt||| |dd g dg dg dg dg}t||| |ddk s:J dt d	 }t||| |dtd
ksPJ d S )N)r   r+   r$   r   )r   r   r   rX   )r   rX   r   r   )r   r   rX   r   )r   皙?r  r   r   r   rX   r   )r   r   rx   )r0   r   r   r   r   r   approx)r   r   rH   	y_perfecty_imperfecty_chancerI   rI   rJ   0test_perfect_imperfect_chance_multiclass_roc_aucv  s0   	r  c           	         s   |  t jjg dd d}t fdd|D }t|g dd}t| | \}}}t||}t	||dd	d
}|t
|ksCJ d S )N)       @rX   rx     )r   r*   c                    s"   g | ]}t jjd | d qS )r+   )nrB   r*   )r   multinomialrvsrj   )r   y_pred_iseedrI   rJ   r     s    z3test_micro_averaged_ovr_roc_auc.<locals>.<listcomp>r   )classesr	  r   r  )r   	dirichletr  r0   asarrayr   r   ravelr	   r   r   r  )	global_random_seedrG   rH   y_onehotrn   ro   rp   roc_auc_by_handroc_auc_autorI   r  rJ   test_micro_averaged_ovr_roc_auc  s   

r'  zmsg, y_true, labelsz!Parameter 'labels' must be uniquer   r$   r   )r   r   r   zKNumber of classes in y_true not equal to the number of columns in 'y_score'z"Parameter 'labels' must be ordered)r   r   r   zMNumber of given labels, 2, not equal to the number of columns in 'y_score', 3r+   r   r   zMNumber of given labels, 4, not equal to the number of columns in 'y_score', 3)r   r+   r$   r   )r   r   r   r   z2'y_true' contains labels not in parameter 'labels')r   r   r   er   r   r	  c                 C   sf   t g dg dg dg dg}tjt| d t||||d W d    d S 1 s,w   Y  d S )Nr   r   r   r   r   r   )r0   r   r   r   r   r   )msgrH   r   r   r   rI   rI   rJ   *test_roc_auc_score_multiclass_labels_error  s   I"r+  zmsg, kwargszLaverage must be one of \('macro', 'weighted', None\) for multiclass problemsr   )r   r   zUaverage must be one of \('micro', 'macro', 'weighted', None\) for multiclass problemszksample_weight is not supported for multiclass one-vs-one ROC AUC, 'sample_weight' must be None in this case)r   r   z|Partial AUC computation not available in multiclass setting, 'max_fpr' must be set to `None`, received `max_fpr=0.5` insteadrx   )r   rm   z'multi_class must be in \('ovo', 'ovr'\)c                 C   sr   t d}|dd}t|}|jdddd}tjt| d t||fi | W d    d S 1 s2w   Y  d S )N     r   r   r   r   )r#   randr   r   r   r   r   r   )r*  kwargsrC   rF   y_probrH   rI   rI   rJ   #test_roc_auc_score_multiclass_error  s   '"r1  c                  C   s   t d} | d}tjddd}d}tjt|d t|| W d    n1 s)w   Y  tjddd}tjt|d t|| W d    n1 sLw   Y  tj	dddd}tjt|d t|| W d    d S 1 sqw   Y  d S )Nr,  
   r3   dtyper   r   rL   )
r#   r.  r0   r   r   r   r   r   r   r   )rC   rG   rH   warn_messagerI   rI   rJ   test_auc_score_non_binary_class4  s    
"r6  
curve_funcc                 C   sd   t d}|jdddd}|d}d}tjt|d | || W d    d S 1 s+w   Y  d S )Nr,  r   r   r2  r   z"multiclass format is not supportedr   )r#   r   r.  r   r   r   )r7  rC   rH   rG   r*  rI   rI   rJ   &test_binary_clf_curve_multiclass_errorI  s   
"r8  c                 C   s   d}t jt|d | tjddgddddg W d    n1 s"w   Y  t jt|d | tjddgtdddg W d    n1 sGw   Y  g d	}| g d
|}| g d|}t||D ]\}}tj|| qcd S )Nzy_true takes value in {'a', 'b'} and pos_label is not specified: either make y_true take value in {0, 1} or {-1, 1} or pass pos_label explicitly.r   r   r   z<U1r3  r   rX   )r   rX   r   gzG?)r   r+   r+   r   )r   rX   rX   r   )	r   r   r   r0   r   objectziptestingr   )r7  r*  rG   	int_curvefloat_curveint_curve_partfloat_curve_partrI   rI   rJ   (test_binary_clf_curve_implicit_pos_labelS  s   r@  z.ignore:Support for labels represented as byteslabels_typerb   r   c                 C   sT   t ddg|}d}tjt|d | |ddg W d    d S 1 s#w   Y  d S )N   a   bzy_true takes value in {b'a', b'b'} and pos_label is not specified: either make y_true take value in {0, 1} or {-1, 1} or pass pos_label explicitly.r   r   rX   )r   r   r   r   )r7  rA  r   r*  rI   rI   rJ   .test_binary_clf_curve_implicit_bytes_pos_labelm  s   "rD  c                 C   sn   g d}g d}g d}| |||d}| |d d |d d |d d d}t ||D ]	\}}t|| q+d S )Nr   )r   r   r   r   rx   )r+   r+   r+   rx   r   r   rL   )r:  r   )r7  rH   rF   r   result_1result_2arr_1arr_2rI   rI   rJ   (test_binary_clf_curve_zero_sample_weight}  s   &rI  c           
      C   sB  t dd\}}}t|||  t|dd  |dd  | d\}}}|d dks(J |d |dd   ks6J d|t|dk< | }t|||  t|| g d}g d	}	t||	| d\}}}| rxt|g d
 t|g d t|g d nt|g d t|g d t|g d	 |j	|j	ksJ |j	|j	d ksJ d S )NTr   r+   r   r   rX   rL   r+   r   r   r+   )r+   r$   r   r   )rx   QUU?rX   rX   )rX   rx   rx   r   )r+   r$   r   )rx   rK  rx   rX   rX   )rX   rx   rx   rx   r   )
rK   _test_precision_recall_curver   meanr0   wherecopyr   r   r   )
r   rH   rp   rF   rB   rr   y_true_copyr   predict_probasrI   rI   rJ   test_precision_recall_curve  s*   $
rS  c                 C   s   t | ||d\}}}t| |}t|dd t|t| | tt| ||dd |j|jks/J |j|jd ks9J t | t||d\}}}|j|jksNJ |j|jd ksXJ d S )Nr   grh|?r   r$   r   r+   )	r   rh   r   r
   r   ra   r   r0   
zeros_like)rH   rF   r   rB   rP  r   precision_recall_aucrI   rI   rJ   rL    s    

rL  c              	   C   s  t jddw ddg}ddg}t||| d\}}}t||}t|g d t|g d t|d ddg}ddg}t||| d\}}}t||}t|g d	 t|g d
 t|d ddg}ddg}t||| d\}}}t||}t|ddg t|ddg t|d ddg}ddg}t||| d\}}}t||}t|g d t|g d t|d ddg}ddg}t||| d\}}}t||}t|ddg t|ddg t|d ddg}ddg}tjtdd t||| d\}}}W d    n1 sw   Y  tjtdd t||}W d    n	1 sw   Y  t	|g d t	|g d t	|d ddg}ddg}t||| d\}}}tt||d t|g d t|g d t 
ddgddgg}t 
ddgddgg}tjtdd t	t||ddd W d    n	1 sw   Y  tjtdd t	t||ddd W d    n	1 sw   Y  t	t||ddd t	t||ddd t 
ddgddgg}t 
ddgddgg}tjtdd t	t||ddd W d    n	1 sw   Y  tjtdd t	t||ddd W d    n	1 sw   Y  t	t||ddd t	t||ddd t 
ddgddgg}t 
ddgddgg}tt||ddd tt||ddd tt||ddd tt||ddd t 
ddgddgg}t 
ddgddgg}tjtdd t	t||ddd W d    n	1 sw   Y  t	t||ddd tjtdd t	t||ddd W d    n	1 sw   Y  tjtdd t	t||ddd W d    n	1 sw   Y  t 
ddgddgg}t 
ddgddgg}t	t||ddd t	t||ddd t	t||ddd t	t||ddd t 
ddgddgg}t 
ddgddgg}tt||ddd tt||ddd tt||ddd tt||ddd W d    n	1 sw   Y  t jddI t 
ddgddgg}t 
ddgddgg}tjtdd t	t||ddd W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )Nraise)allr   r+   r   )rx   r+   r+   r   rX   )rx   r   rX   r  rx   r   r   r   z!No positive class found in y_truer   r   )rX   rX   rX   )r+   rx   r   r   r   r   r   r   ignore)r0   errstater   r
   r   r   r   r   UserWarningr   r   )r   rH   rF   rB   rP  rp   auc_prcrI   rI   rJ   #test_precision_recall_curve_toydata  s:  










   $r\  c                  C   s   g d} g d}t | |dd\}}}t|g d g d} g d}t | |dd\}}}t|g d g d	} g d
}t | |dd\}}}t|ddg g d} g d
}t | |dd\}}}t|g d
 dS )z9Check the behaviour of the `drop_intermediate` parameter.r   r   Tr   )r   r   rX   r   r   )r   r   r   r   r   rX   r   r   r   r   )r   r   r   r   r   r   r+   r+   r+   r+   N)r   r   )rH   rF   rd   re   r   rI   rI   rJ   -test_precision_recall_curve_drop_intermediated  s0   r_  c                  C   s<   t jdtd} d| d d d< t d}t| |dksJ d S )Nr   r3  r+   r   r   )r0   r   r3   r   r
   rH   rF   rI   rI   rJ   &test_average_precision_constant_values  s   
ra  c                  C   sb   t ddg} t ddg}d}tjt|d t| |dd W d    d S 1 s*w   Y  d S )Nr   r+   z>pos_label=2 is not a valid label. It should be one of \[0, 1\]r   r$   rR   r0   r   r   r   r   r
   rH   rG   err_msgrI   rI   rJ   4test_average_precision_score_binary_pos_label_errors  s   "rf  c                  C   s   t ddgddgddgddgg} t ddgddgddgddgg}d}tjt|d t| |dd	 W d    d S 1 s>w   Y  d S )
Nr+   r   r   r   r   r   znParameter pos_label is fixed to 1 for multilabel-indicator y_true. Do not set pos_label or set pos_label to 1.r   rb  rc  rd  rI   rI   rJ   8test_average_precision_score_multilabel_pos_label_errors  s   """rg  c               	   C   s   t g d} t g dg dg dg dg dg dg}d}tjt|d t| |dd	 W d    d S 1 s:w   Y  d S )
N)r   r+   r$   r   r+   r$   )rx   r   r   )r   rx   r   )r   r   r   )r   r   rx   zdParameter pos_label is fixed to 1 for multiclass y_true. Do not set pos_label or set pos_label to 1.r   r   rb  rc  rd  rI   rI   rJ   8test_average_precision_score_multiclass_pos_label_errors  s   "rh  c                  C   s   t dd\} }}t| |}t| d| }t| d| }t| |d }||ks(J ||ks.J ||ks4J t| |}t| d| }t| d| }	t| |d }
||ksTJ ||	ksZJ ||
ks`J d S )NTr   r   gư>r2  )rK   r   r
   )rH   rp   rF   r   roc_auc_scaled_uproc_auc_scaled_downroc_auc_shiftedpr_aucpr_auc_scaled_uppr_auc_scaled_downpr_auc_shiftedrI   rI   rJ   test_score_scale_invariance  s   

rp  z(y_true,y_score,expected_fpr,expected_fnrr   r   )r   r   rx   )rx   r   r+   r   rx   r   r   r   r   r   )r+   r+   rx   r   r   )r   rx   rx   c                 C   (   t | |\}}}t|| t|| d S Nr   r   rH   rF   expected_fprexpected_fnrrn   fnrrp   rI   rI   rJ   test_det_curve_toydata  s   
ry  r   rx   rx   c                 C   rr  rs  rt  ru  rI   rI   rJ   test_det_curve_tie_handling  s   
r{  c                   C   s*   t tg dg dtg dg d d S )Nr   r   r   )r   r   rx   rx   r+   r+   )r   r   rI   rI   rI   rJ   test_det_curve_sanity_check  s   r|  rF   )r   r   rx   r   r+   c                 C   sF   t g dtd| d\}}}t|dg t|dg t|| g d S )N)r   r+   r   r+   r   r+   r   r`  r+   r   )r   r0   r   r   )rF   rn   rx  rf   rI   rI   rJ   test_det_curve_constant_scores  s   r}  rH   )r   r   r   r   r   r+   r   )r   r   r   r+   r+   r+   )r   r   r+   r+   r+   r+   )r   r+   r+   r+   r+   r+   c                 C   s.   t | | d\}}}t|dg t|dg d S )Nr`  r   rt  )rH   rn   rx  rp   rI   rI   rJ   test_det_curve_perfect_scores   s   r~  zy_true, y_pred, err_msgzinconsistent numbers of samplesr   r   r   z#Only one class is present in y_truer+   r+   r+   )cancerr  
not cancer)r   r   r   zpos_label is not specifiedc                 C   s>   t jt|d t| | W d    d S 1 sw   Y  d S )Nr   )r   r   r   r   rd  rI   rI   rJ   test_det_curve_bad_input1  s   "r  c            	      C   s   dgd dgd  } t g d}d| }t| |dd\}}}t| |dd\}}}|d td	ks4J |d td
ks?J t||d d d  t||d d d  d S )Nr  r   r  r   )
r   r   r   r   r   r   rx   r   r   r   r+   rb  r   r   r   rL   )r0   r   r   r   r  r   )	rH   y_pred_pos_not_cancery_pred_pos_cancerfpr_pos_cancerfnr_pos_cancerth_pos_cancerfpr_pos_not_cancerfnr_pos_not_cancerth_pos_not_cancerrI   rI   rJ   test_det_curve_pos_labelE  s"   r  c                 C   s  t | ddggddggd t | ddggddggd t | ddggddggd t | g dgg dgd t | g dgg dgd t | g d	gg dgd t | g d
gg dgd t | g dgg dgd t | g dgg dgd t | g dgg dgd t | g dgg dgd t | g d	gg dgd t | g d
gg dgd t | g dgg dgd t | g dgg dgd t | g dgg dgd t | g dgg dgd t | g dgg dgd t | g d	gg dgd t | g d
gg dgd t | g dgg dgd t | g dgg dgd t | g dgg dgd t | ddggddggd t | ddggddggd t | ddggddggd t | g dgg dgd t | g dgg dgd t | g d	gg dgd t | g d
gg dgd t | g dgg dgd t | g dgg dgd t | g dgg dgd t | g dgg dgd t | g dgg dgd d S )Nr   r+   r   r   rx   r   rq  r   r   r   gUUUUUU?r   g?r   g?r   rx   r   r  rx   r   r   rz  )rx   rx   rx   UUUUUU?)r+   r+   r+   r   )rx   rx   rx   rx   )r   
lrap_scorerI   rI   rJ   check_lrap_toy_  s^    r  c                 C   s   t d}tddD ]A}|jd|fd}t|}td|f}| ||dks(J | ||dks1J td|f}| ||dksAJ | ||dksJJ q	t| dgdgdgdggdgdgdgdggd d S )Nr   r$   r   r+   r   rX   rx   )r#   rZ   uniformr0   rT  r   r   r   )r  r*   n_labelsrF   y_score_tiesrH   rI   rI   rJ   !check_zero_or_all_relevant_labels  s   
*r  c                 C   s  t t | g dg d W d    n1 sw   Y  t t | g dg dg dg dg W d    n1 s>w   Y  t t | g dg dg dg dg W d    n1 scw   Y  t t | ddgddggddg W d    n1 sw   Y  t t | ddgddggddgg W d    n1 sw   Y  t t | ddgddggdgdgg W d    n1 sw   Y  t t | ddggddgddgg W d    n1 sw   Y  t t | dgdggddgddgg W d    n	1 sw   Y  t t | ddgddggdgdgg W d    d S 1 s:w   Y  d S )	Nr   )r   r   r   r   )r   r   r   )r   r   r   )r   r   r   r   r+   )r   r   r   r  rI   rI   rJ   check_lrap_error_raised  s:   "   $r  c              	   C   sz   t ddD ]5}td|f}t d|D ]&}t || D ]}td|f}d|d||| f< t| ||||  qqqd S )Nr$   r2  r+   r   )rZ   r0   r   r   r   )r  r  rF   
n_relevantrS   rH   rI   rI   rJ   check_lrap_only_ties  s   r  c              	      s   t ddD ]c}|t|d|fd  }td|f}d|d< d|d< t| ||d| d d  t d|D ]0 t |  D ]'td|f}d|d  f< t| ||t fddt  D  q?q7qd S )	Nr$   r2  r+   )r   r   )r   rL   r   c                 3   s(    | ]}|d  | d     V  qdS )r+   NrI   r   rP  r  rS   rI   rJ   	<genexpr>  s
    
z>check_lrap_without_tie_and_increasing_score.<locals>.<genexpr>)rZ   r0   r1   rN   r   r   rO   )r  r  rF   rH   rI   r  rJ   +check_lrap_without_tie_and_increasing_score  s&   r  c                    s
  t | | t| } t|}| j\}}t|f}t|D ]d}tj|| dd\}}|j}|| tj|d d	 }	|	 | | 
 d }
|
jdksQ|
j|krVd||< qd||< |
D ] t fdd|
D }||  |   7  < q\||  |
j  < q| S )	z8Simple implementation of label ranking average precisionT)return_inverser+   )	minlengthr   r   c                 3   s     | ]}|   kV  qd S rs  rI   r  labelrankrI   rJ   r    s    z_my_lrap.<locals>.<genexpr>)r"   r!   r/   r0   emptyrZ   rM   r   bincountcumsumnonzerorO   rM  )rH   rF   r@   r  r]   r^   unique_rankinv_rankn_ranks	corr_rankrelevantn_ranked_aboverI   r  rJ   _my_lrap  s*   

r  r   r-  c           	      C   s   t dd|||d\}}t|jd |jd |d}t|dr!| }t||}t||}t|| t|}|j	||fd}t||}t||}t|| d S )Nr+   F)rA   allow_unlabeledr*   	n_classesr@   r   )n_componentsrA   r*   toarrayr   )
r   r   r/   hasattrr  r   r  r   r#   r  )	r  r  r@   r*   rp   rH   rF   
score_lrapscore_my_lraprI   rI   rJ   %check_alternative_lrap_implementation  s,   
	





r  checkfuncc                 C   s   | | d S rs  rI   )r  r  rI   rI   rJ   test_label_ranking_avp;  s   r  c                   C   s   t t d S rs  )r  r   rI   rI   rI   rJ   test_lrap_error_raisedI  s   r  r@   )r+   r$   r   r-  r  )r$   r   r2  r*   c                 C   s   t t|| | d S rs  )r  r   )r@   r  r*   rI   rI   rJ   $test_alternative_lrap_implementationM  s   r  c                  C   s   t jg dg dg dgtd} t g dg dg dg}t g d}t g d	}tt| ||d
t || t |  d S )Nr  rJ  r]  r3  )r   r   r   r   )r   r   r   r   r   r   r   r   )rx   r   rX   )rX   rX   r   r   )r0   r   boolr   r   rO   )rH   rF   samplewise_lrapsr   rI   rI   rJ   &test_lrap_sample_weighting_zero_labelsV  s    r  c                   C   s  t tddggddggd t tddggddggd t tddggddggd t tddggddggd t tg dgg dgd t tg dgg dgd t tg d	gg dgd t tg d
gg dgd t tg dgg dgd t tg dgg dgd t tg dgg dgd t tg dgg dgd t tg dgg dgd t tg dgg dgd t tg d	gg dgd t tg d
gg dgd t tg dgg dgd t tg dgg dgd t tg dgg dgd t tg dgg dgd t tg dgg dgd t tg dgg dgd t tg d	gg dgd t tg d
gg dgd t tg dgg dgd t tg dgg dgd t tg dgg dgd t tg dgg dgd t tg d	g dgg dg dgd t tg d	g dg d
gg dg dg dgd t tg d	g dg d
gg dg dg dgd d S )Nr   r+   r   r   r$   r  rq  r   r   r   r   r   r   r   r  r  r  r   g      $@r   r+   r   r  r   r2  r  r(  g@r   r+   r   r   r   rI   rI   rI   rJ   test_coverage_errork  sX    ((r  c                   C   sT  t tddggddggd t tddggddggd t tddggddggd t tddggddggd t tg dgg dgd t tg dgg dgd t tg dgg dgd t tg d	gg dgd t tg d
gg dgd t tg dgg dgd t tg dgg dgd t tg dgg dgd d S )Nr   rx   r+   r$   r  rz  r   r   r   r   r   r   r   r  r  rI   rI   rI   rJ   test_coverage_tie_handling  s    r  zy_true, y_scorec                 C   s>   t jtdd t| | W d    d S 1 sw   Y  d S )Nz'Expected 2D array, got 1D array insteadr   )r   r   r   r   r`  rI   rI   rJ   test_coverage_1d_error_message  s   "r  c                   C   sT  t tddggddggd t tddggddggd t tg dgg dgd t tg dgg dgd t tg d	gg dgd t tg d
gg dgd t tg dgg dgd t tg dgg dgd t tddggddggd t tddggddggd t tddggddggd t tddggddggd t tg dgg dgd t tg dgg dgd t tg dgg dgd t tg dgg dgd t tg dg dgg dg dgd t tg dg dg d	gg dg dg dgd t tg dg dg d	gg dg dg dgd d S )Nr   r+   r   r   r   rq  r   rx   r   r   rX   r   r   r  r  r  rz  r  r  r  r(  r  r   r   rI   rI   rI   rJ   test_label_ranking_loss  s@    ((r  csr_containerc                 C   s6   t t| tg dg dgg dg dgd d S )Nr   r   r  r  rx   )r   r   r0   r   )r  rI   rI   rJ   test_label_ranking_loss_sparse  s   &r  c                   C   s  t t tddgddggddg W d    n1 sw   Y  t t tddgddggddgg W d    n1 s@w   Y  t t tddgddggdgdgg W d    n1 sdw   Y  t t tddggddgddgg W d    n1 sw   Y  t t tdgdggddgddgg W d    n1 sw   Y  t t tddgddggdgdgg W d    d S 1 sw   Y  d S )Nr   r+   )r   r   r   r   rI   rI   rI   rJ   $test_ranking_appropriate_input_shape  s$      "r  c                   C   s   t tddggddggd t tddggddggd t tg dgg dgd t tg dgg dgd t tg dgg dgd t tg dgg dgd t tg d	gg dgd t tg d
gg dgd d S )Nr+   r   rx   r   rz  r   r   r   r   r   r  rI   rI   rI   rJ   test_ranking_loss_ties_handling  s    r  c                  C   H   t ddd\} }| d }t|| tjdd\}}t|| d S Nr   r2  )r*   r  r+   )r$   r   r2  )r   _test_dcg_score_forr0   r4   r5   random_samplerp   rH   rF   rI   rI   rJ   test_dcg_score  
   

r  c                 C   s   t t | jd d }t| | }t| |}||k sJ t| | dd|k s,J |j| jd fks7J |j| jd fksBJ |tt | d d d d df | j	ddks]J d S )Nr+   r$   r   kr   rL   axis)
r0   log2r1   r/   r   rW  r   r  sortrO   )rH   rF   discountidealr]   rI   rI   rJ   r    s   

:r  c               	   C   sL  t t dg} t | j}t| |}t| |dd}dt t dd }|t|	 | 
  gks6J |t|| d d d d df  	 gksMJ d|dd	d f< t| |}t| |dd}|t|| d d d d df  	 gksxJ |t|d d 	 | dd	d f 
  |dd  	 | dd d	f 
   gksJ d S )
Nr   Tignore_tiesr+   r$   r   rL   r   r   )r0   r!  r1   r   r/   r   r  r   r  rO   rM  )rH   rF   dcgdcg_ignore_ties	discountsrI   rI   rJ   test_dcg_ties%  s"   
 .
.""r  c               	   C   s>   t dd} t| | dddtt| | dddksJ d S )N   )r$   r   r   T)r  r  )r0   r1   rN   r   r   r  )r   rI   rI   rJ   test_ndcg_ignore_ties_with_k9  s   r  c                  C   sb   t g dg} t g dg}d}tjt|d t| | W d   dS 1 s*w   Y  dS )zDCheck `ndcg_score` exception when `y_true` contains negative values.)g{Gzg(\gGz޿g(\?gQ?)gQ?gףp=
?r   gQ?gHzG?z7ndcg_score should not be used on negative y_true valuesr   N)r0   r   r   r   r   r   )rH   rF   r   rI   rI   rJ    test_ndcg_negative_ndarray_error@  s   "r  c                  C   s   t ddd} | t jdjdd| jd }t| |}t| |dd	}|t	|ks-J |t	d
ks6J |d7 }t| |t	d
ksFJ d S )NF   r   r2  r   皙ɿr   r   Tr  rX   r  )
r0   r1   rN   r4   r5   r  r/   r   r   r  )rH   rF   ndcgndcg_no_tiesrI   rI   rJ   test_ndcg_invariantI  s   
r  r  c              
   C   s  dt dd d  }t t dddd}|t jdjdd	|jd
 }t||| dt	
dt t dd ks<J t||| dt	
dt t dd ksSJ t||| dt	
dt t dd ksjJ t||d| dt	
dt t dd ksJ t||| dt	
dt t dd  ksJ t||| dt	
dt t dd  ksJ dt d }dt t dd  }t||| dt	
|t d ksJ t||| dt	
t dksJ t||| dt	
|ksJ t||| dt	
dks	J d S )Nr   r   r   r   rL   )r   r+   r   r  r   r   r  r$   r+   r2  )log_baser  )r   r   	   rX   )r0   eyetiler1   r4   r5   r  r/   r   r   r  r  r   log10r   rM  r   r   rO   )r  rH   rF   y_score_noisyexpected_dcg_scorerI   rI   rJ   test_ndcg_toy_examplesT  s^   


"r  c                  C   sJ   d} t jt| d tdggdgg W d   dS 1 sw   Y  dS )zhCheck that we raise an informative error message when trying to
    compute NDCG with a single document.zTComputing NDCG is only meaningful when there is more than 1 document. Got 1 instead.r   r+   N)r   r   r   r   )re  rI   rI   rJ   test_ndcg_error_single_document{  s
   "r  c                  C   r  r  )r   _test_ndcg_score_forr0   r4   r5   r  r  rI   rI   rJ   test_ndcg_score  r  r  c                 C   s   t | | }t | |}||k sJ | dkjdd}||  tt|  ks,J || tt| ks<J ||  tt| ||  t| | |   ksVJ || tt| ksfJ |j	| j	d fksqJ |j	| j	d fks|J d S )Nr   r+   r  )
r   rW  r   r  r0   r   rO   r   r   r/   )rH   rF   r  r]   all_zerorI   rI   rJ   r    s   

$ 
 r  c                  C   sz  t g d} t| | dddksJ t| | dddksJ tt t| | dds,J W d    n1 s6w   Y  tt t| | ddsJJ W d    n1 sTw   Y  tt t| | ddshJ W d    n1 srw   Y  t g d}t| |dd}t| |}||ksJ t| |d	dd
ksJ tdd\} }}t dddD ]}tt| ||dt	| || qd S )Nr  r+   )rm   gMbP?gg?r   )r   r   r   g{Gz?r   rx   Tr   g-C6?r   )
r0   r   r   r   r   r   rK   linspacer   r~   )rH   r   roc_auc_with_max_fpr_oneunconstrained_roc_aucrG   rp   rm   rI   rI   rJ   test_partial_roc_auc_score  s0   

r  zy_true, k, true_scorer   r$   r   r   c                 C   sF   t g dg dg dg dg}t| ||d}|t|ks!J d S )Nr  r   r   r   r   r   r   r   r   r   r   r   r   r  r0   r   r   r   r  )rH   r  
true_scorerF   r]   rI   rI   rJ   test_top_k_accuracy_score  s   	r   zy_score, k, true_score)rL   rL   r+   r+   )rL   r+   rL   r+   )r   r   r   r   )r   r   r   r   c                 C   s   g d}|   dkr|  dkrdnd}|dkr | |ktjn|}t|| |d}t||}||  kr<t|ks?J  J d S )Nr  r   r+   rx   r  )	minmaxastyper0   int64r   r   r   r  )rF   r  r  rH   rf   rG   r]   	score_accrI   rI   rJ    test_top_k_accuracy_score_binary  s    
&r  zy_true, true_score, labels)r   r+   r+   r$   )r   r+   r+   r+   r^  )r   r)  r)  r   )r   r   r   r)  labels_as_ndarrayc                 C   sV   |rt |}t g dg dg dg dg}t| |d|d}|t|ks)J dS )z,Test when labels and y_score are multiclass.r  r  r  r  r$   r  r   N)r0   r!  r   r   r   r  )rH   r  r   r  rF   r]   rI   rI   rJ   0test_top_k_accuracy_score_multiclass_with_labels  s   
	r	  c                     s   t jddddd\ t dd\} }}}tdd| | t| |f||fD ]\  fddtddD }tt	|dksHJ q*d S )	Nr2  r  r   )r  r@   n_informativer*   )r*   c                    s    g | ]}t  |d qS )r  )r   r:   )r   r  r>   rE   r?   rI   rJ   r     s    z8test_top_k_accuracy_score_increasing.<locals>.<listcomp>r$   )
r   make_classificationr   r   r9   r:  rZ   r0   rW  r   )X_trainX_testy_trainy_testscoresrI   r  rJ   $test_top_k_accuracy_score_increasing  s   

r  c                 C   sB   t g dg dg dg dg}t| ||dt|ksJ d S )N)r   r   r   r   )r+   r   r   r   )r   r   r   r   r^  r  r  )rH   r  r  rF   rI   rI   rJ   test_top_k_accuracy_score_ties  s   
 r  z	y_true, kr   c                 C   sr   t g dg dg dg dg}d}tjt|d t| ||d}W d    n1 s,w   Y  |dks7J d S )	Nr  )r   r   r   r   )r   r   r   r   )r   r   r   r   zu'k' \(\d+\) greater than or equal to 'n_classes' \(\d+\) will result in a perfect score and is therefore meaningless.r   r  r+   )r0   r   r   r   r   r   )rH   r  rF   r   r]   rI   rI   rJ   !test_top_k_accuracy_score_warning)  s   	r  zy_true, y_score, labels, msg)r   g=
ףp=?r+   r$   )r   r   r   )r   r   r   r   )r   rx   r   z9y type must be 'binary' or 'multiclass', got 'continuous'zZNumber of classes in 'y_true' \(4\) not equal to the number of classes in 'y_score' \(3\).)r   r   r   r   z"Parameter 'labels' must be unique.z#Parameter 'labels' must be ordered.)r   r   r+   r$   zSNumber of given labels \(4\) not equal to the number of classes in 'y_score' \(3\).r  z3'y_true' contains labels not in parameter 'labels'.)rx   r   r   )r   r   r   z}`y_true` is binary while y_score is 2d with 3 classes. If `y_true` does not contain all the labels, `labels` must be providedc                 C   sD   t jt|d t| |d|d W d    d S 1 sw   Y  d S )Nr   r$   r  )r   r   r   r   )rH   rF   r   r*  rI   rI   rJ   test_top_k_accuracy_score_errorB  s   S"r  c                 C   sJ   | g dg dg}t g dg dg}t||}|tdks#J d S )Nr   r   )rx   r   r   r  )r0   r   r   r   r  )r  rH   rF   resultrI   rI   rJ   Otest_label_ranking_avg_precision_score_should_allow_csr_matrix_for_y_true_input  s   
r  metricr  ))FT)r   r+   )r   rX   )zeroonec                 C   s   t jd}d|d }}|j||dd}||}| |||d}t|tr/t |r-J dS |\}}	}
t | r=J t |	 rFJ t |
 rOJ dS )zCheck that the metric works with different types of `pos_label`.

    We can expect `pos_label` to be a bool, an integer, a float, a string.
    No error should be raised for those types.
    *   r2  rL   T)r   replacerb  N)	r0   r4   r5   choicer.  
isinstancerP   r   any)r  r  rC   r@   rR   rH   y_probar  metric_1metric_2r   rI   rI   rJ   #test_ranking_metric_pos_label_types  s   


r#  c                 C   sL   t j| }|jdddd}|d}t||\}}}t |d s$J dS )zCheck that thresholds do not exceed 1.0 when `y_score` is a probability
    estimate.

    Non-regression test for:
    https://github.com/scikit-learn/scikit-learn/issues/26193
    r   r$   r2  r   N)r0   r4   r5   r   r.  r   isinf)r#  rC   rH   rF   rp   r   rI   rI   rJ   (test_roc_curve_with_probablity_estimates  s
   
r%  c                  C   s   t dd\} }}d}tjt|d t| |d W d   n1 s"w   Y  d}tjt|d t| ||d W d   dS 1 sCw   Y  dS )	z)Check the message for future deprecation.Tr   z)probas_pred was deprecated in version 1.5r   )probas_predNz4`probas_pred` and `y_score` cannot be both specified)r&  rF   )rK   r   r   FutureWarningr   r   r   )rH   rp   rF   warn_msg	error_msgrI   rI   rJ   /test_precision_recall_curve_deprecation_warning  s    "r*  )NF)r   r-  r   )r   r   numpyr0   r   scipyr   sklearnr   r   sklearn.datasetsr   sklearn.exceptionsr   sklearn.linear_modelr   sklearn.metricsr   r	   r
   r   r   r   r   r   r   r   r   r   r   sklearn.metrics._rankingr   r   sklearn.model_selectionr   sklearn.preprocessingr   sklearn.random_projectionr   sklearn.utils._testingr   r   r   r   r   sklearn.utils.extmathr   sklearn.utils.fixesr    sklearn.utils.validationr!   r"   r#   CURVE_FUNCSrK   rW   ra   rh   r~   markparametrizer   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r'  r+  r1  r6  r8  r@  filterwarningsrD  rI  rS  rL  r\  r_  ra  rf  rg  rh  rp  ry  r{  r|  r}  r~  r  r  r  r  r  r  r  r  r  r  r  rZ   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r	  r  r  r  r  r  r#  r%  r*  rI   rI   rI   rJ   <module>   s   <
0
r

	2


	"
"	


	G				
#
	




 $"	






;' 	7
+
		
&
	
R