o
    iM                     @   s  d dl Zd dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZ d dlmZ d dlmZ ejdddgejdd	d
gdd Zejddd gejdddgejdg ddd Zejdeg ddfed dgdfeg ddfgdd Zejdddgejddeg dfdeg dfgd d! Zejd"d#d$ieddgd%d&gged dgddd'd(fd$ddgddggd%d&gd%d&ggd)d*eddgged dgddd'd+fd$ddgddggd%d&gd%d&ggd)d*eg d,eg d-ddd'd.fd$ddgddggd%d&gd%d&ggd)d*eg d,eg ded/gdd'dfd$ddgddggd%d&gd%d&ggd)d*eg d,eg d0ddd'd1fgd2d3 Zejd4g d5d6d7 Zejd8d9d:idgejd;i d9d:igd<d= Zd>d? Zejddd@d@ggejdAdBdCdDdddDgejdEdFdGgejd8ddHdIigdJdK Zejddd@g dLgejdAdMg dNidMg dOigejdEdFdGgdPdQ ZdRdM ZdSdT ZejdUdVdWdXdYdZd[d\d]d^ed_d^fd^ed`d^fded_dafded`dbfd^ed_d^fd^ed`d^fded_dbfded`dafgdcdd Zejdee dfddgdgdhfe dfddi djdkfe!d ddgdldmfg dndodpfgdqdr Z"ejdsdtddudvdwidtddwdxfdtdydzdIdwd{dIdwdzfd|d}d~dddid|d}ddfi i i fi dwdIdddddtdgddwdIdddddtdgdfgdd Z#ejdi dd%dfi ddtdfgdd Z$dd Z%ejdddgejdddgdd Z&dS )    N)LogisticRegression)"_BinaryClassifierCurveDisplayMixin_deprecate_estimator_name_despine_interval_max_min_ratio_validate_score_name_validate_style_kwargs)_get_response_values_binary)assert_allcloseaxZAxzname, expected_name_out)NTestEstimator)
CustomNamer   c                 C   sT   t  }d|_|r|  \}}|j||d\}}}||ksJ |r&||ks(J dS dS )z9Check `_validate_plot_params` returns the correct values.r   )r   nameN)r   estimator_nameZsubplotsZ_validate_plot_params)pyplotr   r   Zexpected_name_outdisplay_Zax_outname_out r   p/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/sklearn/utils/tests/test_plotting.pytest_validate_plot_params   s   r   	pos_labelr   r   response_method)autoZpredict_probaZdecision_functionc                 C   s   t ddgddgddgddgg}t g d}t ||}tj||||||d\}}}t||||d\}	}
t||	 ||
ksBJ |durH|nd	}||ksPJ dS )
zECheck `_validate_and_get_response_values` returns the correct values.r            )r   r   r   r   )r   r   r   )r   r   Nr   )nparrayr   fitr   Z!_validate_and_get_response_valuesr	   r
   )r   r   r   r   Xy	estimatory_predr   Zexpected_y_predexpected_pos_labelexpected_namer   r   r   %test_validate_and_get_response_values#   s&   "

r&   zy_true, error_message)r   r   r   zThe target y is not binary.r   z'Found input variables with inconsistent)r   r   r   r   z,y_true takes value in \{0, 2\} and pos_labelc                 C   s^   t g d}t d}tjt|d tj|||dd W d   dS 1 s(w   Y  dS )zDCheck `_validate_from_predictions_params` raises the correct errors.皙?皙?g333333?g?   matchN)y_truer#   sample_weightr   )r   r   Zonespytestraises
ValueErrorr   !_validate_from_predictions_params)r   r-   error_messager#   r.   r   r   r   ,test_validate_from_predictions_params_errorsE   s   

"r4   zpos_label, y_true)r   r   r   r   r   c           	      C   sb   t g d}tj||d||d\}}|dur|nd}||ks!J |dur'|nd}||ks/J dS )zECheck `_validate_from_predictions_params` returns the correct values.r'   N)r-   r#   r.   r   r   
Classifierr   )r   r   r   r2   )	r   r   r   r-   r#   Zpos_label_outr   r%   r$   r   r   r   -test_validate_from_predictions_params_returns[   s   
r6   zparams, err_msgr"   dummyr   r*   )Z
cv_resultsr    r!   r.   r   z2`cv_results` does not contain one of the following)testtrain)r"   indicesz*`X` does not contain the correct number of)r   r   r   r*   )r   r   r   r   zThe target `y` is not binary      ?)r   r   r   r   z6y takes value in {2, 3} and pos_label is not specifiedc                 C   sF   t jt|d t jdi | W d   dS 1 sw   Y  dS )z2Check parameter validation is performed correctly.r+   Nr   )r/   r0   r1   r   Z _validate_from_cv_results_params)r   paramserr_msgr   r   r   $test_validate_from_cv_results_paramsy   s   J"r>   z/curve_legend_metric, curve_name, expected_label))g333333?Nz
AUC = 0.85)NModel Ar?   )gffffff?zRandom ForestzRandom Forest (AUC = 0.95)NNNc                 C   s"   d}t | ||}||ksJ dS )z4Check `_get_legend_label` returns the correct label.AUCN)r   Z_get_legend_label)Zcurve_legend_metric
curve_nameexpected_labellegend_metric_namelabelr   r   r   test_get_legend_label   s
   rF   curve_kwargsalpha      ?kwargsc                 C   s   d}d}ddd}d}| r6|r6t jtdd tj||||| fi | W d   dS 1 s/w   Y  dS |r_t jtd	d tj||||| fi | W d   dS 1 sXw   Y  dS tj||||| fi | dS )
z;Check `_validate_curve_kwargs` deprecates kwargs correctly.r   N皙?r(   meanZstdrA   z"Cannot provide both `curve_kwargs`r+   z`\*\*kwargs` is deprecated and)r/   r0   r1   r   _validate_curve_kwargswarnsFutureWarning)rG   rJ   n_curvesr   legend_metricrD   r   r   r   +test_validate_curve_kwargs_deprecate_kwargs   sB   
"	"

rS   c                  C   s   d} ddd}d}t jtdd tj| d||d	d
igd W d   n1 s(w   Y  t jtdd# g d}tj| |||dd tj| |||d	d
id W d   dS 1 sZw   Y  dS )zGCheck `_validate_curve_kwargs` performs parameter validation correctly.r   rK   r(   rL   rA   z`curve_kwargs` must be Noner+   NrH   rI   rQ   r   rR   rD   rG   z#To avoid labeling individual curvesonetwothree)r/   r0   r1   r   rN   )rQ   rR   rD   r   r   r   r    test_validate_curve_kwargs_error   s:   
"rY   rB   rR   rK   r)   rL   rD   rA   ZAPcolorredc                 C   s\  d}t j|| |||d}t|tsJ t||ksJ d}t| tr&| d } | dur;| }|d dur:|d| d }n|d durF| d}|d d	 |ksPJ |d
 d	 du sZJ |d d	 du sdJ |du rtdd |D ssJ tdd |D s~J tdd |D sJ tdd |D sJ dS tdd |D sJ tdd |D sJ dS )zNCheck `_validate_curve_kwargs` returns correct kwargs for single legend entry.r   rT   Nr   rM    (z = 0.80 +/- 0.20)z = 0.80 +/- 0.20rE   r   r   c                 s       | ]	}t |d kV  qdS )r*   Nlen.0rJ   r   r   r   	<genexpr>O      z;test_validate_curve_kwargs_single_legend.<locals>.<genexpr>c                 s       | ]	}|d  dkV  qdS )rH   r;   Nr   r`   r   r   r   rb   P  rc   c                 s   rd   )	linestyle--Nr   r`   r   r   r   rb   Q  rc   c                 s   rd   )rZ   blueNr   r`   r   r   r   rb   R  rc   c                 s   r]   r   Nr^   r`   r   r   r   rb   T  rc   c                 s   rd   )rZ   r[   Nr   r`   r   r   r   rb   U  rc   )r   rN   
isinstancelistr_   all)r   rR   rD   rG   rQ   curve_kwargs_outrC   r   r   r   (test_validate_curve_kwargs_single_legend  s<   

rm   rU   metric)rI   rI   rI   r@   c                    sd  d}ddiddiddig}t j|| | |d}t|tsJ t||ks&J g d}t| trGd}|d	 d
 durA|d  d }|g| }n7t| trW|d	 d
 du rW| }n't| trn|d	 d
 durn fdd| D }n|d	 d
 dur~  dg| }t|D ]\}}|| d |ksJ qtdd |D sJ t||D ]\}	}
|
d |	d ksJ qdS )zMCheck `_validate_curve_kwargs` returns correct kwargs for multi legend entry.r   rZ   r[   yellowrg   rT   r@   rB   rn   r   Nr\    = 1.00)c                    s   g | ]
}| d   dqS )r\   rp   r   )ra   Zname_singlerD   r   r   
<listcomp>u  s    z;test_validate_curve_kwargs_multi_legend.<locals>.<listcomp>z = 1.00rE   c                 s   r]   rh   r^   r`   r   r   r   rb     rc   z:test_validate_curve_kwargs_multi_legend.<locals>.<genexpr>)	r   rN   ri   rj   r_   str	enumeraterk   zip)r   rR   rD   rQ   rG   rl   Zexpected_labelsidxrC   Zcurve_kwargZcurve_kwarg_outr   rq   r   'test_validate_curve_kwargs_multi_legendX  s>   

rw   c                   C      d S Nr   r   r   r   r   rn        c                   C   rx   ry   r   r   r   r   r   
neg_metric  rz   r{   z6score_name, scoring, negate_score, expected_score_name)accuracyNFr|   )Nr|   FZAccuracy)Nr|   TzNegative accuracy)Nneg_mean_absolute_errorFzNegative mean absolute error)Nr}   TzMean absolute error)MAEr}   Tr~   )NNFZScore)NNTzNegative scorezSome metricFTZMetriczNegative metricc                 C   s   t | |||ks
J dS )z*Check that we return the right score name.N)r   )Z
score_nameZscoringZnegate_scoreZexpected_score_namer   r   r   test_validate_score_name  s   r   zdata, lower_bound, upper_boundr(         
         g?g?)r   r   r   r      2   r   (   c                 C   s$   |t |   k r|k sJ  J d S ry   )r   )datalower_boundupper_boundr   r   r   test_inverval_max_min_ratio  s   $r   z%default_kwargs, user_kwargs, expectedrg   )rZ   	linewidthre   Zdashed)rZ   r   re   Zsolid)rZ   re   )clsZxxxkrf   )rE   rZ   re   r   z-.blackro   green)r   r   ecZfcZlwZmecZmfcaltms)re   rZ   Z	edgecolorZ	facecolorr   ZmarkeredgecolorZmarkerfacecoloraltZ
markersizec                 C   s,   t | |}||ksJ d| d| ddS )zLCheck the behaviour of `validate_style_kwargs` with various type of entries.zLThe validation of style keywords does not provide the expected results: Got z instead of .N)r   )default_kwargsuser_kwargsexpectedresultr   r   r   test_validate_style_kwargs  s   
.
r   zdefault_kwargs, user_kwargs)r   re   r)r   rZ   c                 C   s:   t t t| | W d   dS 1 sw   Y  dS )z3Check that `validate_style_kwargs` raises TypeErrorN)r/   r0   	TypeErrorr   )r   r   r   r   r    test_validate_style_kwargs_error  s   "r   c                 C   sl   |   }t| |jd  du sJ |jd  du sJ |jd  dks)J |jd  dks4J d S )NtopFrightbottom)r   r   left)Zgcar   ZspinesZget_visibleZ
get_bounds)r   r   r   r   r   test_despine  s   r   r   Zmy_est_name
deprecatedZmy_namec                 C   s   d}d}| dkrt | ||}||ksJ dS |du rHd| d| d}tjt|d t | ||}W d   n1 s;w   Y  || ksFJ dS |durud	| d| d
}tjt|d t | || W d   dS 1 snw   Y  dS dS )z3Check `_deprecate_estimator_name` behaves correctlyz1.7z1.9r   Nz"`estimator_name` is deprecated in z and will be removed in z. Use `name` instead.r+   zSCannot provide both `estimator_name` and `name`. `estimator_name` is deprecated in z. )r   r/   rO   rP   r0   r1   )r   r   versionZversion_remover   Zwarning_messager   r3   r   r   r   test_deprecate_estimator_name  s2   "r   )'numpyr   r/   Zsklearn.linear_modelr   Zsklearn.utils._plottingr   r   r   r   r   r   Zsklearn.utils._responser	   Zsklearn.utils._testingr
   markZparametrizer   r&   r   r4   r6   r>   rF   rS   rY   rm   rw   rn   r{   r   Z	geomspaceZlinspacer   r   r   r   r   r   r   r   r   <module>   s    
   
 
H
	
"+'













,	
	