
    {KgH                        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%ej&                  j)                  d,g d-d"fg d.d/fg d0d'fg      d1        Z&ej&                  j)                  d2ei fedg ddfg      d3        Z'y)4    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        k/home/alanp/www/video.onchill/myenv/lib/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_validationr0      sO    $ DAq&A6I	xw	/###Iq!QQ&Q 
0	/	/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.   r/   r   displaympllinefill_legend_labelstrain_sizes_absrG   rH   s                  r   )test_learning_curve_display_default_usagerP   .   s   DAq&A6I!K"111a[G $$$gnnd+++$		 0 0111  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   Nr3   r4   r5   r6   )r   r   r&   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   r   r   r   r
   rG   rH   )r'   r   r-   r.   r/   r   r   rI   rJ   rK   rL   rM   rN   rG   rH   s                  r   +test_validation_curve_display_default_usagerR   U   s   DAq&A6I)9J$331aJKG $$$gnnd+++$		 0 0111  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_scorer4   TzNegative score)rU   N)	r   r&   r:   get_dataallrC   rE   r
   plot)r'   r   r+   r,   r-   r.   r/   rU   rI   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)Nr4   )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"   rB   r   rT   N)r   r&   rC   rE   rB   )
r'   r   rB   ylabelr+   r,   r-   r.   r/   rI   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   r2   train)r   r   r   r5   Nr   axistestr6   both   )r   r   r   r&   rC   rF   lenr:   r8   rV   r<   r   r
   mean)r'   r   r   r-   r.   r/   r   rO   rG   rH   r   rI   rM   legend_labelx_datay_datax_data_trainy_data_trainx_data_testy_data_tests                       r   &test_learning_curve_display_score_typerr      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	)rb   r   r"   r   r   r   rc   )r   r   r   r   r5   Nr   rd   rf   r6   rg   rh   )r   r   r   r&   rC   rF   ri   r:   r8   rV   r<   r   r
   rj   )r'   r   r   r-   r.   r/   r   r   rG   rH   r   rI   rM   rk   rl   rm   rn   ro   rp   rq   s                       r   (test_validation_curve_display_score_typert   "  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    )numrh   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&   rC   
get_xscale)	r'   r   r+   r,   expected_xscaler-   r.   r/   rI   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   rh   fill_betweenr`   )r   r7   r&   ri   r:   r9   r<   r=   r8   r>   rC   rF   r?   r@   	containerErrorbarContainer)r'   r   r+   r,   r-   r.   r/   rJ   r   rI   rK   rM   rk   r~   r`   s                  r   $test_curve_display_std_display_styler     s    DAq&A6I)l))		 	
 ,G w~~!###$		 0 0111 $$$  (((kk;;=OA||!!!&)l))		 	
 ,G w~~!###$		 0 0111 $$$w$$%***--,(F(FGGG .kk;;=OA||!!!")l))		 	
 ,G >>!!!w  !Q&&&%%(CMM$C$CDDD &  (((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   r`   )r   errorbar_kwN)	r   r&   r:   	get_colorr
   r>   get_facecolorr8   r<   )r'   r   r+   r,   r-   r.   r/   r   r   r   rI   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   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&   rC   rz   )	r'   r   r   xscaler-   r.   r/   r   rI   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   8  s    r   r   N)r   r&   r9   )	r'   r   Displayr(   r-   r.   r/   r   rI   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
ValueErrorr0   rP   rR   r[   r_   rr   rt   arangelinspaceroundlogspaceastypeint64r|   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	?@$>$>N 80(;lE=RS.	.& 	r"	I!VW22r   