
    h$,fK                        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        Zej&                  j)                  dd	d
iedfdd
iedfg      ej&                  j)                  dedg ddfedg difg      d               Zd Zd Zej&                  j)                  dedg ddfedg difg      d        Zej&                  j)                  dddg      ej&                  j)                  dedg ddfedg difg      d               Zej&                  j)                  d	d      d        Zej&                  j)                  d	d      d        Zej&                  j)                  ded ej:                  d d!      dd"fed ej<                  d#d$d!%      id"fed ej>                   ej@                  d d&d!%            jC                  ejD                        dd'fed ej@                  d(d d!%      id'fg      d)        Z#ej&                  j)                  dedg ddfedg difg      d*        Z$ej&                  j)                  dedg ddfedg difg      d+        Z%d, Z&ej&                  j)                  d-g d.d"fg d/d0fg d1d'fg      d2        Z'ej&                  j)                  d3ei fedg ddfg      d4        Z(y)5    N)	load_iris)LearningCurveDisplayValidationCurveDisplaylearning_curvevalidation_curve)DecisionTreeClassifier)shuffle)assert_allcloseassert_array_equalc                  ,    t        t        d      ddiS )NT)
return_X_yrandom_stater   )r	   r        Glib/python3.12/site-packages/sklearn/model_selection/tests/test_plot.pydatar      s    I.?Q??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_sizesg333333?g333333??c                     |\  }}t        d      }	t        j                  ||      5   |j                  |	||fi || ddd       y# 1 sw Y   yxY w)zCCheck that we raise a proper error when passing invalid parameters.r   r   matchN)r   pytestraisesfrom_estimator)
pyplotr   paramserr_typeerr_msgCurveDisplayspecific_paramsXy	estimators
             r   (test_curve_display_parameters_validationr1      s\    $ DAq&A6I	xw	/ R###Iq!QQ&QR R Rs   A

Ac                 ~   |\  }}t        d      }g d}t        j                  ||||      }ddl}|j                  J t        |j                  t              sJ |j                  D ]$  }t        ||j                  j                        r$J  t        |j                  t              sJ |j                  D ]9  }	t        |	|j                  j                        sJ |	j                         dk(  r9J  |j                  dk(  sJ |j                  j!                         dk(  sJ |j                  j#                         dk(  sJ |j                  j%                         \  }
}|d	d
gk(  sJ t'        ||||      \  }}}t)        |j*                  |       t-        |j.                  |       t-        |j0                  |       y)z:Check the default usage of the LearningCurveDisplay class.r   r"   r   r   N      ?Scorez%Number of samples in the training setTrainTest)r   r   r'   
matplotlib	errorbar_
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/   r0   r   displaympllinefill_legend_labelstrain_sizes_absrH   rI   s                  r   )test_learning_curve_display_default_usagerQ   .   s   DAq&A6I!K"111a[G $$$gnnd+++ 2$		 0 01112 g++T222%% '$ > >???~~3&&&' (((;;!!#'NNNN;;!!#w...{{<<>A}Wf----1?1a[2.O\; w**O<G((,7G''5r   c                    |\  }}t        d      }dg d}}t        j                  |||||      }ddl}|j                  J t        |j                  t              sJ |j                  D ]$  }	t        |	|j                  j                        r$J  t        |j                  t              sJ |j                  D ]9  }
t        |
|j                  j                        sJ |
j                         dk(  r9J  |j                  dk(  sJ |j                  j!                         | k(  sJ |j                  j#                         dk(  sJ |j                  j%                         \  }}|d	d
gk(  sJ t'        |||||      \  }}t)        |j*                  |       t-        |j.                  |       t-        |j0                  |       y)z<Check the default usage of the ValidationCurveDisplay class.r   r"   r   r   r   Nr4   r5   r6   r7   )r   r   r'   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   r   r   r   r
   rH   rI   )r(   r   r.   r/   r0   r   r   rJ   rK   rL   rM   rN   rO   rH   rI   s                  r   +test_validation_curve_display_default_usagerS   U   s   DAq&A6I)9J$331aJKG $$$gnnd+++ 2$		 0 01112 g++T222%% '$ > >???~~3&&&' (((;;!!#*666;;!!#w...{{<<>A}Wf---- 01aJK!L+ w**K8G((,7G''5r   c                 <   |\  }}t        dd      }d} |j                  |||fi |d|i}|j                  d   j                         d   }	|	dk\  j	                         sJ |j
                  j                         dk(  sJ d} |j                  |||fi |d|i}|j                  d   j                         d   }
|
dk  j	                         sJ t        |
|	        |j
                  j                         dk(  sJ d} |j                  |||fi |d|i}|j
                  j                         dk(  sJ |j                  | 	       |j
                  j                         dk(  sJ |j                  d   j                         d   dk  j	                         sJ y
)zaCheck the behaviour of the `negate_score` parameter calling `from_estimator` and
    `plot`.
    r   r   r   r   Fnegate_scorer5   TzNegative score)rV   N)	r   r'   r;   get_dataallrD   rF   r
   plot)r(   r   r,   r-   r.   r/   r0   rV   rJ   positive_scoresnegative_scoress              r   test_curve_display_negate_scorer\   |   s    DAq&CIL)l))1a*9EG nnQ'00215Oq %%''';;!!#w...L)l))1a*9EG nnQ'00215Oq %%'''Oo%56;;!!#'7777L)l))1a*9EG ;;!!#w...LL,.L/;;!!#w...NN1&&(+a/44666r   zscore_name, ylabel)Nr5   )Accuracyr]   c                    |\  }}t        d      } |j                  |||fi |d|i}	|	j                  j                         |k(  sJ |\  }}t        dd      } |j                  |||fi |d|i}	|	j                  |k(  sJ y)zGCheck that we can overwrite the default score name shown on the y-axis.r   r"   rC   r   rU   N)r   r'   rD   rF   rC   )
r(   r   rC   ylabelr,   r-   r.   r/   r0   rJ   s
             r   test_curve_display_score_namer`      s     DAq&A6I)l))1a*7AG ;;!!#v---DAq&CI)l))1a*7AG '''r   )Nerrorbarc                 |   |\  }}t        d      }g d}t        ||||      \  }}}	d}
t        j                  |||||
|      }|j                  j                         \  }}|dgk(  sJ |It        |j                        d	k(  sJ |j                  J |j                  d   j                         \  }}nU|j                  J t        |j                        d	k(  sJ |j                  d   j                  d   j                         \  }}t        ||       t        ||j                  d	
             d}
t        j                  |||||
|      }|j                  j                         \  }}|dgk(  sJ |It        |j                        d	k(  sJ |j                  J |j                  d   j                         \  }}nU|j                  J t        |j                        d	k(  sJ |j                  d   j                  d   j                         \  }}t        ||       t        ||	j                  d	
             d}
t        j                  |||||
|      }|j                  j                         \  }}|ddgk(  sJ |it        |j                        dk(  sJ |j                  J |j                  d   j                         \  }}|j                  d	   j                         \  }}n|j                  J t        |j                        dk(  sJ |j                  d   j                  d   j                         \  }}|j                  d	   j                  d   j                         \  }}t        ||       t        ||j                  d	
             t        ||       t        ||	j                  d	
             y):Check the behaviour of setting the `score_type` parameter.r   r"   r   r3   train)r   r   r   r6   Nr   axistestr7   both   )r   r   r   r'   rD   rG   lenr;   r9   rW   r=   r   r
   mean)r(   r   r   r.   r/   r0   r   rP   rH   rI   r   rJ   rN   legend_labelx_datay_datax_data_trainy_data_trainx_data_testy_data_tests                       r   &test_learning_curve_display_score_typers      s    DAq&A6I!K1?1a[2.O\; J"11		+G kk;;=OA|G9$$$ 7>>"a'''  ((( *335~~%%%7$$%*** **1-33A6??Av/FL--1-56J"11		+G kk;;=OA|F8### 7>>"a'''  ((( *335~~%%%7$$%*** **1-33A6??Av/FK,,!,45J"11		+G kk;;=OA|GV,,,, 7>>"a'''  (((%,^^A%6%?%?%A"l#*>>!#4#=#=#? [~~%%%7$$%***%,%6%6q%9%?%?%B%K%K%M"l#*#4#4Q#7#=#=a#@#I#I#K [|_5L,"3"3"3";<{O4K!1!1q!1!9:r   c           	         |\  }}t        d      }dg d}}t        |||||      \  }}	d}
t        j                  ||||||
|      }|j                  j                         \  }}|dgk(  sJ |It        |j                        d
k(  sJ |j                  J |j                  d   j                         \  }}nU|j                  J t        |j                        d
k(  sJ |j                  d   j                  d   j                         \  }}t        ||       t        ||j                  d
             d}
t        j                  ||||||
|      }|j                  j                         \  }}|dgk(  sJ |It        |j                        d
k(  sJ |j                  J |j                  d   j                         \  }}nU|j                  J t        |j                        d
k(  sJ |j                  d   j                  d   j                         \  }}t        ||       t        ||	j                  d
             d}
t        j                  ||||||
|      }|j                  j                         \  }}|ddgk(  sJ |it        |j                        dk(  sJ |j                  J |j                  d   j                         \  }}|j                  d
   j                         \  }}n|j                  J t        |j                        dk(  sJ |j                  d   j                  d   j                         \  }}|j                  d
   j                  d   j                         \  }}t        ||       t        ||j                  d
             t        ||       t        ||	j                  d
             y	)rc   r   r"   r   r   r   rd   )r   r   r   r   r6   Nr   re   rg   r7   rh   ri   )r   r   r   r'   rD   rG   rj   r;   r9   rW   r=   r   r
   rk   )r(   r   r   r.   r/   r0   r   r   rH   rI   r   rJ   rN   rl   rm   rn   ro   rp   rq   rr   s                       r   (test_validation_curve_display_score_typeru   "  s    DAq&A6I)9J 01aJK!L+ J$33		+G kk;;=OA|G9$$$ 7>>"a'''  ((( *335~~%%%7$$%*** **1-33A6??Av{+FL--1-56J$33		+G kk;;=OA|F8### 7>>"a'''  ((( *335~~%%%7$$%*** **1-33A6??Av{+FK,,!,45J$33		+G kk;;=OA|GV,,,, 7>>"a'''  (((%,^^A%6%?%?%A"l#*>>!#4#=#=#? [~~%%%7$$%***%,%6%6q%9%?%?%B%K%K%M"l#*#4#4Q#7#=#=a#@#I#I#K [|[1L,"3"3"3";<{K0K!1!1q!1!9:r   z.CurveDisplay, specific_params, expected_xscaler   r   linearg?r    )numri   logc                     |\  }}t        d      } |j                  |||fi |}|j                  j                         |k(  sJ y)zICheck the behaviour of the x-axis scaling depending on the data provided.r   r"   N)r   r'   rD   
get_xscale)	r(   r   r,   r-   expected_xscaler.   r/   r0   rJ   s	            r   test_curve_display_xscale_autor}     sM    0 DAq&A6I)l)))QM_MG;;!!#666r   c                    |\  }}t        d      }ddl}d} |j                  |||fi |d|i}	t        |	j                        dk(  sJ |	j                  D ]$  }
t        |
|j                  j                        r$J  |	j                  J |	j                  J |	j                  j                         \  }}t        |      dk(  sJ d} |j                  |||fi |d|i}	t        |	j                        dk(  sJ |	j                  D ]$  }
t        |
|j                  j                        r$J  |	j                  J t        |	j                        dk(  sJ |	j                  D ]$  }t        ||j                  j                        r$J  |	j                  j                         \  }}t        |      dk(  sJ d} |j                  |||fi |d|i}	|	j                  J t        |	j                        dk(  sJ |	j                  D ]$  }t        ||j                  j                        r$J  |	j                  J |	j                  j                         \  }}t        |      dk(  sJ y)z9Check the behaviour of the parameter `std_display_style`.r   r"   Nr   ri   fill_betweenra   )r   r8   r'   rj   r;   r:   r=   r>   r9   r?   rD   rG   r@   rA   	containerErrorbarContainer)r(   r   r,   r-   r.   r/   r0   rK   r   rJ   rL   rN   rl   r   ra   s                  r   $test_curve_display_std_display_styler     s    DAq&A6I)l))		 	
 ,G w~~!### 2$		 0 01112$$$  (((kk;;=OA||!!!&)l))		 	
 ,G w~~!### 2$		 0 01112$$$w$$%***-- H,(F(FGGGHkk;;=OA||!!!")l))		 	
 ,G >>!!!w  !Q&&&%% E(CMM$C$CDDDE  (((kk;;=OA||!!!r   c                    |\  }}t        d      }d}ddi}ddd}	 |j                  |||fi ||||	d}
|
j                  d   j                         dk(  sJ t	        |
j
                  d   j                         g d	g       d
}ddi} |j                  |||fi |||d}
|
j                  d   j                  d   j                         dk(  sJ y)zuCheck the behaviour of the different plotting keyword arguments: `line_kw`,
    `fill_between_kw`, and `errorbar_kw`.r   r"   r   colorred      ?)r   alpha)r   line_kwfill_between_kw)r           r   r   ra   )r   errorbar_kwN)	r   r'   r;   	get_colorr
   r?   get_facecolorr9   r=   )r(   r   r,   r-   r.   r/   r0   r   r   r   rJ   r   s               r   test_curve_display_plot_kwargsr     s     DAq&A6I&G %4O)l))		 	
 ,'G >>!&&(E111a ..0	
 #E"K)l))		 	
 ,G Q%%a(224===r   c                 N   | \  }}t        d      }t        j                  t        d      5  t	        j
                  |||g dd      }ddd       j                  j                         d	k(  sJ |j                  j                         d
k(  sJ t        j                  t        d      5  t	        j
                  |||g dd      }ddd       |j                  j                         d
k(  sJ |j                  j                         d
k(  sJ y# 1 sw Y   xY w# 1 sw Y   TxY w)z<Check that we warn for the deprecated parameter `log_scale`.r   r"   z#`log_scale` parameter is deprecatedr#   r   T)r   	log_scaleNrx   rv   F)	r   r%   warnsFutureWarningr   r'   rD   r{   
get_yscale)r   r(   r.   r/   r0   rJ   s         r   /test_learning_curve_display_deprecate_log_scaler     s   DAq&A6I	m+P	Q 
&55q!D


 ;;!!#u,,,;;!!#x///	m+P	Q 
&55q!E


 ;;!!#x///;;!!#x///
 

 
s   D+DDD$zparam_range, xscale)r   
      )ir   2     symlog)r   r   r   c                     |\  }}t        d      }d}t        j                  |||||      }|j                  j	                         |k(  sJ y)z>Check the induced xscale from the provided param_range values.r   r"   r   r   N)r   r   r'   rD   r{   )	r(   r   r   xscaler.   r/   r0   r   rJ   s	            r   @test_validation_curve_xscale_from_param_range_provided_as_a_listr   (  sX     DAq&A6IJ$33		G ;;!!#v---r   zDisplay, paramsc                     |\  }}t        d      } G d d|      } |j                  |||fi |}t        ||      sJ y)zCheck that named constructors return the correct type when subclassed.

    Non-regression test for:
    https://github.com/scikit-learn/scikit-learn/pull/27675
    r   r"   c                       e Zd Zy)4test_subclassing_displays.<locals>.SubclassOfDisplayN)__name__
__module____qualname__r   r   r   SubclassOfDisplayr   O  s    r   r   N)r   r'   r:   )	r(   r   Displayr)   r.   r/   r0   r   rJ   s	            r   test_subclassing_displaysr   ?  sR     DAq&A6IG  /..y!QI&IGg0111r   ))numpynpr%   sklearn.datasetsr   sklearn.model_selectionr   r   r   r   sklearn.treer   sklearn.utilsr	   sklearn.utils._testingr
   r   fixturer   markparametrize
ValueErrorr1   rQ   rS   r\   r`   rs   ru   arangelinspaceroundlogspaceastypeint64r}   r   r   r   r   r   r   r   r   <module>r      s     &  0 ! F @ @ 
y	):7ST
		"J0EF #	I!VW	?@RR$6N$6N #	I!VW	?@!7!7H ?,DE #	I!VW	?@((, ,.@AW; BW;t ,.@AZ; BZ;z 4 #&yryyAG	

 
{r{{3/KLhW")'rxxAqa(@AHHR 	
 
{r{{2qa/HI5Q(7)(7 #	I!VW	?@:":"z #	I!VW	?@$>$>P0, 80(;lE=RS.	.& 	r"	I!VW22r   