o
    tBhx                     @   s  d dl mZ d dlmZ d dlmZ d dlmZ d dlmZ d dlZ	d dl
mZ d dlZd dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm Z  d dlm!Z! d dlm"Z" d dlm#Z# d dlm$Z$ d dlm%Z% d dlm&Z& d dlm'Z' d dlm(Z( d dlm)Z) d dlm*Z* d dlm+Z+ d dlm,Z, d dlm-Z- d d lm.Z. d d!lm/Z/ d d"lm0Z0 d d#lm1Z1 d d$lm2Z2 d d%lm3Z3 d d&lm4Z4 d d'lm5Z5 d d(lm6Z6 d d)lm7Z7 d d*lm8Z8 d d+lm9Z9 d d,lm:Z: d d-lm;Z; d d.lm<Z< d d/lm=Z= d d0lm>Z> d d1lm?Z? d d2lm@Z@ d d3lmAZA d d4lmBZB d d5lmCZC d d6lmDZD d d7lmEZE d d8lmFZF d d9lmGZG d d:lmHZH d d;lImJZJ e4e6e8e>e<e7e+eeAd<d=ee9d d>e:e;ee9d?d>ee'd?d>e(e)d@ZKi dAe dBe"dCee"dDdEdFee dGdHdIe%dJdKdL dMe=dNee=dDdOdPe.dQeEdReeEdGdHdSe0dTe@dUeBdVe,dWee-dXdYdZee-d[dYi d\e5d]ee-d^d[d_d`ee,d^dadbee-d^dXd_dcee@d^daddeeBd^dadeee0d^dadfee-dgd[d_dhee,dgdadiee-dgdXd_djee@dgdadkeeBdgdadlee0dgdadmee-dnd[d_doee,dndadpee-dndXd_dqee@dndaeeBdndaee0dndaee-drd[d_ee,drdaee-drdXd_ee@drdaeeBdrdaee0drdae$ds	ZLdtdu ZMeDeMe*dvZNi dwe&dxe2dye3dzee3dGdHd{e/d|e#d}eCd~eeCd^dadeeCdrdadeeCdgdadeeCdndddeeCd^dddeeCdndddeeCd^dddeeCd[dde!dee!d^daee!drdaee!dgdae1eFeGeHdZOeP ZQeQReO eQReL eQReK eQReN h dZSh dZTeSUeTZVh dZWh dZXh dZYh dZZh dZ[h dZ\h dZ]h dZ^h dZ_h dZ`h dZah dZbdd Zcdd Zdejefdege_dd Zhejefdege`dd ZiejefdegejeQeV dd Zkedd ZlejefdegejeQeV dd ZmejefdegejeLeV dd ZnejefdeOdd Zod dge	jpe	jpgfd dge	jqe	jqgfd dge	jqe	jpgfd dge	jpdgfd dge	jqdgfgZrejefdeeOs eKs ejefderdd ZtejefdeLs ejefdere	jqddXgg dfe	jpddXgg dfg dd ZuejefdeLs dd Zvedd Zwedd ZxejefdegejeQeV ejeO dd Zyejefdege^e]B dd Zzejefdege^dd Z{ejefdege^ddÄ Z|eddń Z}ejefdege]ddǄ Z~ejefdege[ddɄ Zejefdege[dd˄ Zejefdege[e]dd̈́ Zeddτ Zddф ZejefdegeWddӄ ZejefdegeWeXB ddՄ ZejefdegeWddׄ Zddل ZejefdegeWddۄ Zedd݄ ZejefdegejeQejeKea dd߄ ZejefdegejeQejeK ea eS dd ZejefdegejeQejeK ea eV dd Zejefdege]e\B e^B ea dd Zedd Zejefdege]dMh dd Zejefdege\e^B dd ZejefdegejeOeV dd ZejefdeLdd Zejefde!dDfe#dDfe,dGfee-ddYdGfe0dGfe?dDfe@dGfeBdGfeDdDfg	ejefdeegdd ZdS )    )partial)	signature)product)chain)permutationsN)make_multilabel_classification)LabelBinarizer)type_of_target)_num_samples)check_random_state)shuffle)assert_allclose)assert_almost_equal)assert_array_equal)assert_array_less)ignore_warnings)accuracy_score)average_precision_score)balanced_accuracy_score)brier_score_loss)cohen_kappa_score)confusion_matrix)coverage_error)d2_tweedie_score)d2_pinball_score)d2_absolute_error_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)	max_error)matthews_corrcoef)mean_absolute_error)mean_absolute_percentage_error)mean_squared_error)mean_tweedie_deviance)mean_poisson_deviance)mean_gamma_deviance)median_absolute_error)multilabel_confusion_matrix)mean_pinball_loss)precision_recall_curve)precision_score)r2_score)recall_score)roc_auc_score)	roc_curve)zero_one_loss)
ndcg_score)	dcg_score)top_k_accuracy_score)_average_binary_scorevariance_weighted)multioutput)powergffffff?)r&   r(   r*   r0   r.   r)   r   r3   mean_normal_deviancer,   r-   mean_compound_poisson_deviancer   r   r   r   r    adjusted_balanced_accuracy_scoreT)adjustedunnormalized_accuracy_scoreF	normalizeunnormalized_confusion_matrixnormalized_confusion_matrixc                  O   s8   t | i |dt | i |jddd d tjf  S )Nfloat   axis)r   astypesumnpnewaxis)argskwargs rR   x/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/sklearn/metrics/tests/test_common.py<lambda>   s   "rT   (unnormalized_multilabel_confusion_matrix/unnormalized_multilabel_confusion_matrix_sample)
samplewiser    r7   unnormalized_zero_one_lossr"   r2   r4   r   f2_score   )beta
f0.5_scoreg      ?matthews_corrcoef_scoreweighted_f0.5_scoreweighted)averager[   weighted_f1_scorer`   weighted_f2_scoreweighted_precision_scoreweighted_recall_scoreweighted_jaccard_scoremicro_f0.5_scoremicromicro_f1_scoremicro_f2_scoremicro_precision_scoremicro_recall_scoremicro_jaccard_scoremacro_f0.5_scoremacromacro_f1_scoremacro_f2_scoremacro_precision_scoresamples)	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   sR   t | i |\}}}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   constant)	pad_widthmodeconstant_values)r1   lenrN   arraypadrL   float64nan)rP   rQ   	precisionrecall
thresholdspad_threshholdsrR   rR   rS   (precision_recall_curve_padded_thresholds   s   
r   )r6   r1   r   r   r$   r%   unnormalized_log_lossr!   r   r5   weighted_roc_aucsamples_roc_aucmicro_roc_aucovr_roc_aucovr)r`   multi_classweighted_ovr_roc_aucovo_roc_aucovoweighted_ovo_roc_aucpartial_roc_auc)max_fprr    weighted_average_precision_score)samples_average_precision_scoremicro_average_precision_scorer#   r8   r9   r:   >   r9   r8   r   rw   rx   r$   rz   r{   ry   r#   rV   rv   >   r   rY   r   r6   r4   r"   r   r5   r   r2   r   r   r   r1   r   r   r   r   r\   >   r   rY   r4   r"   r2   r\   >   r5   r   r   >   r   rY   r   r6   r4   r"   r2   r   r1   r   r   r   r   r\   >    r   rY   r   r6   r4   r"   rp   rq   ri   rj   r2   r   ra   rc   rt   rl   ru   rm   rr   rk   re   r1   rf   rd   rG   rF   rU   rV   r\   rn   rg   r^   >   r7   r   r:   >   r%   r9   r8   r   r5   r   r   r   r   r$   r   r   r   r   r   r#   >   r    r7   r   rp   rq   ri   rj   rw   rx   ra   rc   rt   rl   ru   rm   rz   rr   rk   r{   re   rf   ry   rd   rX   rC   rU   rn   rg   rv   r^   >	   r3   r   r0   r*   r(   r.   r   r   r)   >   r   r&   r    r"   r7   r   rp   ri   rj   r   r0   r*   rl   ru   r(   rm   r?   r.   rk   r{   re   r]   rX   rC   rg   >    rY   r%   r3   r   r6   r!   r4   rq   r2   r   r   ra   rc   rt   r-   rr   r,   r1   rf   r   r   r   rd   rG   rF   r)   r@   rA   rU   r\   rn   r^   >   r&   r   r   r.   >   r   r-   r,   r@   c                 C   s2   t t|  | d }| |7 } ||7 }| |fS )zMake targets strictly positiverI   )absmin)y1y2offsetrR   rR   rS   _require_positive_targets   s   r   c                   C   s6   t tB ttB tB ttksJ t t@ t ksJ d S N)SYMMETRIC_METRICSNOT_SYMMETRIC_METRICSsetTHRESHOLDED_METRICS"METRIC_UNDEFINED_BINARY_MULTICLASSALL_METRICSrR   rR   rR   rS   test_symmetry_consistency(  s   r   namec                 C   s   t d}|jdddd}|jdddd}| tv rt||\}}|jdddd}|jdddd}t|  }| tv rP| tv rLt||||||d|  d d S J d	t||||||d|  d d S )
Nr   rZ      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_METRICSr   )r   random_statey_truey_pred
y_true_bin
y_pred_binmetricrR   rR   rS   test_symmetric_metric5  s*   

r   c                 C   s   t d}|jdddd}|jdddd}| tv rt||\}}t|  }tt t|||||| t	d|  1 s=w   Y  d S )Nr   rZ   r   r   z%s seems to be symmetric)
r   r   r   r   r   pytestraisesAssertionErrorr   
ValueError)r   r   r   r   r   rR   rR   rS   test_not_symmetric_metricT  s   r   c                 C   s   t d}|jdddd}|jdddd}| tv rt||\}}t||dd\}}t  t|  }t||||||d|  d W d    d S 1 sJw   Y  d S )Nr   rZ   r   r   r    %s is not sample order invariantr   )r   r   r   r   r   r   r   r   )r   r   r   r   y_true_shuffley_pred_shuffler   rR   rR   rS   test_sample_order_invariancef  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 q(tD ]}t| }t||||||d| d q@t	D ]$}t| }t||||||d| d t||||||d| d qXd S )Nr   rZ   r   r   r   r   r   )
r   r   normalshaper   r   r   r   THRESHOLDED_MULTILABEL_METRICSMULTIOUTPUT_METRICS)	r   r   r   y_scorer   r   y_score_shuffler   r   rR   rR   rS   7test_sample_order_invariance_multilabel_and_multioutput|  sD   r   c              	   C   sn  t d}|jdddd}|jdddd}| tv rt||\}}t|}t|}t|t|}}t|jd t|jd t	|d}t	|d}	t	|d}
t	|d}t
 R 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 d    n1 sw   Y  tt ||
| W d    n1 sw   Y  tt ||| W d    n	1 sw   Y  tt ||
| W d    n	1 s5w   Y  tt ||| W d    n	1 sPw   Y  tt ||
|	 W d    n	1 skw   Y  | ttB tB vrtt ||
| W d    n1 sw   Y  W d    d S W d    d S W d    d S 1 sw   Y  d S )Nr   rZ   r   r   rI   )rI   )rI   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   listrN   r   r   ndimreshaper   r   r   r   r   r   r   r   r   )r   r   r   r   y1_listy2_listy1_1dy2_1d	y1_column	y2_columny1_rowy2_rowr   measurerR   rR   rS   &test_format_invariance_with_1d_vectors  s   



	

 \_$r   c                 C   sb  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 x t|  }|||}	|}
| tv rEt|
|d}
|
||}t|	|d	| d	 |
|
d
|
d
}t|	|d	| d	 | tv rt|
|d}
|
||}t|	|d	| d	 |
|
d
|
d
}t|	|d	| d	 W d    d S W d    d S 1 sw   Y  d S )Nr   rZ   r   r   eggsspam	pos_label+{0} failed string vs number invariance testr   O2{0} failed string object vs number invariance test)labelsz,{0} failed string vs number  invariance test)r   r   rN   r   r   CLASSIFICATION_METRICSMETRICS_WITH_POS_LABELr   r   formatrL   METRICS_WITH_LABELS)r   r   r   r   y1_stry2_strpos_label_str
labels_strr   measure_with_number
metric_strmeasure_with_strmeasure_with_strobjrR   rR   rS   7test_classification_invariance_string_vs_numbers_labels   sT   


"r   c              	   C   sn  t d}|jdddd}|jdddd}tddg| }d}t  t|  }| tvr^|}| tv r7t||d}|||}|||}	t	||	d
| d	 ||d
|}
t	||
d
| d	 n?tt ||| W d    n1 ssw   Y  tt ||d
| W d    n1 sw   Y  W d    d S W d    d S W d    d S 1 sw   Y  d S )Nr   rZ   r   r   r   r   r   r   r   r   r   )r   r   rN   r   r   r   r   r   r   r   r   rL   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   rR   rR   rS   4test_thresholded_invariance_string_vs_numbers_labelsX  sJ   

	"r   rI   r   zy_true, y_scorec                 C   s>   t jtdd | || W d    d S 1 sw   Y  d S )Nzcontains (NaN|infinity)matchr   r   r   )r   r   r   rR   rR   rS   )test_regression_thresholded_inf_nan_input  s   "r   )rI   rZ      c                 C   s   t | sd}t | rd}nd}nd}t | r"d}nd}d| d| }tjt|d | || W d   dS 1 sDw   Y  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)rN   isfiniteallisnananyr   r   r   )r   r   r   
input_nameunexpected_valuer   rR   rR   rS   !test_classification_inf_nan_input  s   "r   c                 C   sT   g dg d}}d}t jt|d | || W d   dS 1 s#w   Y  dS )zocheck that classification metrics raise a message of mixed type data
    with continuous/binary target vectors.)abr   )g?g?333333?zJClassification metrics can't handle a mix of binary and continuous targetsr   Nr   )r   r   r   r   rR   rR   rS   +test_classification_binary_continuous_input  s   "r  c                 C   sJ   t |  }| tv rddg}nddg}t|ddD ]\}}||g|g qd S )NrI   rZ   r   repeat)r   r   r   )r   r   valuesijrR   rR   rS   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   rI      r  )r   r   rN   r   )r   r   r  r  klrR   rR   rS   check_single_sample_multioutput  s   $r  c                 C      t |  d S r   )r  r   rR   rR   rS   test_single_sample  s   r  c                 C   r  r   )r  r  rR   rR   rS   test_single_sample_multioutput  s   r  c                 C   sz   t g dg dg dg}t ddgddgddgg}t|  }tt ||| W d    d S 1 s6w   Y  d S )N)rI   r   r   rI   )r   rI   rI   rI   )rI   rI   r   rI   r   rI   rN   r   r   r   r   r   )r   r   r   r   rR   rR   rS   (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 ]"}||jd }t||d d |f |d d |f |d|  d q!d S )	Nr   rZ   )r      r   r   rI   z'%s is not dimension shuffling invariantr   )r   uniformr   rangepermutationr   r   )r   r   r   r   r   error_permrR   rR   rS   =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	rcd
|_
||_|||}t||||d| d t||	|
|d| d t||||d| d qRd S )Nr  2   rI   r   T
n_features	n_classesr   	n_samplesallow_unlabeledc                 S      g | ]}t |qS rR   r   .0r   rR   rR   rS   
<listcomp>*      z=test_multilabel_representation_invariance.<locals>.<listcomp>c                 S   r   rR   r!  r"  rR   rR   rS   r$  +  r%  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   rN   vstacksp
coo_matrixr   r   r   
isinstancer   
__module____name__r   r   )r  r  r  r   r   y1_sparse_indicatory2_sparse_indicatory1_list_array_indicatory2_list_array_indicatory1_list_list_indicatory2_list_list_indicatorr   r   r   rR   rR   rS   )test_multilabel_representation_invariance  sh   

	



	
r3  c              	   C   s   dgdgddggg dg gdgt jg ddggddg}t|  }|D ]}tt ||| W d    n1 s8w   Y  q!d S )NrI   rZ   r   )rR   rZ   )r   rI   rR   objectdtyper  )r   multilabel_sequencesr   seqrR   rR   rS   +test_raise_value_error_multilabel_sequencesW  s   r9  c                 C   s   d}d}t d}|jd||fd}|jd||fd}|j|jd}t|  }| tv r+|n|}|||dd}	|||dd}
td|	 dd	d
 t|	|
| d|  d
 d S )NrZ   r   r   r   TrD   F      0We failed to test correctly the normalize optionr   Failed with )r   r   r   r   r   r   r   r   r   r  r  r   r   r   r   metricspredmeasure_normalizedmeasure_not_normalizedrR   rR   rS   +test_normalize_option_binary_classificationh  s(   
rB  c                 C   s   d}d}t d}|jd||fd}|jd||fd}|j||fd}t|  }| tv r,|n|}|||dd}	|||dd}
td|	 dd	d
 t|	|
| d|  d
 d S )Nr  r   r   r   TrD   Fr:  r;  r   r<  )r   r   r  r   r   r   r   r=  rR   rR   rS   /test_normalize_option_multiclass_classification  s(   
rC  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v r=|n|}	|||	dd}
|||	d	d}td
|
 ddd t|
|| d|  d d S )Nr  d   r   rI   T)r  r  r   r  r  r   rD   Fr:  r;  r   r<  )r   r   r  r   r   r   r   r   )r   r  r  r   r  r   r   r   r>  r?  r@  rA  rR   rR   rS   /test_normalize_option_multilabel_classification  sD   


rE  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 d    n1 sw   Y  t	
t  ||dd W d    d S 1 sw   Y  d S )Nrb   c                    s.   g | ]} d d |f d d |f qS r   rR   r#  r  r   y_pred_binarizey_true_binarizerR   rS   r$    s     z$_check_averaging.<locals>.<listcomp>rh   ro   r   )rK   r6  r_   )weightsrs   c                    s   g | ]} | | qS rR   rR   rF  rG  rR   rS   r$    s    unknowngarbage)r   r   r  ravelrN   meanrM   intr`   r   r   r   )r   r   r   rI  rH  is_multilabelr  r  label_measuremicro_measuremacro_measurerJ  weighted_measuresample_measurerR   rG  rS   _check_averaging  sH   
	

"rV  c                 C   sZ   t |d}t|  }| tv rt|||||| d S | tv r)t|||||| d S td)N
multilabelz2Metric is not recorded as having an average option)r	   
startswithr   METRICS_WITH_AVERAGINGrV  "THRESHOLDED_METRICS_WITH_AVERAGINGr   )r   r   rI  r   rH  r   rP  r   rR   rR   rS   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  r   fit	transformr[  )
r   r  r  r   r   r   r   lbrI  rH  rR   rR   rS   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  rI   r  Fr  r   r   r   )r   r   r   r[  )
r   r  r  r  yr   r   r   rI  rH  rR   rR   rS   test_averaging_multilabel+  s   
rb  c                 C   <   t d}t d}t d}|}|}t| ||||| d S Nr   r   )rN   zerosr[  r   r   r   r   rI  rH  rR   rR   rS   $test_averaging_multilabel_all_zeroes@     


rh  c                  C   s>   t d} t d}| }|}ddd}t|| |||dd d S )Nre  ro   c                 S   s   t t| ||S r   )r;   r2   )r   r   r`   rR   rR   rS   rT   Q  s    z=test_averaging_binary_multilabel_all_zeroes.<locals>.<lambda>T)rP  )ro   )rN   rf  rV  )r   r   rI  rH  binary_metricrR   rR   rS   +test_averaging_binary_multilabel_all_zeroesK  s   



rk  c                 C   rc  rd  )rN   onesr[  rg  rR   rR   rS   "test_averaging_multilabel_all_ones^  ri  rm  c                 C   s,  t jd}|jddt|d}| dkrt|ddn|}|||d d}t||||t jt|ddd	|  d
 ||||d}t	t
 t|| td||| f 1 sUw   Y  |||| 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sdD ]}t|||||| dd|  d
 qdt|t|t|d }tj	t|d |||t ||gd W d    d S 1 sw   Y  d S )Nr   rI   
   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 %srJ   z.Weighting %s is not equal to repeating samplesrZ   zeZeroing weights does not give the same result as removing the corresponding samples (%s != %s) for %sunnormalized)rZ   r   z/%s sample_weight is not invariant under scalingzJFound input variables with inconsistent numbers of samples: \[{}, {}, {}\]r   )rN   randomRandomStater   r   r   r   rl  r   r   r   r   tolistr  copyrX  r   r
   hstack)r   r   r   r   rngro  unweighted_scoreweighted_scoreweighted_score_listrepeat_weighted_scoresample_weight_subsetsample_weight_zeroed	y1_subset	y2_subsetweighted_score_subsetweighted_score_zeroedscalingerror_messagerR   rR   rS   check_sample_weight_invariancei  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   rR   rR   rS   (test_regression_sample_weight_invariance  s   r  c                 C   sr   d}t d}|jdd|fd}|jdd|fd}|j|fd}t|  }| tv r0t| ||| d S t| ||| d S )Nr  r   rZ   r   )r   r   r  r   r   r  )r   r  r   r   r   r   r   rR   rR   rS   $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v rCt| }||jdddd }t	| ||| d S t	| ||| d S )Nr  r   r  r   r   rJ   rI   )
r   r   r  r   r   rN   exprM   r   r  )	r   r  r   r   r   r   r   tempy_score_normrR   rR   rS   (test_multiclass_sample_weight_invariance  s   r  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v rBt| ||| d S t| ||| d S )	Nr   rI   rn  r  Fr  r  r   )	r   r   rN   r'  r   r   r   r   r  )	r   r   r  yaybr   r   r   r   rR   rR   rS   (test_multilabel_sample_weight_invariance  s   	



r  c                  C   s   t g dg dg} t g dg dg}t g d}t g d}t g d}t j|dd\}}tD ]3}||g| |gfD ](\}}	|tvrN|	jd	krNq@t| }
|
||	|d d
}|
||	d d}t|||  q@q6d S )N)rI   rI   r   r   )r   r   rI   rI   )r   rI   rI   r   )r   rI   rZ   )r   rZ   r   )r   r   rI   rZ   T)return_inverserI   )r   r`   rb   )rN   r   uniquerY  r   r   r   r   )y_true_multilabely_pred_multilabely_true_multiclassy_pred_multiclassr   r  inverse_labelsr   r   r   r   score_labelsscorerR   rR   rS   test_no_averaging_labels(  s$   r  c                 C   s   t d}d\}}|jdd||fd}|jdd||fd}t|  }|||}tt||D ]}|d d |f }	|d d |f }
||
|	}t|| q,d S )Nr   r   r  rZ   r   )r   r   r   r   r  r   r   r   r  r  r   r   r   r  r  y_score_permy_true_permcurrent_scorerR   rR   rS   -test_multilabel_label_permutations_invarianceB  s   

r  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rht	
|saJ |dksgJ q?t|| q?d S )Nr   r  rZ   r   rI   r  g    .A)r   r   r   r   rM   r   r   r  r)   rN   r   r   r  rR   rR   rS   ?test_thresholded_multilabel_multioutput_permutations_invarianceW  s"   

r  c                 C   s   d\}}t d}|||}t| }||jdddd }|jd||d}t|  }|||}tt	||D ]*}	tj
|td}
t||
t|	< |d d |
f }t|	|}|||}t|| q8d S )N)rD  r   r   r   rJ   rI   r   r5  )r   randrN   r  rM   r   r   r   r   r  rf  rO  aranger   taker   )r   r  r  r   r   r  r   r   r  r  inverse_permr  r  r  rR   rR   rS   .test_thresholded_metric_permutation_invariancex  s    

r  metric_namec                 C   s   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 d    d S 1 s:w   Y  d S )N*   r   r   r   rZ   r5  r   r   z7Labels in y_true and y_pred should be of the same type.r   )rN   rq  rr  r   r4  r   r   r   r   	TypeErrorr   )r  rv  r   r   r   rR   rR   rS   "test_metrics_consistent_type_error  s   "r  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}|s+t jddg|d| }d	}d
}t| jd j}|dkr=|n|}	t	j
t|	d | || W d    d S 1 sWw   Y  d S )Nr  r   r   r   rZ   r5  r   r   zy_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   rI   r   )rN   rq  rr  r   r   r   r   
parametersdefaultr   r   r   )
r   y_pred_thresholdr  rv  r   r   err_msg_pos_label_Noneerr_msg_pos_label_1pos_label_defaultr   rR   rR   rS    test_metrics_pos_label_error_str  s   "r  )	functoolsr   inspectr   	itertoolsr   r   r   numpyrN   scipy.sparsesparser(  r   sklearn.datasetsr   sklearn.preprocessingr   sklearn.utils.multiclassr	   sklearn.utils.validationr
   r   sklearn.utilsr   sklearn.utils._testingr   r   r   r   r   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/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   sklearn.metrics._baser;   REGRESSION_METRICSr   r   CURVE_METRICSr   dictr   updater   METRIC_UNDEFINED_MULTICLASSunionr   rY  rZ  r   r   METRICS_WITH_NORMALIZE_OPTIONr   r   r   r   r   METRICS_WITHOUT_SAMPLE_WEIGHTr   r   r   markparametrizesortedr   r   r   r   r   r   r   r   infr   invalids_nan_infr  r   r   r  r  r  r  r  r  r  r3  r9  rB  rC  intersectionrE  rV  r[  r_  rb  rh  rk  rm  r  r  r  r  r  r  r  r  r  r  strr4  r  rR   rR   rR   rS   <module>   s(   %



	
 !"#$%&'()*+,
-




9 	

"




$"!%



*
v
5
+	




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

a


	
	






