U
    _»{jÞ  ã                -   @   s¼
  d dl mZ d dlmZ d dlmZmZmZ d dlZ	d dl
Z
d dlmZ d dlmZ d dlmZmZmZmZ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!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.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 d dl:m;Z; d dl<m=Z= d d	l>m?Z? d d
l@mAZAmBZBmCZCmDZDmEZE d dlFmGZG d dlHmIZImJZJ e'e(e-e+e/e)eee4dd�ee.d d�e,e*ee.dd�eedd�eedœZKeeeedd�eedd�edd„ e0ee0dd�e e9ee9dd�e"e3e5eeedd�eedd�e&eeddd�eedd�eeddd�ee3dd�ee5dd�ee"dd�eeddd�eedd�eeddd�ee3dd�ee5dd�ee"dd�eed dd�eed d�eed dd�ee3d d�ee5d d�ee"d d�eed!dd�eed!d�eed!dd�ee3d!d�ee5d!d�ee"d!d�ed"œ+ZLd#d$„ ZMe7eMed%œZNee$e%ee%dd�e!ee6ee6dd�ee6d!d�ee6dd�ee6d d&d'�ee6dd&d'�ee6d d(d'�ee6dd(d'�ee6dd)�eeedd�eed!d�eedd�e#e1ee8d*œZOePƒ ZQeQ ReO¡ eQ ReL¡ eQ ReK¡ eQ ReN¡ d+d,d-d.d/d0d1d2d3d4d5d6hZSd7d8d9d:d;d<d=d>d?d@dAdBdCdDdEhZTeS UeT¡ZVd>d?d@dAdBd=hZWd;dFd:hZXdCdDdEd7d>d?d@dAdBd=dFdGdHdIhZYdJdKdCdDdEd>d?d@dAdBd=dLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d2d_h ZZd`dadbhZ[dcddd;d<d9d8d:dFdGdIdHd1d3d6d5d4hZ\d`dedfdbdgdLdMdNdOdPdQdXdYdZd[d\d]dRdSdTdUdVdWd^d+d,d-d.d/d0hZ]dhdidjdkdldmdndodph	Z^d`dedfdbdgdWd]d=d0d@dSdYdPdRdSdTdUdVdqdhdjdidrdnd_dshZ_dtdudldkdJdKdCdDdEd>d?dAdBdLdMdNdOdQd^dXdZd[d\dvdwdxdydzdodpdmhZ`didrd{d|hZadxdwdydzhZbd}d~„ Zcdd€„ Zde
je fd�ege_ƒ¡d‚dƒ„ ƒZhe
je fd�ege`ƒ¡d„d…„ ƒZie
je fd�egejeQƒeV ƒ¡d†d‡„ ƒZkeEdˆd‰„ ƒZle
je fd�egejeQƒeV ƒ¡dŠd‹„ ƒZme
je fd�egejeLƒeV ƒ¡dŒd�„ ƒZne
je fd�eO¡dŽd�„ ƒZod d�ge	jpe	jpgfd d�ge	jqe	jqgfd d�ge	jqe	jpgfd d�ge	jpd�gfd d�ge	jqd�gfgZre
je fd‘eeO s¡ eK s¡ ƒ¡e
je fd’er¡d“d”„ ƒƒZte
je fd‘eL s¡ ¡e
je fd’ere	jqd�dgd�dd•gfe	jpd�dgd�dd•gfg ¡d–d—„ ƒƒZue
je fd‘eL s¡ ¡d˜d™„ ƒZveEdšd›„ ƒZweEdœd�„ ƒZxe
je fd�egejeQƒeV ejeOƒ ƒ¡dždŸ„ ƒZye
je fd�ege^e]B ƒ¡d d¡„ ƒZze
je fd�ege^ƒ¡d¢d£„ ƒZ{e
je fd�ege^ƒ¡d¤d¥„ ƒZ|eEd¦d§„ ƒZ}e
je fd�ege]ƒ¡d¨d©„ ƒZ~e
je fd�ege[ƒ¡dªd«„ ƒZe
je fd�ege[ƒ¡d¬d­„ ƒZ€e
je fd�ege[ �e]¡ƒ¡d®d¯„ ƒZ‚eEd°d±„ ƒZƒd²d³„ Z„e
je fd�egeWƒ¡d´dµ„ ƒZ…e
je fd�egeWeXB ƒ¡d¶d·„ ƒZ†e
je fd�egeWƒ¡d¸d¹„ ƒZ‡dºd»„ Zˆe
je fd�egeWƒ¡d¼d½„ ƒZ‰eEd¾d¿„ ƒZŠe
je fd�egejeQƒ �ejeKƒ¡ea ƒ¡dÀdÁ„ ƒZ‹e
je fd�egejeQƒejeKƒ ea eS ƒ¡dÂdÃ„ ƒZŒe
je fd�egejeQƒejeKƒ ea eV ƒ¡dÄdÅ„ ƒZ�e
je fd�ege]e\B e^B ea ƒ¡dÆdÇ„ ƒZŽeEdÈdÉ„ ƒZ�e
je fd�ege]d^h ƒ¡dÊdË„ ƒZ�e
je fd�ege\e^B ƒ¡dÌdÍ„ ƒZ‘e
je fd�egejeOƒeV ƒ¡dÎdÏ„ ƒZ’e
je fdÐeL¡dÑdÒ„ ƒZ“e
je fdÓedfedfedfeed�d�dfe"dfe2dfe3dfe5dfe7dfg	¡e
je fdÔe”e•g¡dÕdÖ„ ƒƒZ–dS )×é    )Úpartial)Ú	signature)ÚchainÚpermutationsÚproductN)Úmake_multilabel_classification))Úaccuracy_scoreÚaverage_precision_scoreÚbalanced_accuracy_scoreÚbrier_score_lossÚcohen_kappa_scoreÚconfusion_matrixÚcoverage_errorÚd2_absolute_error_scoreÚd2_pinball_scoreÚd2_tweedie_scoreÚ	dcg_scoreÚ	det_curveÚexplained_variance_scoreÚf1_scoreÚfbeta_scoreÚhamming_lossÚ
hinge_lossÚjaccard_scoreÚ%label_ranking_average_precision_scoreÚlabel_ranking_lossÚlog_lossÚmatthews_corrcoefÚ	max_errorÚmean_absolute_errorÚmean_absolute_percentage_errorÚmean_gamma_devianceÚmean_pinball_lossÚmean_poisson_devianceÚmean_squared_errorÚmean_tweedie_devianceÚmedian_absolute_errorÚmultilabel_confusion_matrixÚ
ndcg_scoreÚprecision_recall_curveÚprecision_scoreÚr2_scoreÚrecall_scoreÚroc_auc_scoreÚ	roc_curveÚtop_k_accuracy_scoreÚzero_one_loss)Ú_average_binary_score)ÚLabelBinarizer)Úshuffle)Úassert_allcloseÚassert_almost_equalÚassert_array_equalÚassert_array_lessÚignore_warnings)Útype_of_target)Ú_num_samplesÚcheck_random_stateZvariance_weighted)Zmultioutput)Úpowergffffffö?)r   r   r$   r"   r&   r    r   r+   Úmean_normal_deviancer#   r!   Úmean_compound_poisson_deviancer   r   r   T)ÚadjustedF©Ú	normalizec                  O   s0   t | |Ž d¡t | |Žjdd�d d …tjf  S )NÚfloaté   ©Úaxis)r   ÚastypeÚsumÚnpZnewaxis)ÚargsÚkwargs© rK   ú`/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sklearn/metrics/tests/test_common.pyÚ<lambda>   s    ÿrM   )Z
samplewiseé   )Úbetag      à?Úweighted)ÚaveragerO   ©rQ   ÚmicroÚmacroÚsamples)+r   r
   Ú adjusted_balanced_accuracy_scoreÚunnormalized_accuracy_scoreÚunnormalized_confusion_matrixÚnormalized_confusion_matrixÚ(unnormalized_multilabel_confusion_matrixÚ/unnormalized_multilabel_confusion_matrix_sampler   r0   Úunnormalized_zero_one_lossr   r*   r,   r   Úf2_scoreú
f0.5_scoreÚmatthews_corrcoef_scoreúweighted_f0.5_scoreÚweighted_f1_scoreÚweighted_f2_scoreÚweighted_precision_scoreÚweighted_recall_scoreÚweighted_jaccard_scoreúmicro_f0.5_scoreÚmicro_f1_scoreÚmicro_f2_scoreÚmicro_precision_scoreÚmicro_recall_scoreÚmicro_jaccard_scoreúmacro_f0.5_scoreÚmacro_f1_scoreÚmacro_f2_scoreÚmacro_precision_scoreÚmacro_recall_scoreÚmacro_jaccard_scoreúsamples_f0.5_scoreÚsamples_f1_scoreÚsamples_f2_scoreÚsamples_precision_scoreÚsamples_recall_scoreÚsamples_jaccard_scorer   c               
   O   sN   t | |Ž\}}}t|ƒt|ƒ }t ||tj| tj¡d|fdtjgd�g¡S )a'  
    The dimensions of precision-recall pairs and the threshold array as
    returned by the precision_recall_curve do not match. See
    func:`sklearn.metrics.precision_recall_curve`

    This prevents implicit conversion of return value triple to an higher
    dimensional np.array of dtype('float64') (it will be of dtype('object)
    instead). This again is needed for assert_array_equal to work correctly.

    As a workaround we pad the threshold array with NaN values to match
    the dimension of precision and recall arrays respectively.
    r   Zconstant)Z	pad_widthÚmodeZconstant_values)r)   ÚlenrH   ÚarrayÚpadrF   Zfloat64Únan)rI   rJ   Ú	precisionZrecallZ
thresholdsZpad_threshholdsrK   rK   rL   Ú(precision_recall_curve_padded_thresholds®   s    
üýÿr~   )r.   r)   r   Zovr)rQ   Zmulti_classZovo)Zmax_fpr)r   r   r   Úunnormalized_log_lossr   r   r-   Úweighted_roc_aucÚsamples_roc_aucÚmicro_roc_aucZovr_roc_aucZweighted_ovr_roc_aucÚovo_roc_aucÚweighted_ovo_roc_aucÚpartial_roc_aucr	   Ú weighted_average_precision_scoreÚsamples_average_precision_scoreÚmicro_average_precision_scorer   r(   r   r/   rr   rs   rt   ru   rv   rw   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   rY   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rZ   r   r   r/   r0   r   r   rW   r   r\   r   r&   r$   r+   r   r    r"   r   r   r_   r   r=   r
   rV   r   r!   r#   r>   r   rƒ   r„   c                 C   s2   t t|  ¡ | ¡ ƒƒd }| |7 } ||7 }| |fS )zMake targets strictly positiverC   )ÚabsÚmin)Úy1Úy2ÚoffsetrK   rK   rL   Ú_require_positive_targets  s    rŽ   c                   C   s6   t tB ttƒB tB ttƒks t‚t t@ tƒ ks2t‚d S ©N)ÚSYMMETRIC_METRICSÚNOT_SYMMETRIC_METRICSÚsetÚTHRESHOLDED_METRICSÚ"METRIC_UNDEFINED_BINARY_MULTICLASSÚALL_METRICSÚAssertionErrorrK   rK   rK   rL   Útest_symmetry_consistency  s    ÿþýûr—   Únamec                 C   sÆ   t dƒ}|jdddd�}|jdddd�}| tkr>t||ƒ\}}|jdddd�}|jdddd�}t|  }| tkr¤| tkr–t|||ƒ|||ƒd|  d� qÂdsÂtd	ƒ‚nt|||ƒ|||ƒd|  d� d S )
Nr   rN   ©é   ©Úsize©rš   é   z%s is not symmetric©Úerr_msgFz This case is currently unhandled)	r;   ÚrandintÚMETRICS_REQUIRE_POSITIVE_YrŽ   r•   ÚMETRIC_UNDEFINED_BINARYÚMULTILABELS_METRICSr4   r–   )r˜   Úrandom_stateÚy_trueÚy_predZ
y_true_binZ
y_pred_binÚmetricrK   rK   rL   Útest_symmetric_metric+  s*    ýýr©   c              	   C   s‚   t dƒ}|jdddd�}|jdddd�}| tkr>t||ƒ\}}t|  }t t¡�( t|||ƒ|||ƒƒ t	d|  ƒ‚W 5 Q R X d S )Nr   rN   r™   r›   z%s seems to be symmetric)
r;   r¡   r¢   rŽ   r•   ÚpytestÚraisesr–   r6   Ú
ValueError)r˜   r¥   r¦   r§   r¨   rK   rK   rL   Útest_not_symmetric_metricJ  s    r­   c              	   C   sŒ   t dƒ}|jdddd�}|jdddd�}| tkr>t||ƒ\}}t||dd�\}}tƒ �, t|  }t|||ƒ|||ƒd|  d� W 5 Q R X d S )Nr   rN   r™   r›   ©r¥   ú %s is not sample order invariantrŸ   )r;   r¡   r¢   rŽ   r3   r8   r•   r4   )r˜   r¥   r¦   r§   Úy_true_shuffleÚy_pred_shuffler¨   rK   rK   rL   Útest_sample_order_invariance\  s    ýr²   c            	      C   sþ   t dƒ} | jdddd�}| jdddd�}| j|jd�}t|||dd�\}}}tD ]*}t| }t|||ƒ|||ƒd| d� qPtD ]*}t| }t|||ƒ|||ƒd| d� q€t	D ]H}t| }t|||ƒ|||ƒd| d� t|||ƒ|||ƒd| d� q°d S )Nr   rN   r�   r›   r®   r¯   rŸ   )
r;   r¡   ÚnormalÚshaper3   r¤   r•   r4   ÚTHRESHOLDED_MULTILABEL_METRICSÚMULTIOUTPUT_METRICS)	r¥   r¦   r§   Úy_scorer°   r±   Zy_score_shuffler˜   r¨   rK   rK   rL   Ú7test_sample_order_invariance_multilabel_and_multioutputr  sH       ÿýýýýr¸   c              
   C   s   t dƒ}|jdddd�}|jdddd�}| tkr>t||ƒ\}}t|ƒ}t|ƒ}t |¡t |¡ }}t|jdƒ t|jdƒ t 	|d¡}t 	|d¡}	t 	|d¡}
t 	|d¡}t
ƒ ��â t|  }|||ƒ}t|||ƒ|d|  d	� t|||ƒ|d
|  d	� t|||	ƒ|d|  d	� t|||ƒ|d|  d	� t|||ƒ|d|  d	� t|||	ƒ|d|  d	� t|||ƒ|d|  d	� t|||	ƒ|d|  d	� t|||ƒ|d|  d	� t t¡� |||ƒ W 5 Q R X t t¡� ||
|ƒ W 5 Q R X t t¡� |||ƒ W 5 Q R X t t¡� ||
|ƒ W 5 Q R X t t¡� |||ƒ W 5 Q R X t t¡� ||
|	ƒ W 5 Q R X | ttB tB k�r’t t¡� ||
|ƒ W 5 Q R X W 5 Q R X d S )Nr   rN   r™   r›   rC   )éÿÿÿÿrC   )rC   r¹   z,%s is not representation invariant with listrŸ   z3%s is not representation invariant with np-array-1dz7%s is not representation invariant with np-array-columnz@%s is not representation invariant with mix np-array-1d and listzK%s is not representation invariant with mix np-array-1d and np-array-columnzD%s is not representation invariant with mix list and np-array-column)r;   r¡   r¢   rŽ   ÚlistrH   rz   r6   ÚndimÚreshaper8   r•   r4   rª   r«   r¬   r¶   rµ   r¤   )r˜   r¥   r‹   rŒ   Zy1_listZy2_listZy1_1dZy2_1dZ	y1_columnZ	y2_columnZy1_rowZy2_rowr¨   ÚmeasurerK   rK   rL   Ú&test_format_invariance_with_1d_vectors�  s¶    

ýýýÿýÿýüý
üý
ýý	ýý

ÿr¾   c              	   C   s>  t dƒ}|jdddd�}|jdddd�}t ddg¡| }t ddg¡| }d}ddg}tƒ �Ö t|  }|||ƒ}	|}
| tkrŠt|
|d�}
|
||ƒ}t|	|d 	| ¡d	� |
| 
d
¡| 
d
¡ƒ}t|	|d 	| ¡d	� | tk�r0t|
|d�}
|
||ƒ}t|	|d 	| ¡d	� |
| 
d
¡| 
d
¡ƒ}t|	|d 	| ¡d	� W 5 Q R X d S )Nr   rN   r™   r›   ÚeggsÚspam©Ú	pos_labelú+{0} failed string vs number invariance testrŸ   ÚOú2{0} failed string object vs number invariance test)Úlabelsz,{0} failed string vs number  invariance test)r;   r¡   rH   rz   r8   ÚCLASSIFICATION_METRICSÚMETRICS_WITH_POS_LABELr   r6   ÚformatrF   ÚMETRICS_WITH_LABELS)r˜   r¥   r‹   rŒ   Úy1_strZy2_strÚpos_label_strZ
labels_strr¨   Úmeasure_with_numberÚ
metric_strÚmeasure_with_strÚmeasure_with_strobjrK   rK   rL   Ú7test_classification_invariance_string_vs_numbers_labels  sN    

ýý

ýýrÑ   c              
   C   s  t dƒ}|jdddd�}|jdddd�}t ddg¡| }d}tƒ �Â t|  }| tkr¼|}| tkrnt||d�}|||ƒ}|||ƒ}	t	||	d 
| ¡d	� || d
¡|ƒ}
t	||
d 
| ¡d	� nFt t¡� |||ƒ W 5 Q R X t t¡� || d
¡|ƒ W 5 Q R X W 5 Q R X d S )Nr   rN   r™   r›   r¿   rÀ   rÁ   rÃ   rŸ   rÄ   rÅ   )r;   r¡   rH   rz   r8   r“   r£   rÈ   r   r6   rÉ   rF   rª   r«   r¬   )r˜   r¥   r‹   rŒ   rË   rÌ   r¨   rÎ   rÍ   rÏ   rÐ   rK   rK   rL   Ú4test_thresholded_invariance_string_vs_numbers_labelsN  s<    

ýÿý	rÒ   rC   r¨   zy_true, y_scorec              	   C   s<   | t kr|g}|g}tjtdd�� | ||ƒ W 5 Q R X d S )Nzcontains (NaN|infinity)©Úmatch)r   rª   r«   r¬   )r¨   r¦   r·   rK   rK   rL   Ú)test_regression_thresholded_inf_nan_input‚  s
    rÕ   é   c              	   C   s€   t  |¡ ¡ s,d}t  |¡ ¡ r&d}qHd}nd}t  |¡ ¡ rDd}nd}d|› d|› �}tjt|d�� | ||ƒ W 5 Q R X dS )	z{check that classification metrics raise a message mentioning the
    occurrence of non-finite values in the target vectors.r¦   ÚNaNzinfinity or a value too larger§   zInput z
 contains rÓ   N)rH   ÚisfiniteÚallÚisnanÚanyrª   r«   r¬   )r¨   r¦   r·   Z
input_nameZunexpected_valuer    rK   rK   rL   Ú!test_classification_inf_nan_input�  s    rÜ   c              	   C   sB   dddgdddg }}d}t jt|d�� | ||ƒ W 5 Q R X dS )	zocheck that classification metrics raise a message of mixed type data
    with continuous/binary target vectors.ÚaÚbgš™™™™™¹?gš™™™™™É?ç333333Ó?zJClassification metrics can't handle a mix of binary and continuous targetsrÓ   N)rª   r«   r¬   )r¨   r¦   r·   r    rK   rK   rL   Ú+test_classification_binary_continuous_input±  s
    ÿrà   c                 C   sJ   t |  }| tkrddg}nddg}t|dd�D ]\}}||g|gƒ q.d S )NrC   rN   r   ©Úrepeat)r•   r¢   r   )r˜   r¨   ÚvaluesÚiÚjrK   rK   rL   Úcheck_single_sample½  s    
ræ   c                 C   sL   t |  }tddgdd�D ].\}}}}|t ||gg¡t ||gg¡ƒ qd S )Nr   rC   é   rá   )r•   r   rH   rz   )r˜   r¨   rä   rå   ÚkÚlrK   rK   rL   Úcheck_single_sample_multioutputÎ  s    rê   c                 C   s   t | ƒ d S r�   )ræ   ©r˜   rK   rK   rL   Útest_single_sampleÕ  s    rì   c                 C   s   t | ƒ d S r�   )rê   rë   rK   rK   rL   Útest_single_sample_multioutputã  s    rí   c              	   C   sp   t  ddddgddddgddddgg¡}t  ddgddgddgg¡}t|  }t t¡� |||ƒ W 5 Q R X d S )NrC   r   ©rH   rz   r•   rª   r«   r¬   )r˜   r¦   r§   r¨   rK   rK   rL   Ú(test_multioutput_number_of_output_differè  s
    (rï   c                 C   sŒ   t dƒ}|jdddd�}|jdddd�}t|  }|||ƒ}tdƒD ]D}| |jd ¡}t||d d …|f |d d …|f ƒ|d|  d� qBd S )	Nr   rN   )rš   é   r›   rÖ   rC   z'%s is not dimension shuffling invariantrŸ   )r;   Úuniformr•   ÚrangeZpermutationr´   r4   )r˜   r¥   r¦   r§   r¨   ÚerrorÚ_ÚpermrK   rK   rL   Ú=test_multioutput_regression_invariance_to_dimension_shufflingò  s    
 ýrö   c                  C   s  d} d}t d| d|dd�\}}t d| d|dd�\}}t |dg|  gg¡}t |dg|  gg¡}t |¡}t |¡}t|ƒ}t|ƒ}dd„ |D ƒ}	d	d„ |D ƒ}
tD ]t}t| }t|t	ƒrÆd
|_
||_|||ƒ}t|||ƒ|d| d� t||	|
ƒ|d| d� t|||ƒ|d| d� q¤d S )Nrç   é2   rC   r   T©Ú
n_featuresÚ	n_classesr¥   Ú	n_samplesÚallow_unlabeledc                 S   s   g | ]}t |ƒ‘qS rK   ©rº   ©Ú.0rÝ   rK   rK   rL   Ú
<listcomp>$  s     z=test_multilabel_representation_invariance.<locals>.<listcomp>c                 S   s   g | ]}t |ƒ‘qS rK   rý   rþ   rK   rK   rL   r   %  s     ÚtmpzO%s failed representation invariance between dense and sparse indicator formats.rŸ   z\%s failed representation invariance  between dense array and list of list indicator formats.zW%s failed representation invariance  between dense and list of array indicator formats.)r   rH   ÚvstackÚspZ
coo_matrixrº   r¤   r•   Ú
isinstancer   Ú
__module__Ú__name__r4   r5   )rú   rû   rô   r‹   rŒ   Zy1_sparse_indicatorZy2_sparse_indicatorZy1_list_array_indicatorZy2_list_array_indicatorZy1_list_list_indicatorZy2_list_list_indicatorr˜   r¨   r½   rK   rK   rL   Ú)test_multilabel_representation_invariance  sf    û
û
	



üý	ûý
ûýr  c              
   C   sn   dgdgddggdddgg gdgt jg ddggdd�g}t|  }|D ]$}t t¡� |||ƒ W 5 Q R X qDd S )NrC   rN   r   rK   )r   rC   Úobject©Údtyperî   )r˜   Zmultilabel_sequencesr¨   ÚseqrK   rK   rL   Ú+test_raise_value_error_multilabel_sequencesQ  s    ûr  c                 C   s¤   d}d}t dƒ}|jd||fd�}|jd||fd�}|j|jd�}t|  }| tkrV|n|}|||dd�}	|||dd�}
td|	 dd	d
� t|	|
| d| › �d
� d S )NrN   rš   r   r›   Tr@   Fç      ð¿ú0We failed to test correctly the normalize optionrŸ   úFailed with )r;   r¡   r³   r´   r•   r“   r7   r4   ©r˜   rú   rû   r¥   r¦   r§   r·   ÚmetricsÚpredÚmeasure_normalizedÚmeasure_not_normalizedrK   rK   rL   Ú+test_normalize_option_binary_classificationb  s(    ýýr  c                 C   s¦   d}d}t dƒ}|jd||fd�}|jd||fd�}|j||fd�}t|  }| tkrX|n|}|||dd�}	|||dd�}
td|	 dd	d
� t|	|
| d| › �d
� d S )Nrç   rš   r   r›   Tr@   Fr  r  rŸ   r  )r;   r¡   rñ   r•   r“   r7   r4   r  rK   rK   rL   Ú/test_normalize_option_multiclass_classification  s(    ýýr  c                 C   sÈ   d}d}t dƒ}td|dd|d�\}}td|dd|d�\}}|j|jd�}|dg| 7 }|dg| 7 }t|  }| tkrz|n|}	|||	dd�}
|||	d	d�}td
|
 ddd� t|
|| d| › �d� d S )Nrç   éd   r   rC   T)rù   rú   r¥   rü   rû   r›   r@   Fr  r  rŸ   r  )r;   r   rñ   r´   r•   r“   r7   r4   )r˜   rú   rû   r¥   rô   r¦   r§   r·   r  r  r  r  rK   rK   rL   Ú/test_normalize_option_multilabel_classificationœ  sD    û
û
ýýr  c              	      s\  ˆj \}}ˆ ||d d�}t|‡ ‡‡fdd„t|ƒD ƒƒ ˆ ||dd�}	t|	ˆ ˆ ¡ ˆ ¡ ƒƒ ˆ ||dd�}
t|
t |¡ƒ tjˆdtd�}t |¡dkr¾ˆ ||dd�}t|tj||d	�ƒ nˆ ||dd�}t|dƒ |�rˆ ||d
d�}t|t ‡ ‡‡fdd„t|ƒD ƒ¡ƒ t	 
t¡� ˆ ||dd� W 5 Q R X t	 
t¡� ˆ ||dd� W 5 Q R X d S )NrR   c                    s.   g | ]&}ˆ ˆd d …|f ˆd d …|f ƒ‘qS r�   rK   ©rÿ   rä   ©r¨   Úy_pred_binarizeÚy_true_binarizerK   rL   r   Ø  s   ÿz$_check_averaging.<locals>.<listcomp>rS   rT   r   )rE   r
  rP   )ÚweightsrU   c                    s   g | ]}ˆ ˆ| ˆ| ƒ‘qS rK   rK   r  r  rK   rL   r   ø  s   ÿÚunknownÚgarbage)r´   r4   rò   ZravelrH   ZmeanrG   ÚintrQ   rª   r«   r¬   )r¨   r¦   r§   r  r  Úis_multilabelrû   rú   Zlabel_measureZmicro_measureZmacro_measurer  Zweighted_measureZsample_measurerK   r  rL   Ú_check_averagingÎ  sF    
þþ	 ÿ
þÿþ
r"  c                 C   sZ   t |ƒ d¡}t|  }| tkr2t||||||ƒ n$| tkrNt||||||ƒ ntdƒ‚d S )NZ
multilabelz2Metric is not recorded as having an average option)r9   Ú
startswithr•   ÚMETRICS_WITH_AVERAGINGr"  Ú"THRESHOLDED_METRICS_WITH_AVERAGINGr¬   )r˜   r¦   r  r§   r  r·   r!  r¨   rK   rK   rL   Úcheck_averaging  s*         ÿ     ÿr&  c           
      C   sz   d\}}t dƒ}|jd||fd�}|jd||fd�}|j||fd�}tƒ  |¡}| |¡}| |¡}	t| ||||	|ƒ d S )N)r÷   rÖ   r   r›   )r;   r¡   rñ   r2   ÚfitZ	transformr&  )
r˜   rû   rú   r¥   r¦   r§   r·   Zlbr  r  rK   rK   rL   Útest_averaging_multiclass  s    

r(  c           
      C   sh   d\}}t d|d|dd�\}}|d d… }|dd … }tdƒjd|fd�}|}|}	t| ||||	|ƒ d S )	N)é(   rð   rC   rð   Frø   rš   r   r›   )r   r;   r³   r&  )
r˜   rû   rú   rô   Úyr¦   r§   r·   r  r  rK   rK   rL   Útest_averaging_multilabel%  s    û
r+  c                 C   s<   t  d¡}t  d¡}t  d¡}|}|}t| |||||ƒ d S ©N©rš   rÖ   )rH   Úzerosr&  ©r˜   r¦   r§   r·   r  r  rK   rK   rL   Ú$test_averaging_multilabel_all_zeroes:  s    


r0  c                  C   s>   t  d¡} t  d¡}| }|}ddd„}t|| |||dd� d S )Nr-  rT   c                 S   s   t t| ||ƒS r�   )r1   r*   )r¦   r·   rQ   rK   rK   rL   rM   K  s
      ÿz=test_averaging_binary_multilabel_all_zeroes.<locals>.<lambda>T)r!  )rT   )rH   r.  r"  )r¦   r§   r  r  Zbinary_metricrK   rK   rL   Ú+test_averaging_binary_multilabel_all_zeroesE  s    


úr1  c                 C   s<   t  d¡}t  d¡}t  d¡}|}|}t| |||||ƒ d S r,  )rH   Úonesr&  r/  rK   rK   rL   Ú"test_averaging_multilabel_all_onesX  s    


r3  c              	   C   s  t j d¡}|jddt|ƒd�}| dkr4t|dd�n|}|||d d�}t||||t jt|ƒd�d�d	|  d
� ||||d�}t 	t
¡�" t||ƒ td||| f ƒ‚W 5 Q R X |||| ¡ d�}t||d||| f d
� |t j||dd�t j||dd�d d�}	t||	d|  d
� |dd d… }
t  |¡}d|d d d…< |dd d… }|dd d… }||||
d�}||||d�}t||d||| f d
� |  d¡�s¾dD ]&}t|||||| d�d|  d
� �q–d t|ƒt|ƒt|ƒd ¡}tj	t|d�� |||t  ||g¡d� W 5 Q R X d S )Nr   rC   é
   r›   r/   )rè   )Úsample_weight)r´   zAFor %s sample_weight=None is not equivalent to sample_weight=onesrŸ   zQUnweighted and weighted scores are unexpectedly almost equal (%s) and (%s) for %szVWeighted scores for array and list sample_weight input are not equal (%s != %s) for %srD   z.Weighting %s is not equal to repeating samplesrN   zeZeroing weights does not give the same result as removing the corresponding samples (%s != %s) for %sZunnormalized)rN   rß   z/%s sample_weight is not invariant under scalingzJFound input variables with inconsistent numbers of samples: \[{}, {}, {}\]rÓ   )rH   ÚrandomÚRandomStater¡   ry   r   r4   r2  rª   r«   r–   r¬   Útolistrâ   Úcopyr#  rÉ   r:   Zhstack)r˜   r¨   r‹   rŒ   Úrngr5  Zunweighted_scoreZweighted_scoreZweighted_score_listZrepeat_weighted_scoreZsample_weight_subsetZsample_weight_zeroedZ	y1_subsetZ	y2_subsetZweighted_score_subsetZweighted_score_zeroedZscalingÚerror_messagerK   rK   rL   Úcheck_sample_weight_invariancec  sŒ    ÿý
þÿüýýý
  ÿüý
ý
	  
þÿr<  c                 C   sB   d}t dƒ}|j|fd�}|j|fd�}t|  }t| |||ƒ d S )Nr÷   r   r›   )r;   Úrandom_sampler•   r<  )r˜   rû   r¥   r¦   r§   r¨   rK   rK   rL   Ú(test_regression_sample_weight_invarianceÅ  s    r>  c                 C   sp   d}t dƒ}|jdd|fd�}|jdd|fd�}|j|fd�}t|  }| tkr^t| |||ƒ nt| |||ƒ d S )Nr÷   r   rN   r›   )r;   r¡   r=  r•   r“   r<  )r˜   rû   r¥   r¦   r§   r·   r¨   rK   rK   rL   Ú$test_binary_sample_weight_invarianceÖ  s    r?  c           	      C   s–   d}t dƒ}|jdd|fd�}|jdd|fd�}|j|dfd�}t|  }| tkr„t | ¡}||jdd� dd¡ }t	| |||ƒ nt	| |||ƒ d S )Nr÷   r   rð   r›   r¹   rD   rC   )
r;   r¡   r=  r•   r“   rH   ÚexprG   r¼   r<  )	r˜   rû   r¥   r¦   r§   r·   r¨   ÚtempZy_score_normrK   rK   rL   Ú(test_multiclass_sample_weight_invarianceí  s    rB  c           	      C   s”   t dƒ}tdddddd�\}}tdddddd�\}}t ||g¡}t ||g¡}|jdd|jd�}t|  }| tkr‚t| |||ƒ nt| |||ƒ d S )	Nr   rC   r4  r÷   Frø   rç   r›   )	r;   r   rH   r  r¡   r´   r•   r“   r<  )	r˜   r¥   rô   ZyaZybr¦   r§   r·   r¨   rK   rK   rL   Ú(test_multilabel_sample_weight_invariance  s,    	    ÿ
    ÿ
rC  c                  C   sð   t  ddddgddddgg¡} t  ddddgddddgg¡}t  dddg¡}t  dddg¡}t  ddddg¡}t j|dd�\}}tD ]f}||g| |gfD ]P\}}	|tkr´|	jdkr´q˜t| }
|
||	|d d�}|
||	d d�}t||| ƒ q˜q„d S )	NrC   r   rN   rÖ   T)Zreturn_inverse)rÆ   rQ   rR   )rH   rz   Úuniquer$  r¤   r»   r•   r6   )Zy_true_multilabelZy_pred_multilabelZy_true_multiclassZy_pred_multiclassrÆ   rô   Zinverse_labelsr˜   r¦   r§   r¨   Zscore_labelsÚscorerK   rK   rL   Útest_no_averaging_labels"  s     þrF  c                 C   s–   t dƒ}d\}}|jdd||fd�}|jdd||fd�}t|  }|||ƒ}tt|ƒ|ƒD ]8}|d d …|f }	|d d …|f }
||
|	ƒ}t||ƒ qXd S )Nr   ©rš   rç   rN   r›   )r;   r¡   r•   r   rò   r5   ©r˜   r¥   rû   rú   r¦   r·   r¨   rE  rõ   Úy_score_permÚy_true_permÚcurrent_scorerK   rK   rL   Ú-test_multilabel_label_permutations_invariance<  s    

rL  c                 C   sà   t dƒ}d\}}|jdd||fd�}|j|jd�}d|| d¡dkdf< d|| d¡dkdf< t|  }|||ƒ}tt|ƒ|ƒD ]\}|d d …|f }	|d d …|f }
||
|	ƒ}|tkrÐt	 
|¡sÂt‚|dksÚt‚q~t||ƒ q~d S )Nr   rG  rN   r›   rC   rç   g    €„.A)r;   r¡   r³   r´   rG   r•   r   rò   r    rH   rØ   r–   r5   rH  rK   rK   rL   Ú?test_thresholded_multilabel_multioutput_permutations_invarianceQ  s     

rM  c                 C   sÊ   d\}}t dƒ}| ||¡}t | ¡}||jdd� dd¡ }|jd||d�}t|  }|||ƒ}tt	|ƒ|ƒD ]T}	tj
|td�}
t |¡|
t|	ƒ< |d d …|
f }t |	|¡}|||ƒ}t||ƒ qpd S )N)r  rÖ   r   r¹   rD   rC   r›   r	  )r;   ZrandrH   r@  rG   r¼   r¡   r•   r   rò   r.  r   Zarangerº   Ztaker5   )r˜   rû   rú   r¥   r·   rA  r¦   r¨   rE  rõ   Zinverse_permrI  rJ  rK  rK   rK   rL   Ú.test_thresholded_metric_permutation_invariancer  s    

rN  Úmetric_namec              	   C   sl   t j d¡}t jdgd dgd  td�}|jdd|jd�}d	}tjt	|d
�� t
|  ||ƒ W 5 Q R X d S )Né*   rÀ   rÖ   r¿   rN   r	  r   r›   z7Labels in y_true and y_pred should be of the same type.rÓ   )rH   r6  r7  rz   r  r¡   rœ   rª   r«   Ú	TypeErrorrÇ   )rO  r:  r‹   rŒ   r    rK   rK   rL   Ú"test_metrics_consistent_type_errorŠ  s    rR  zmetric, y_pred_thresholdÚdtype_y_strc           
   	   C   s¦   t j d¡}t jdgd dgd  |d�}|jdd|jd�}|sVt jddg|d�| }d	}d
}t| ƒjd j}|dkrz|n|}	t	j
t|	d�� | ||ƒ W 5 Q R X d S )NrP  rÀ   rÖ   r¿   rN   r	  r   r›   z”y_true takes value in {'eggs', 'spam'} and pos_label is not specified: either make y_true take value in {0, 1} or {-1, 1} or pass pos_label explicitzHpos_label=1 is not a valid label. It should be one of \['eggs', 'spam'\]rÂ   rC   rÓ   )rH   r6  r7  rz   r¡   rœ   r   Ú
parametersÚdefaultrª   r«   r¬   )
r¨   Zy_pred_thresholdrS  r:  r‹   rŒ   Zerr_msg_pos_label_NoneZerr_msg_pos_label_1Zpos_label_defaultr    rK   rK   rL   Ú test_metrics_pos_label_error_str—  s    ÿÿrV  )—Ú	functoolsr   Úinspectr   Ú	itertoolsr   r   r   ÚnumpyrH   rª   Zscipy.sparseÚsparser  Zsklearn.datasetsr   Zsklearn.metricsr   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(   r)   r*   r+   r,   r-   r.   r/   r0   Zsklearn.metrics._baser1   Zsklearn.preprocessingr2   Zsklearn.utilsr3   Zsklearn.utils._testingr4   r5   r6   r7   r8   Zsklearn.utils.multiclassr9   Zsklearn.utils.validationr:   r;   ZREGRESSION_METRICSrÇ   r~   ZCURVE_METRICSr“   Údictr•   Úupdater£   ZMETRIC_UNDEFINED_MULTICLASSÚunionr”   r$  r%  rÈ   rÊ   ZMETRICS_WITH_NORMALIZE_OPTIONrµ   r¤   r¶   r�   r‘   ZMETRICS_WITHOUT_SAMPLE_WEIGHTr¢   rŽ   r—   ÚmarkZparametrizeÚsortedr©   r­   r’   r²   r¸   r¾   rÑ   rÒ   Úinfr|   Zinvalids_nan_infrã   rÕ   rÜ   rà   ræ   rê   rì   rí   rï   rö   r  r  r  r  Úintersectionr  r"  r&  r(  r+  r0  r1  r3  r<  r>  r?  rB  rC  rF  rL  rM  rN  rR  Ústrr  rV  rK   rK   rK   rL   Ú<module>   s  ¬+$



ñ

 ÿ


















Ë9 ý



  ÿ  ÿ
 ÿ ÿ
á"



ôïÿúýòà%ýðâ#÷ä"á%üü

 ÿ

* ÿ
v ÿ
5
+û	 ÿ	þüþ


ýüÿþ



	

K


 ÿ
/
6
 
ÿ





aÿÿþ

ÿþýÿþ	
ÿþýÿþ	

ÿÿþ

 ÿ
 
ÿ
 ÿ

÷þ