
    0Ph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                            dd	d
iedfdd
iedfg          ej                            dedg ddfedg difg          d                         Zd Zd Zej                            dedg ddfedg difg          d             Zej                            dddg          ej                            dedg ddfedg difg          d                         Zej                            d	d          d             Zej                            d	d          d             Ze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!%                    !                    ej"                  dd'fed ej         d(d d!%          id'fg          d)             Z#ej                            dedg ddfedg difg          d*             Z$ej                            dedg ddfedg difg          d+             Z%ej                            d,g d-d"fg d.d/fg d0d'fg          d1             Z&ej                            d2ei fedg ddfg          d3             Z'dS )4    N)	load_iris)LearningCurveDisplayValidationCurveDisplaylearning_curvevalidation_curve)DecisionTreeClassifier)shuffle)assert_allcloseassert_array_equalc                  6    t          t          d          ddiS )NT)
return_X_yrandom_stater   )r	   r        g/var/www/html/test/jupyter/venv/lib/python3.11/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           dS # 1 swxY w Y   dS )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      s    $ DAq&A666I	xw	/	/	/ R R##Iq!QQQ&QQQR R R R R R R R R R R R R R R R R Rs   AAAc                 L   |\  }}t          d          }g d}t          j        ||||          }ddl}|j        J t          |j        t                    sJ |j        D ]}t          ||j        j	                  sJ t          |j
        t                    sJ |j
        D ]8}	t          |	|j        j                  sJ |	                                dk    sJ 9|j        dk    sJ |j                                        dk    sJ |j                                        dk    sJ |j                                        \  }
}|d	d
gk    sJ t'          ||||          \  }}}t)          |j        |           t-          |j        |           t-          |j        |           dS )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666I!//K"11a[  G $$$gnd+++++ 2 2$	 0111111g+T22222% ' '$ >?????~~3&&&&&((((;!!##'NNNNN;!!##w....{<<>>A}Wf-----1?1a[2 2 2.O\; w*O<<<G(,777G'55555r   c                 T   |\  }}t          d          }dg d}}t          j        |||||          }ddl}|j        J t          |j        t                    sJ |j        D ]}	t          |	|j        j	                  sJ t          |j
        t                    sJ |j
        D ]8}
t          |
|j        j                  sJ |
                                dk    sJ 9|j        dk    sJ |j                                        | k    sJ |j                                        dk    sJ |j                                        \  }}|d	d
gk    sJ t'          |||||          \  }}t)          |j        |           t-          |j        |           t-          |j        |           dS )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666I)999J$31aJK  G $$$gnd+++++ 2 2$	 0111111g+T22222% ' '$ >?????~~3&&&&&((((;!!##*6666;!!##w....{<<>>A}Wf----- 01aJK! ! !L+ w*K888G(,777G'55555r   c                 t   |\  }}t          dd          }d} |j        |||fi |d|i}|j        d                                         d         }	|	dk                                    sJ |j                                        dk    sJ d} |j        |||fi |d|i}|j        d                                         d         }
|
dk                                    sJ t          |
|	            |j                                        dk    sJ d} |j        |||fi |d|i}|j                                        dk    sJ |                    | 	           |j                                        dk    sJ |j        d                                         d         dk                                     sJ d
S )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[   |   s8    DAq&CCCIL)l)1a * 9E  G nQ'002215Oq %%''''';!!##w....L)l)1a * 9E  G nQ'002215Oq %%'''''Oo%5666;!!##'77777L)l)1a * 9E  G ;!!##w....LL,.L///;!!##w....N1&&((+a/446666666r   zscore_name, ylabel)Nr4   )Accuracyr\   c                    |\  }}t          d          } |j        |||fi |d|i}	|	j                                        |k    sJ |\  }}t          dd          } |j        |||fi |d|i}	|	j        |k    sJ dS )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666I)l)1a * 7A  G ;!!##v----DAq&CCCI)l)1a * 7A  G ''''''r   )Nerrorbarc                    |\  }}t          d          }g d}t          ||||          \  }}}	d}
t          j        |||||
|          }|j                                        \  }}|dgk    sJ |Ft          |j                  d	k    sJ |j        J |j        d         	                                \  }}nP|j        J t          |j                  d	k    sJ |j        d         j
        d         	                                \  }}t          ||           t          ||                    d	
                     d}
t          j        |||||
|          }|j                                        \  }}|dgk    sJ |Ft          |j                  d	k    sJ |j        J |j        d         	                                \  }}nP|j        J t          |j                  d	k    sJ |j        d         j
        d         	                                \  }}t          ||           t          ||	                    d	
                     d}
t          j        |||||
|          }|j                                        \  }}|ddgk    sJ |ht          |j                  dk    sJ |j        J |j        d         	                                \  }}|j        d	         	                                \  }}n}|j        J t          |j                  dk    sJ |j        d         j
        d         	                                \  }}|j        d	         j
        d         	                                \  }}t          ||           t          ||                    d	
                     t          ||           t          ||	                    d	
                     dS ):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      sC    DAq&A666I!//K1?1a[2 2 2.O\; J"1		+  G k;;==OA|G9$$$$ 7>""a'''' ((( *3355~%%%7$%%**** *1-3A6??AAv///FL--1-55666J"1		+  G k;;==OA|F8#### 7>""a'''' ((( *3355~%%%7$%%**** *1-3A6??AAv///FK,,!,44555J"1		+  G k;;==OA|GV,,,,, 7>""a'''' (((%,^A%6%?%?%A%A"l#*>!#4#=#=#?#? [[~%%%7$%%****%,%6q%9%?%B%K%K%M%M"l#*#4Q#7#=a#@#I#I#K#K [|_555L,"3"3"3";";<<<{O444K!1!1q!1!9!9:::::r   c           	         |\  }}t          d          }dg d}}t          |||||          \  }}	d}
t          j        ||||||
|          }|j                                        \  }}|dgk    sJ |Ft          |j                  d
k    sJ |j        J |j        d         	                                \  }}nP|j        J t          |j                  d
k    sJ |j        d         j
        d         	                                \  }}t          ||           t          ||                    d
                     d}
t          j        ||||||
|          }|j                                        \  }}|dgk    sJ |Ft          |j                  d
k    sJ |j        J |j        d         	                                \  }}nP|j        J t          |j                  d
k    sJ |j        d         j
        d         	                                \  }}t          ||           t          ||	                    d
                     d}
t          j        ||||||
|          }|j                                        \  }}|ddgk    sJ |ht          |j                  dk    sJ |j        J |j        d         	                                \  }}|j        d
         	                                \  }}n}|j        J t          |j                  dk    sJ |j        d         j
        d         	                                \  }}|j        d
         j
        d         	                                \  }}t          ||           t          ||                    d
                     t          ||           t          ||	                    d
                     d	S )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   "  sP    DAq&A666I)999J 01aJK! ! !L+ J$3		+  G k;;==OA|G9$$$$ 7>""a'''' ((( *3355~%%%7$%%**** *1-3A6??AAv{+++FL--1-55666J$3		+  G k;;==OA|F8#### 7>""a'''' ((( *3355~%%%7$%%**** *1-3A6??AAv{+++FK,,!,44555J$3		+  G k;;==OA|GV,,,,, 7>""a'''' (((%,^A%6%?%?%A%A"l#*>!#4#=#=#?#? [[~%%%7$%%****%,%6q%9%?%B%K%K%M%M"l#*#4Q#7#=a#@#I#I#K#K [|[111L,"3"3"3";";<<<{K000K!1!1q!1!9!9:::::r   z.CurveDisplay, specific_params, expected_xscaler   r   linearg?r    )numrh   logc                     |\  }}t          d          } |j        |||fi |}|j                                        |k    sJ dS )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|     s`    0 DAq&A666I)l))QMM_MMG;!!##666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                  s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                  sJ |	j        J t          |	j	                  dk    sJ |	j	        D ]}t          ||j        j                  s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                  sJ |	j	        J |	j
                                        \  }}t          |          dk    sJ dS )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666I)l)		  	 
 ,  G w~!#### 2 2$	 0111111$$$ (((k;;==OA||!!!!&)l)		  	 
 ,  G w~!#### 2 2$	 0111111$$$w$%%****- H H,(FGGGGGGk;;==OA||!!!!")l)		  	 
 ,  G >!!!w !!Q&&&&% E E(CM$CDDDDDD (((k;;==OA||!!!!!!r   c                    |\  }}t          d          }d}ddi}ddd}	 |j        |||fi ||||	d}
|
j        d                                         dk    sJ t	          |
j        d                                         g d	g           d
}ddi} |j        |||fi |||d}
|
j        d         j        d                                         dk    sJ dS )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     se    DAq&A666I&G %44O)l)		  	
 ,'   G >!&&((E1111a ..00			  
 #E"K)l)		  	
 ,   G Q%a(2244======r   zparam_range, xscale)r   
      )ir   2     symlog)r   r   r   c                     |\  }}t          d          }d}t          j        |||||          }|j                                        |k    sJ dS )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     so     DAq&A666IJ$3		  G ;!!##v------r   zDisplay, paramsc                     |\  }}t          d          } G d d|          } |j        |||fi |}t          ||          sJ dS )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dS )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   (  s     DAq&A666I    G    /.y!QII&IIGg01111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      sE        & & & & & &            0 / / / / / ! ! ! ! ! ! F F F F F F F F @ @ @ 
y	):7ST
		"J0EF  #	III!V!VW	?@ R R  R$6 $6 $6N$6 $6 $6N #	III!V!VW	?@ !7 !7 !7H ?,DE  #	III!V!VW	?@ ( (  (, ,.@AAW; W; BAW;t ,.@AAZ; Z; BAZ;z 4 #&yryAGG	

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