o
    iH                    @   s0  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dCd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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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;<g dg dg dg dg ddfg dg dg dg ddfg dg dg dg ddfg dg dg dg ddfg dg dg dg ddfg dg dg dg ddfg dg dg dg ddfg dg dg dg ddfgdd Zaej;<ddSd gdhdhgdSd gd dSgfd dSgdhdhgdSd gd dSgfg dg ddhd gd dSgfg dg ddhd gd dSg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dd Zbdd Zcej;<dg ddd Zdej;<dg dg dg dg dg dgdd Zee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 Zfdd ZgddÄ Zhddń ZiddǄ ZjddɄ Zkdd˄ Zldd̈́ Zm	 dDddфZnej;<dehelekeifej;<deemfddՄ Zoddׄ Zpej;<dd١ej;<ddۡej;<deqdSddބ Zrdd Zsdd Ztdd Zuej;<dg dg dfg dg dgfg dgg dfgdd Zvdd Zwej;<de0dd Zxdd Zydd Zzdd Z{dd Z|dd Z}dd Z~dd Zdd Zej;<dddgdd Zd d Zdd Zdd Zd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d0fg d1g d(g d)g d*g d+gg dWd2fg d1g d(g d)g d*g d+gg d3d4fd dSgg d5g d6gdd7fgd8d9 Zej;<de0d:d; Zej;<d<eeeegej;<d=g d>d?d@ ZdAdB ZdS (E      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      ZlinearT)ZkernelZprobabilityrandom_state   )r   Z	load_irisdatatargetshapenparanger#   shuffleintrandomRandomStateZc_Zrandnr   ZSVCfitpredict_probaZpredict)ZdatasetbinaryXy	n_samples
n_featuresprngZhalfclfy_scorey_predy_true r?   q/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/sklearn/metrics/tests/test_ranking.pymake_prediction8   s*   


*
rA   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   )r,   uniquereshapesumfloatlen)r>   r<   	pos_labelposnegZdiff_matrixZ	n_correctr?   r?   r@   _auch   s   rK   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(   NrB   r         ?)r,   rC   rE   ZargsortrangerG   )	r>   r<   rH   Zn_posorderscoreiprecjr?   r?   r@   _average_precisionw   s"   	rS   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reversedrM   rG   )r>   r<   	precisionrecall	thresholdZaverage_precisionrP   r?   r?   r@   _average_precision_slow   s   
"rY   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   r,   appendargmaxZinterp)r>   	y_predictmax_fprfprtpr_new_fprnew_tprZidx_outZidx_inZx_interpZy_interpr?   r?   r@   _partial_roc   s   z,_partial_roc_auc_score.<locals>._partial_rocr         ?r(   )r	   )r>   r\   r]   rc   ra   rb   Zpartial_aucZfpr1Zfpr2Zmin_areaZmax_arear?   r?   r@   _partial_roc_auc_score   s   
re   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r4   drop_intermediater$   decimal)rA   rK   r   r	   r   r   r   r+   )	rf   r>   r`   r<   Zexpected_aucr^   r_   
thresholdsroc_aucr?   r?   r@   test_roc_curve   s   

rn   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   sizeTrh   rB   )r,   r0   r1   arrayrandintr   r+   )r:   r>   r=   r^   r_   Zthrr?   r?   r@   test_roc_curve_end_points   s   rv   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 )NTrg   rL   r$   rj   )rA   r   r,   rE   rZ   r   r+   )
r>   r`   r<   r^   r_   rl   Ztpr_correctttpr9   r?   r?   r@   test_roc_returns_consistency   s   
ry   c                  C   sJ   t dd\} }}tt t| | W d    d S 1 sw   Y  d S )NFrg   )rA   pytestraises
ValueErrorr   )r>   r`   r<   r?   r?   r@   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 )NTrg   rd   ?r$   rj   )rA   r   r	   r   r+   )r>   r`   r<   r^   r_   rl   rm   r?   r?   r@   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 )NTrg   rd   r$   rj   g(\?)rA   r,   onesr+   r   r	   r   zeros)r>   predr<   Ztrivial_predr^   r_   rl   rm   r?   r?   r@   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(   r?   ).0xr?   r?   r@   
<listcomp>5  s    z,test_roc_curve_one_label.<locals>.<listcomp>)
rz   warnsr   r   r   r,   fullrG   nanr+   )r>   r=   expected_messager^   r_   rl   r?   r?   r@   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(   rL           rd         ?      ?r   r   r   rd   rL   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   rz   r   r   r,   r   mathisnanrt   )r>   r<   r_   r^   r`   rm   r   r	   r?   r?   r@   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   皙?rd   333333?ffffff?rL   Trh   rL   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~   rL   r~   r   )r   r   r,   inf)r>   r<   r_   r^   rl   r?   r?   r@    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?皙?rd   r      sample_weightr   )r,   repeatr   diffrE   )r>   r<   r   r^   r_   r`   r?   r?   r@   !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(   rd   r(   r   r   r   r   rd   r(   )r   r	   )r   r6   r?   r?   r@   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(   rp      )r            z+x is neither increasing nor decreasing : {}r   )	rz   r{   r|   r	   formatr,   rt   reescape)r   r6   error_messager?   r?   r@   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?rd   333333?r   r   r   r(   r   r(   )r   r   r   r   r(   r   )r   r   rd   r$   r(   r(   r   )r   r   r   r   )r   r   r   r(   r   r   r   r   r   rp   ovolabelsmulti_class)r   r   rd   )weightsr   r   r   r   z6average=None is not implemented for multi_class='ovo'.r   )r,   rt   r   r   r   rz   r{   NotImplementedError)r>   r   y_scoresscore_01score_10Zaverage_score_01Zscore_02Zscore_20Zaverage_score_02Zscore_12Zscore_21Zaverage_score_12Zovo_unweighted_scoreZpair_scoresZ
prevalenceZovo_weighted_scorer   r?   r?   r@   #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   r,   rt   r   r   )r>   r   r   r   r   Z	ovo_scorer?   r?   r@   *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rL   r   r   )r   rd   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   rd   r   r   )r>   r   r   Zout_0Zout_1Zout_2Zresult_unweightedZresult_weightedr?   r?   r@   #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)rp   r(   r$   r   )r   r   r   rL   )r   rL   r   r   )r   r   rL   r   )r   皙?r   r   r   r   rL   r   )r   r   rd   )r,   rt   r   r   r   rz   approx)r   r   r>   Z	y_perfectZy_imperfectZy_chancer?   r?   r@   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)       @rL   rd     )rs   r'   c                    s"   g | ]}t jjd | d qS )r(   )nr9   r'   )r   Zmultinomialrvsr[   )r   Zy_pred_iseedr?   r@   r     s    z3test_micro_averaged_ovr_roc_auc.<locals>.<listcomp>r   )classesr   r   r   )r   Z	dirichletr   r,   asarrayr   r   Zravelr	   r   rz   r   )	global_random_seedr=   r>   Zy_onehotr^   r_   r`   Zroc_auc_by_handZroc_auc_autor?   r   r@   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$   rp   )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   )r,   rt   rz   r{   r|   r   )msgr>   r   r   r   r?   r?   r@   *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` insteadrd   )r   r]   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     rp   r   rr   r   )r#   randr   ru   rz   r{   r|   r   )r   kwargsr:   r<   Zy_probr>   r?   r?   r@   #test_roc_auc_score_multiclass_error  s   '"r   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   
   r/   Zdtyper   r   rB   )
r#   r   r,   r   rz   r   r   r   r   r   )r:   r=   r>   warn_messager?   r?   r@   test_auc_score_non_binary_class4  s    
"r   
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   rp   r   rr   z"multiclass format is not supportedr   )r#   ru   r   rz   r{   r|   )r   r:   r>   r=   r   r?   r?   r@   &test_binary_clf_curve_multiclass_errorI  s   
"r   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<U1r   r   rL   )r   rL   r   gzG?)r   r(   r(   r   )r   rL   rL   r   )	rz   r{   r|   r,   rt   objectziptestingr   )r   r   r=   Z	int_curveZfloat_curveZint_curve_partZfloat_curve_partr?   r?   r@   (test_binary_clf_curve_implicit_pos_labelS  s   r  z.ignore:Support for labels represented as byteslabels_typerT   rt   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   bz8Support for labels represented as bytes is not supportedr   r   rL   )r   rz   r{   	TypeError)r   r  r   r   r?   r?   r@   .test_binary_clf_curve_implicit_bytes_pos_labell  s
   "r  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   rd   )r(   r(   r(   rd   r   r   rB   )r   r   )r   r>   r<   r   Zresult_1Zresult_2Zarr_1Zarr_2r?   r?   r@   (test_binary_clf_curve_zero_sample_weightx  s   &r  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 )NTrg   r(   rh   r   rL   rB   r(   r   r   r(   )r(   r$   rp   r   )rd   QUU?rL   rL   )rL   rd   rd   r   )r(   r$   r   )rd   r
  rd   rL   rL   )rL   rd   rd   rd   r   )
rA   _test_precision_recall_curver   meanr,   wherecopyr   r   rs   )
rf   r>   r`   r<   r9   rrw   Zy_true_copyr   Zpredict_probasr?   r?   r@   test_precision_recall_curve  s*   $
r  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 )Nrh   grh|?rp   r$   rj   r(   )	r   rY   r   r
   r   rS   rs   r,   
zeros_like)r>   r<   rf   r9   r  rl   Zprecision_recall_aucr?   r?   r@   r    s    

r  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(   rh   )rd   r(   r(   r   rL   )rd   r   rL   r   rd   r   r   r   z!No positive class found in y_truer   r   )rL   rL   rL   )r(   rd   r   r   r   r   r   r   ignore)r,   Zerrstater   r
   r   r   rz   r   UserWarningr   rt   )rf   r>   r<   r9   r  r`   Zauc_prcr?   r?   r@   #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   Trh   )r   r   rL   r   r   )r   r   r   r   r~   rL   r   r   r   r   )r   r   r   r   r   r   r(   r(   r(   r(   N)r   r   )r>   r<   rV   rW   rl   r?   r?   r@   -test_precision_recall_curve_drop_intermediate_  s0   r  c                  C   s<   t jdtd} d| d d d< t d}t| |dksJ d S )Nrq   r   r(   r   r   )r,   r   r/   r   r
   r>   r<   r?   r?   r@   &test_average_precision_constant_values  s   
r  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$   rH   r,   rt   rz   r{   r|   r
   r>   r=   err_msgr?   r?   r@   4test_average_precision_score_binary_pos_label_errors  s   "r   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   r  r  r  r?   r?   r@   8test_average_precision_score_multilabel_pos_label_errors  s   """r!  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$   )rd   r   r   )r   rd   r   )r   r   r   )r   r   rd   zdParameter pos_label is fixed to 1 for multiclass y_true. Do not set pos_label or set pos_label to 1.r   rp   r  r  r  r?   r?   r@   8test_average_precision_score_multiclass_pos_label_errors  s   "r"  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 )NTrg   rq   gư>r   )rA   r   r
   )r>   r`   r<   rm   Zroc_auc_scaled_upZroc_auc_scaled_downZroc_auc_shiftedZpr_aucZpr_auc_scaled_upZpr_auc_scaled_downZpr_auc_shiftedr?   r?   r@   test_score_scale_invariance  s   

r#  z(y_true,y_score,expected_fpr,expected_fnrr   r   )r   r   rd   )rd   r   r(   r   rd   r   r   )rd   rd   r   r   r   r   )r(   r(   rd   r   )r   r(   r(   r(   r   r   )r   rd   rd   c                 C   (   t | |\}}}t|| t|| d S Nr   r   r>   r<   expected_fprexpected_fnrr^   fnrr`   r?   r?   r@   test_det_curve_toydata  s   
r,  )r>   r<   r)  r*  ri   )r(   r(   rd   r   )r(   r(   r   c                 C   s,   t | ||d\}}}t|| t|| d S )Nrh   r'  )r>   r<   r)  r*  ri   r^   r+  r`   r?   r?   r@    test_det_curve_drop_intermediate  s   
r-  r   rd   rd   c                 C   r%  r&  r'  r(  r?   r?   r@   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   rd   rd   r(   r(   )r   r   r?   r?   r?   r@   test_det_curve_sanity_check!  s   r0  r<   )r   r   rd   r   r(   c                 C   sN   t g dtd| d\}}}t|ddg t|ddg t|| tjg d S )N)r   r(   r   r(   r   r(   r   r  r(   r   )r   r,   r   r   r   )r<   r^   r+  rX   r?   r?   r@   test_det_curve_constant_scores)  s   r1  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(   c                 C   s.   t | | d\}}}t|dg t|dg d S )Nr  r   r'  )r>   r^   r+  r`   r?   r?   r@   test_det_curve_perfect_scores4  s   r2  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(   )cancerr5  
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   )rz   r{   r|   r   r  r?   r?   r@   test_det_curve_bad_inputE  s   "r7  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 )Nr5  rp   r6  r   )
r   r   r   r   r   r   rd   r   r   r~   r(   r  r   r   r   rB   )r,   rt   r   rz   r   r   )	r>   Zy_pred_pos_not_cancerZy_pred_pos_cancerZfpr_pos_cancerZfnr_pos_cancerZth_pos_cancerZfpr_pos_not_cancerZfnr_pos_not_cancerZth_pos_not_cancerr?   r?   r@   test_det_curve_pos_labelY  s"   r8  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   rd   r   r$  r   r   r   gUUUUUU?r   g?r   g?r   rd   r   r4  rd   r   r   r.  )rd   rd   rd   UUUUUU?)r(   r(   r(   r   )rd   rd   rd   rd   )r   
lrap_scorer?   r?   r@   check_lrap_toys  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(   rr   rL   rd   )r#   rM   uniformr,   r  r   r   r   )r=  r'   n_labelsr<   Zy_score_tiesr>   r?   r?   r@   !check_zero_or_all_relevant_labels  s   
*rA  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(   )rz   r{   r|   r<  r?   r?   r@   check_lrap_error_raised  s:   "   $rB  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$   r   r(   r   )rM   r,   r   r   r   )r=  r@  r<   
n_relevantrI   r>   r?   r?   r@   check_lrap_only_ties  s   rD  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$   r   r(   )r   r   )r   rB   r   c                 3   s(    | ]}|d  | d     V  qdS )r(   Nr?   r   r  rC  rI   r?   r@   	<genexpr>  s
    
z>check_lrap_without_tie_and_increasing_score.<locals>.<genexpr>)rM   r,   r-   rD   r   r   rE   )r=  r@  r<   r>   r?   rF  r@   +check_lrap_without_tie_and_increasing_score  s&   rH  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)Zreturn_inverser(   )Z	minlengthr   r   c                 3   s     | ]}|   kV  qd S r&  r?   rE  labelZrankr?   r@   rG  %  s    z_my_lrap.<locals>.<genexpr>)r"   r!   r+   r,   emptyrM   rC   rs   ZbincountZcumsumZnonzerorE   r  )r>   r<   r7   r@  rO   rP   Zunique_rankZinv_rankZn_ranksZ	corr_rankZrelevantZn_ranked_abover?   rI  r@   _my_lrap	  s*   

rL  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)r8   Zallow_unlabeledr'   	n_classesr7   r   )Zn_componentsr8   r'   toarrayrr   )
r   r   r+   hasattrrN  r   rL  r   r#   r?  )	r=  rM  r7   r'   r`   r>   r<   Z
score_lrapZscore_my_lrapr?   r?   r@   %check_alternative_lrap_implementation/  s,   
	





rP  checkfuncc                 C   s   | | d S r&  r?   )rQ  rR  r?   r?   r@   test_label_ranking_avpO  s   rS  c                   C   s   t t d S r&  )rB  r   r?   r?   r?   r@   test_lrap_error_raised]  s   rT  r7   )r(   r$   r   r   rM  )r$   r   r   r'   c                 C   s   t t|| | d S r&  )rP  r   )r7   rM  r'   r?   r?   r@   $test_alternative_lrap_implementationa  s   rU  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   r	  r  r   )r   r   r   r   )r   r   r   r   r   r   r   r   )rd   r   rL   )rL   rL   r   r   )r,   rt   boolr   r   rE   )r>   r<   Zsamplewise_lrapsr   r?   r?   r@   &test_lrap_sample_weighting_zero_labelsj  s    rX  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$   r3  r$  r   r   r   r   rp   r   r   r4  r9  r:  r   g      $@r   r(   rp   r   r   r   rZ  r   g@rp   r(   rp   r   r   r?   r?   r?   r@   test_coverage_error  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   rd   r(   r$   r3  r.  r   r   r   r   rp   r   r   r4  r^  r?   r?   r?   r@   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   )rz   r{   r|   r   r  r?   r?   r@   test_coverage_1d_error_message  s   "ra  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   r$  r   rd   r   r   rL   r   r   r3  r:  r4  r.  rY  r[  r\  r   r]  r   r   r?   r?   r?   r@   test_label_ranking_loss  s@    ((rc  csr_containerc                 C   s6   t t| tg dg dgg dg dgd d S )Nr   r   r\  r]  rd   )r   r   r,   rt   )rd  r?   r?   r@   test_label_ranking_loss_sparse   s   &re  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(   )rz   r{   r|   r   r?   r?   r?   r@   $test_ranking_appropriate_input_shape
  s$      "rf  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   rd   r   r.  r   r   r   r   r   rb  r?   r?   r?   r@   test_ranking_loss_ties_handling  s    rg  c                  C   H   t ddd\} }| d }t|| tjdd\}}t|| d S Nr   r   )r'   rM  r(   )r$   rq   r   )r   _test_dcg_score_forr,   r0   r1   random_sampler`   r>   r<   r?   r?   r@   test_dcg_score&  
   

rm  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   rB   Zaxis)
r,   log2r-   r+   r   r  rz   r   sortrE   )r>   r<   ZdiscountidealrO   r?   r?   r@   rj  .  s   

:rj  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   rB   r   rp   )r,   r   r-   r   r+   r   rr  rz   r   rE   r  )r>   r<   ZdcgZdcg_ignore_tiesZ	discountsr?   r?   r@   test_dcg_ties9  s"   
 .
.""rw  c               	   C   s>   t dd} t| | dddtt| | dddksJ d S )N   )r$   r   rp   T)rp  rv  )r,   r-   rD   r   rz   r   )r   r?   r?   r@   test_ndcg_ignore_ties_with_kM  s   ry  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)r,   rt   rz   r{   r|   r   )r>   r<   r   r?   r?   r@    test_ndcg_negative_ndarray_errorT  s   "rz  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   r   r   皙ɿr   rr   Tru  rL   r   )
r,   r-   rD   r0   r1   r?  r+   r   rz   r   )r>   r<   ZndcgZndcg_no_tiesr?   r?   r@   test_ndcg_invariant]  s   
r}  rv  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 )Nrp   r   r   r   rB   )r   r(   r   r|  r   rr   ru  r$   r(   r   )Zlog_baserv  )r   r   	   rL   )r,   eyeZtiler-   r0   r1   r?  r+   r   rz   r   rr  r   log10r   r  r   r   rE   )rv  r>   r<   Zy_score_noisyZexpected_dcg_scorer?   r?   r@   test_ndcg_toy_examplesh  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)rz   r{   r|   r   )r  r?   r?   r@   test_ndcg_error_single_document  s
   "r  c                  C   rh  ri  )r   _test_ndcg_score_forr,   r0   r1   rk  rl  r?   r?   r@   test_ndcg_score  rn  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(   rq  )
r   r  rz   r   r,   r   rE   r   r   r+   )r>   r<   rt  rO   Zall_zeror?   r?   r@   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(   )r]   gMbP?gg?r   )r   r   r   g{Gz?r   rd   Trg   g-C6?r   )
r,   rt   r   rz   r{   r|   rA   Zlinspacer   re   )r>   r   Zroc_auc_with_max_fpr_oneZunconstrained_roc_aucr=   r`   r]   r?   r?   r@   test_partial_roc_auc_score  s0   

r  zy_true, k, true_scorer   r$   rp   r   c                 C   sF   t g dg dg dg dg}t| ||d}|t|ks!J d S )NrV  r   r   r   r   r   r   r   r   r   r   r   r   ro  r,   rt   r   rz   r   )r>   rp  
true_scorer<   rO   r?   r?   r@   test_top_k_accuracy_score  s   	r  zy_score, k, true_score)rB   rB   r(   r(   )rB   r(   rB   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(   rd   ro  )	minmaxZastyper,   Zint64r   r   rz   r   )r<   rp  r  r>   rX   r=   rO   Z	score_accr?   r?   r@    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   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.rV  r  r  r  r$   rp  r   N)r,   r   rt   r   rz   r   )r>   r  r   r  r<   rO   r?   r?   r@   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 )	Nr   r   r   )rM  r7   Zn_informativer'   )r'   c                    s    g | ]}t  |d qS )ro  )r   r3   )r   rp  r5   r;   r6   r?   r@   r   !  s    z8test_top_k_accuracy_score_increasing.<locals>.<listcomp>r$   )
r   Zmake_classificationr   r   r2   r   rM   r,   r  r   )ZX_trainZX_testZy_trainZy_testZscoresr?   r  r@   $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   rp   rp   r  ro  r  )r>   rp  r  r<   r?   r?   r@   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 )	NrV  )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   ro  r(   )r,   rt   rz   r   r   r   )r>   rp  r<   r   rO   r?   r?   r@   !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   rd   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'.)rd   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  )rz   r{   r|   r   )r>   r<   r   r   r?   r?   r@   test_top_k_accuracy_score_errorV  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   )rd   r~   r   r;  )r,   rt   r   rz   r   )rd  r>   r<   resultr?   r?   r@   Otest_label_ranking_avg_precision_score_should_allow_csr_matrix_for_y_true_input  s   
r  metricr   ))FT)r   r(   )r   rL   )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.
    *   r   rB   T)rs   replacer  N)	r,   r0   r1   choicer   
isinstancerF   r   any)r  r   r:   r7   rH   r>   Zy_probar  Zmetric_1Zmetric_2rl   r?   r?   r@   #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$   r   rr   N)r,   r0   r1   ru   r   r   isinf)r   r:   r>   r<   r`   rl   r?   r?   r@   (test_roc_curve_with_probablity_estimates  s
   
r  )NF)r   r   r   )r   r   numpyr,   rz   Zscipyr   Zsklearnr   r   Zsklearn.datasetsr   Zsklearn.exceptionsr   Zsklearn.linear_modelr   Zsklearn.metricsr   r	   r
   r   r   r   r   r   r   r   r   r   r   Zsklearn.metrics._rankingr   r   Zsklearn.model_selectionr   Zsklearn.preprocessingr   Zsklearn.random_projectionr   Zsklearn.utils._testingr   r   r   r   r   Zsklearn.utils.extmathr   Zsklearn.utils.fixesr    Zsklearn.utils.validationr!   r"   r#   ZCURVE_FUNCSrA   rK   rS   rY   re   markZparametrizern   rv   ry   r}   r   r   r   r   r   r   r   r   rt   r   r   r   r   r   r   r   r   r   r  filterwarningsr  r  r  r  r  r  r  r   r!  r"  r#  r,  r-  r/  r0  r1  r2  r7  r8  r>  rA  rB  rD  rH  rL  rP  rS  rT  rM   rU  rX  r_  r`  ra  rc  re  rf  rg  rm  rj  rw  ry  rz  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r?   r?   r?   r@   <module>   s.   <
0
r

	2


	"
"	


	G				
#
	

	


 $"	







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