U
    9%eH                     @   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	 d dl
mZ d dlmZ d dlmZmZ ejdd Zejd	d
diedfddiedfgejdeddddgdfeddddgifgdd Zdd Zdd Zejdeddddgdfeddddgifgdd  Zejd!d"d#gejdeddddgdfeddddgifgd$d% Zejd
d&d'd( Zejd
d&d)d* Zejd+ededddd,fedejd-ddd.id,fedeej d d/dd.!ej"dd0fedej d1d dd.id0fgd2d3 Z#ejdeddddgdfeddddgifgd4d5 Z$ejdeddddgdfeddddgifgd6d7 Z%d8d9 Z&ejd:dd;d<gd,fd=dd>d?gd@fdd>d?gd0fgdAdB Z'dS )C    N)	load_iris)LearningCurveDisplayValidationCurveDisplaylearning_curvevalidation_curve)DecisionTreeClassifier)shuffle)assert_allcloseassert_array_equalc                   C   s   t tddddiS )NT)Z
return_X_yrandom_stater   )r   r    r   r   f/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/sklearn/model_selection/tests/test_plot.pydata   s    r   zparams, err_type, err_msgstd_display_styleinvalidzUnknown std_display_style:
score_typezUnknown score_type:zCurveDisplay, specific_params	max_depth         
param_nameparam_rangetrain_sizes333333?333333??c           
   	   C   sF   |\}}t dd}	tj||d |j|	||f|| W 5 Q R X dS )zCCheck that we raise a proper error when passing invalid parameters.r   r   matchN)r   pytestZraisesfrom_estimator)
pyplotr   paramsZerr_typeerr_msgCurveDisplayspecific_paramsXy	estimatorr   r   r   (test_curve_display_parameters_validation   s    
r*   c                 C   s@  |\}}t dd}dddg}tj||||d}ddl}|jdksDtt|jtsTt|jD ]}t||j	j
sZtqZt|jtst|jD ]&}	t|	|jjst|	 dkstq|jd	kst|j d
kst|j d	kst|j \}
}|ddgkstt||||d\}}}t|j| t|j| t|j| dS )z:Check the default usage of the LearningCurveDisplay class.r   r   r   r   r   r   N      ?Scorez%Number of samples in the training setTrainTest)r   r   r!   
matplotlib	errorbar_AssertionError
isinstancelines_listlinesLine2Dfill_between_collectionsPolyCollection	get_alpha
score_nameax_
get_xlabel
get_ylabelget_legend_handles_labelsr   r
   r   r	   train_scorestest_scores)r"   r   r'   r(   r)   r   displaympllinefill_legend_labelstrain_sizes_absrA   rB   r   r   r   )test_learning_curve_display_default_usage.   s@    

   

   rJ   c                 C   sJ  |\}}t dd}ddddg }}tj|||||d}ddl}|jdksLtt|jts\t|jD ]}	t|	|j	j
sbtqbt|jtst|jD ]&}
t|
|jjst|
 d	kstq|jd
kst|j | kst|j d
kst|j \}}|ddgkstt|||||d\}}t|j| t|j| t|j| dS )z<Check the default usage of the ValidationCurveDisplay class.r   r   r   r   r   r   r   Nr,   r-   r.   r/   )r   r   r!   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   r   r
   r   r	   rA   rB   )r"   r   r'   r(   r)   r   r   rC   rD   rE   rF   rG   rH   rA   rB   r   r   r   +test_validation_curve_display_default_usageU   sD    
    

    
rK   c                 C   s:  |\}}t ddd}d}|j|||f|d|i}|jd  d }	|	dk sTt|j dksftd}|j|||f|d|i}|jd  d }
|
dk stt|
|	  |j dkstd}|j|||f|d|i}|j dkst|j	| d	 |j dkst|jd  d dk  s6td
S )zaCheck the behaviour of the `negate_score` parameter calling `from_estimator` and
    `plot`.
    r   r   r   r   Fnegate_scorer-   TzNegative score)rM   N)
r   r!   r4   get_dataallr2   r=   r?   r	   Zplot)r"   r   r%   r&   r'   r(   r)   rM   rC   Zpositive_scoresZnegative_scoresr   r   r   test_curve_display_negate_score|   sV          rP   zscore_name, ylabel)Nr-   )AccuracyrQ   c           
      C   s~   |\}}t dd}|j|||f|d|i}	|	j |ks>t|\}}t ddd}|j|||f|d|i}	|	j|ksztdS )zGCheck that we can overwrite the default score name shown on the y-axis.r   r   r<   r   rL   N)r   r!   r=   r?   r2   r<   )
r"   r   r<   Zylabelr%   r&   r'   r(   r)   rC   r   r   r   test_curve_display_score_name   s0    
    rR   )Nerrorbarc                 C   s  |\}}t dd}dddg}t||||d\}}}	d}
tj|||||
|d}|j \}}|d	gksht|d
krt|jdkst|j	d
kst|jd 
 \}}n8|jd
kstt|j	dkst|j	d jd 
 \}}t|| t||jdd d}
tj|||||
|d}|j \}}|dgks0t|d
krrt|jdksNt|j	d
ks^t|jd 
 \}}n<|jd
kstt|j	dkst|j	d jd 
 \}}t|| t||	jdd d}
tj|||||
|d}|j \}}|d	dgkst|d
krXt|jdks"t|j	d
ks2t|jd 
 \}}|jd 
 \}}nT|jd
kshtt|j	dks|t|j	d jd 
 \}}|j	d jd 
 \}}t|| t||jdd t|| t||	jdd d
S ):Check the behaviour of setting the `score_type` parameter.r   r   r   r   r   r+   train)r   r   r   r.   Nr   Zaxistestr/   both   )r   r   r   r!   r=   r@   r2   lenr4   r1   rN   r6   r
   r	   mean)r"   r   r   r'   r(   r)   r   rI   rA   rB   r   rC   rG   legend_labelx_datay_datax_data_trainy_data_trainx_data_testy_data_testr   r   r   &test_learning_curve_display_score_type   s    

   	
	

	


rc   c              	   C   s  |\}}t dd}ddddg }}t|||||d\}}	d}
tj||||||
|d	}|j \}}|d
gkspt|dkrt|jdkst|j	dkst|jd 
 \}}n8|jdkstt|j	dkst|j	d jd 
 \}}t|| t||jdd d}
tj||||||
|d	}|j \}}|dgks:t|dkr|t|jdksXt|j	dksht|jd 
 \}}n<|jdkstt|j	dkst|j	d jd 
 \}}t|| t||	jdd d}
tj||||||
|d	}|j \}}|d
dgkst|dkrdt|jdks.t|j	dks>t|jd 
 \}}|jd 
 \}}nT|jdksttt|j	dkst|j	d jd 
 \}}|j	d jd 
 \}}t|| t||jdd t|| t||	jdd dS )rT   r   r   r   r   r   r   r   rU   )r   r   r   r   r.   NrV   rW   r/   rX   rY   )r   r   r   r!   r=   r@   r2   rZ   r4   r1   rN   r6   r
   r	   r[   )r"   r   r   r'   r(   r)   r   r   rA   rB   r   rC   rG   r\   r]   r^   r_   r`   ra   rb   r   r   r   (test_validation_curve_display_score_type"  s    
    









rd   z.CurveDisplay, specific_params, expected_xscalelinearg?)numrY   logc           	      C   s:   |\}}t dd}|j|||f|}|j |ks6tdS )zICheck the behaviour of the x-axis scaling depending on the data provided.r   r   N)r   r!   r=   
get_xscaler2   )	r"   r   r%   r&   Zexpected_xscaler'   r(   r)   rC   r   r   r   test_curve_display_xscale_auto  s    
rj   c                 C   s  |\}}t dd}ddl}d}|j|||f|d|i}	t|	jdksJt|	jD ]}
t|
|jjsPtqP|	j	dksvt|	j
dkst|	j \}}t|dkstd}|j|||f|d|i}	t|	jdkst|	jD ]}
t|
|jjstq|	j	dkstt|	j
dkst|	j
D ]}t||jjstq|	j \}}t|dksTtd}|j|||f|d|i}	|	jdkstt|	j	dkst|	j	D ]}t||jjstq|	j
dkst|	j \}}t|dkstdS )z9Check the behaviour of the parameter `std_display_style`.r   r   Nr   rY   fill_betweenrS   )r   r0   r!   rZ   r4   r2   r3   r6   r7   r1   r8   r=   r@   r9   r:   	containerZErrorbarContainer)r"   r   r%   r&   r'   r(   r)   rD   r   rC   rE   rG   r\   rk   rS   r   r   r   $test_curve_display_std_display_style  sp    	




rm   c                 C   s   |\}}t dd}d}ddi}ddd}	|j|||f||||	d}
|
jd  dks\tt|
jd  dd	d	dgg d
}ddi}|j|||f|||d}
|
jd j	d  dkstdS )zuCheck the behaviour of the different plotting keyword arguments: `line_kw`,
    `fill_between_kw`, and `errorbar_kw`.r   r   rk   colorredg      ?)rn   alpha)r   line_kwfill_between_kwg        rS   )r   errorbar_kwN)
r   r!   r4   	get_colorr2   r	   r8   Zget_facecolorr1   r6   )r"   r   r%   r&   r'   r(   r)   r   rq   rr   rC   rs   r   r   r   test_curve_display_plot_kwargs  s@    





	ru   c              	   C   s   | \}}t dd}tjtdd  tj|||dddgdd	}W 5 Q R X |j d
ksXt|j	 dksjttjtdd  tj|||dddgdd	}W 5 Q R X |j dkst|j	 dkstdS )z<Check that we warn for the deprecated parameter `log_scale`.r   r   z#`log_scale` parameter is deprecatedr   r   r   r   T)r   Z	log_scalerg   re   FN)
r   r    ZwarnsFutureWarningr   r!   r=   ri   r2   Z
get_yscale)r   r"   r'   r(   r)   rC   r   r   r   /test_learning_curve_display_deprecate_log_scale  s,    
        rw   zparam_range, xscale
      i2   i  Zsymlogc           	      C   s@   |\}}t dd}d}tj|||||d}|j |ks<tdS )z>Check the induced xscale from the provided param_range values.r   r   r   r   N)r   r   r!   r=   ri   r2   )	r"   r   r   Zxscaler'   r(   r)   r   rC   r   r   r   @test_validation_curve_xscale_from_param_range_provided_as_a_list(  s    
r{   )(numpynpr    Zsklearn.datasetsr   Zsklearn.model_selectionr   r   r   r   Zsklearn.treer   Zsklearn.utilsr   Zsklearn.utils._testingr	   r
   Zfixturer   markZparametrize
ValueErrorr*   rJ   rK   rP   rR   rc   rd   ZarangeZlinspaceroundZlogspaceZastypeZint64rj   rm   ru   rw   r{   r   r   r   r   <module>   s   
''
$ 
Z
]

=
((