
    0Ph9                       U d Z ddlZddlZddlZddlZddlZddlZddlmZm	Z	 ddl
Z
ddlZddlZddlmZ ddlmZ ddlmZmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZmZ ddl m!Z!m"Z" ddl#m$Z$ ddl%m&Z& ddl'm(Z(m)Z)m*Z*m+Z+ ddl,m-Z-m.Z.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: ddl3m;Z< ddl=m>Z> ddl?m@Z@mAZAmBZBmCZCmDZDmEZE ddlFmGZGmHZHmIZImJZJ ddlKmLZL dZMdZNe(e*dZOe)e+dZP eQ            ZReQeSd<   eRT                    eO           eRT                    eP           g dZU ejV        g dg dg dg dg d g d!g d"g d#g d$g d%g d&g d'g d(g d)g d*g d+g d,g d-g d.g d/g d0g d1g d2g          ZWg d3ZXg d4ZYd5d6gd6d6gd6d5gd7d7gd7d8gd8d7ggZZg d9Z[d6d6gd8d8gd:d8ggZ\g d;Z] ej^                    Z_ej`        a                    d7          Zbebc                    e_jd        je                  Zfe_jg        ef         e__g        e_jd        ef         e__d         ejh                    Ziebc                    eijd        je                  Zfeijg        ef         ei_g        eijd        ef         ei_d         ejj                    Zkebc                    ekjd        je                  Zfekjg        ef         ek_g        ekjd        ef         ek_d         eLd          Zl ejm        dd<d=>          \  ZnZoelp                    d?@          ZqdAeqeqdBk    <   elr                    ddCdD@          Zs e&dEd=dFdG          t                                Zue_jg        e_jd        dHeijg        eijd        dHekjg        ekjd        dHeZe[dHeWeXdHeWeYdHeneodHeqesdHeq esdHeuesdH ejv        dI          esdHdJZwdK ZxdL ZydM Zzej{        |                    dNeP}                                          ej{        |                    dOeN          dP                         Z~dQ ZdR Zej{        |                    dSeP                                          ej{        |                    dOeN          dT                         ZeEej{        |                    dSeP                                          ej{        |                    dUdVdWedXfdYdEedXfdZdWedXfd[dWed<fg          d\                                     Zd] Zd^ Zd_ Zd` Zda Zdb Zdc Zdd Zde Zdf Zdg ZddhZej{        |                    dieR          dj             Zej{        |                    dieU          ej{        |                    dkeI          dl                         Z	 ddmZej{        |                    dieR          dn             Zej{        |                    dieU          ej{        |                    dkeI          do                         Zdp Zdq Zdr Zds Zdt Zdu Zdv Zdw Zej{        |                    dieO          dx             Zej{        |                    dieO          dy             Zdz Zd{ Zd| Zd} Zd~ Zd Zd Zd Zd ZddZej{        |                    deU          ej{        |                    dd          d                         Zej{        |                    d e eeU                              eP                              ej{        |                    dddg          d                         Zej{        |                    deU          ej{        |                    dg d          ej{        |                    dkeI          d                                     Zej{        |                    d e e	d eUD             eN                     e e	d eUD             eM                    z             ej{        |                    dg d          ej{        |                    dkeI          d                                     Zej{        |                    deU          ej{        |                    d eeIeJ                    d                         Zd Zej{        |                    dieR          d             Zej{        |                    dieR          ej{        |                    ddgeIz             d                         Zej{        |                    dieR          d             Zej{        |                    dieU          ej{        |                    deJ          d                         Zd Zej{        |                    dieR          d             Zej{        |                    dieR          ej{        |                    deJ          d                         Zd Zd Zej{        |                    ddgeIz             d             Zej{        |                    d e eew                                          ddhz
                      ej{        |                    de(e*g          d                         Zej{        |                    dew                                          ej{        |                    de)e+g          d                         Zd Zd Zd Zej{        |                    dieR          ej{        |                    dddg          ej{        |                    ddgeIz   eJz             d                                     Zej{        |                    dOg d          ej{        |                    dNeP}                                          d                         Zej{        |                    d ed:                    d             Zd Zej{        |                    dNe(e*g          ej{        |                    dd8dCg          d                         Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zej{        |                    d e e/j}                     e0j}                                        d             Zd Zej{        |                    dNeR}                                          d             Zej{        |                    dOdVdZg          d             Zej{        |                    d ed:                    ej{        |                    dOdVdZg          d                         Zej{        |                    dOddg          dÄ             Zej{        |                    dOddg          dĄ             Zej{        |                    dOddg          dń             Zej{        |                    dOddg          dƄ             Zej{        |                    ddgeJz             ej{        |                    d e)dYȦ           e+dYȦ          g          dɄ                         Zej{        |                    dNeP}                                          dʄ             Zd˄ Zej{        |                    dej        e)dfej        e+dfee(dfee*dfg          ej{        |                    dddg          d҄                         Zej{        |                    d eeO}                                ddg                    dք             Zej{        |                    dej        e)fej        e(fg          d؄             Zdل Zej{        |                    dNe)e+g          ej{        |                    d ejV        ej        d8ej        dCddg           ejV        ej        ej        d:dCddg           ejV        d7d8d:dCej        ej        g           ejV        d7d8d:ej        dej        g          g          ej{        |                    dOdVdZg          d݄                                     Zdބ Zd߄ Zd Zd Zd ZdS )z-
Testing for the tree module (sklearn.tree).
    N)chainproduct)NumpyPickler)assert_allclose)clonedatasetstree)DummyRegressor)NotFittedError)SimpleImputer)accuracy_scoremean_poisson_deviancemean_squared_error)cross_val_scoretrain_test_split)make_pipeline)_sparse_random_matrix)DecisionTreeClassifierDecisionTreeRegressorExtraTreeClassifierExtraTreeRegressor)CRITERIA_CLFCRITERIA_REGDENSE_SPLITTERSSPARSE_SPLITTERS)_py_sort)
NODE_DTYPE	TREE_LEAFTREE_UNDEFINED_build_pruned_tree_py_check_n_classes_check_node_ndarray_check_value_ndarray)Tree)compute_sample_weight)assert_almost_equalassert_array_almost_equalassert_array_equalcreate_memmap_backed_dataignore_warningsskip_if_32bit)	_IS_32BITCOO_CONTAINERSCSC_CONTAINERSCSR_CONTAINERS)check_random_state)ginilog_loss)squared_errorabsolute_errorfriedman_msepoisson)r   r   )r   r   	ALL_TREES)r   r      r   r   r      ir   r   r   r   r   )r   r         r   r:   r   r   r9   皙?r   r8   r9   )r?   r   r         r   r    @r9   r   r   r@   r   r9   )r?   r?   r   g333333r   r   r   r   r   r   r>   r   r   r9   )r?   r?   r   r   r   r   r   r<   r   r   r   r   r   r9   )r?   r   r8   
   r8   r   皙	r   r8   r<   r:   r9   )zG @r         r      r   r   rE            ?r   rC   r9   )rF   r   rG   rH   r   rI   r   r   rE   rJ   r   r   rB   r9   )rF      rG   rH   r   rI   r   r   rE   rJ   r   r   rB   r9   )rF   rL   rG   rH   r   rI   r   r   rE   rJ   rK   r   r?   r   )   rL   r;   r9   rK   r:   rD   r   r9   r=   r<   r   rM   r   )rM   r   r9   r9   r9   r?   r9   r   r   rB   r<   r   r9   r   )rM   r   r9   rM   r<   r?   rD   rM   r   r?   r9   rM   rM   r   )r9   r9   r   rM   rM   r?   r9   rM   r   r=   r9   rM   r<   r   )r<   r9   r   r<   r   r:   rD   r   r9   r=   r<   r   r<   r9   )rF   rL   rG   rH   r   r9   r   r   rE   rJ   rK   r   rC   r9   )rF   rL   rG   rH   r   r9   r   r   rE   rJ         ?r9   r?   r?   )rF   rL   rG   rH   r   rD   r   r   rE   rJ   rK   r   r?   r?   )rM   r   r;   r9   rK   rB   rD   r   r9   r=   r<   r9   r   r?   )rM   r   r9   r9   r9   rB   r9   r   r   rB   r   r   r   r9   )rM   r9   r9   r9   rM   r?   rD   rM   r   r?   r   rM   r9   r9   )r9   r9   r   r   r9   rC   r9   rM   r   r=   r9   rM   r9   r9   )r<   r9   r   r9   r   r:   r9   r   r9   rB   r   r   r9   r   )r9   r9   r   r   r   r   r9   r9   r9   r9   r9   r9   r   r   r   r9   r   r   r9   r   r   r   r   )      ?rA   333333?皙?rD   g333333@@g)\(?{Gz?gףp=
@rR   g?        rP   rM   rI   r   r         @g|?5^?g(\??r   rB   r?   r9   rM   )r?   r?   r?   r9   r9   r9   r<   )r?   r9   r9      rD   )random_state	n_samples
n_features)   r;   sizerT   g?r8   )r[   r[   g      ?)densityrX   Xy)r[   r<   )irisdiabetesdigitstoy	clf_small	reg_small
multilabel
sparse-pos
sparse-neg
sparse-mixzerosc                 4   |j         | j         k    s)J d                    ||j         | j                               t          | j        |j        |dz              t          | j        |j        |dz              | j        t
          k    }t          j        |          }t          | j        |         |j        |         |dz              t          | j	        |         |j	        |         |dz              t          | j
                                        |j
                                        |dz              t          | j
        |j
        |dz              t          | j        |j        |dz   	           t          | j        |         |j        |         |d
z   	           d S )Nz({0}: inequal number of node ({1} != {2})z: inequal children_rightz: inequal children_leftz: inequal featuresz: inequal thresholdz: inequal sum(n_node_samples)z: inequal n_node_samplesz: inequal impurityerr_msgz: inequal value)
node_countformatr(   children_rightchildren_leftr   nplogical_notfeature	thresholdn_node_samplessumr&   impurityr'   value)dsmessageexternalinternals        \/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/tree/tests/test_tree.pyassert_tree_equalr      s   	$$$188q|  	%$$
 	!*G6P,P   	'4M*M   9,H~h''H		(QYx0'<P2P   	Hq{84g@U6U   		11  
 	!*G6P,P   
AJBV8VWWWW	178,g@Q6Q         c                     t                                           D ]\  } } |d          }|                    t          t                     t          |                    t                    t          d	                    |                       |dd          }|                    t          t                     t          |                    t                    t          d	                    |                      d S )Nr   rX   Failed with {0}r9   )max_featuresrX   )
	CLF_TREESitemsfitr`   ra   r(   predictTtrue_resultrq   namer$   clfs      r   test_classification_toyr      s    oo'' X X
dd"""13;;q>>;8I8P8PQU8V8VWWWd22213;;q>>;8I8P8PQU8V8VWWWWX Xr   c            
      ~   t                                           D ]!\  } } |d          }|                    t          t          t          j        t          t                                         t          |	                    t                    t          d                    |                      |                    t          t          t          j        t          t                    d                     t          |	                    t                    t          d                    |                      #d S )Nr   r   sample_weightr   rK   )r   r   r   r`   ra   rt   oneslenr(   r   r   r   rq   fullr   s      r    test_weighted_classification_toyr      s    oo'' X X
dd"""1BGCFFOO4443;;q>>;8I8P8PQU8V8VWWW1BGCFFC$8$89993;;q>>;8I8P8PQU8V8VWWWWX Xr   r$   	criterionc                 >   |dk    rgt          j        t          j        t                              dz   }t          j        t                    |z   }t          j        t
                    |z   }nt          }t
          } | |d          }|                    t          |           t          |	                    t                    |            | |dd          }|                    t          |           t          |	                    t                    |           d S )Nr6   r9   r   rX   r   r   rX   )rt   absminra   arrayr   r   r`   r   r   r   )r$   r   ay_trainy_testregr   s          r   test_regression_toyr     s     I F26!99!(1++/+&&*
$
3
3
3CGGAwCKKNNF+++
$
C
C
CCGGAwCKKNNF+++++r   c                     t          j        d          } d| d dd df<   d| dd dd f<   t          j        | j                  \  }}t          j        |                                |                                g          j        }|                                 } t                                          D ]\  }} |d          }|	                    ||            |
                    ||           dk    sJ d                    |                       |dd          }|	                    ||            |
                    ||           dk    sJ d                    |                      d S )	N)rD   rD   r9   r;   r   r   rO   r   rX   r   )rt   rl   indicesshapevstackravelr   r   r   r   scorerq   )ra   gridxgridyr`   r   r$   r   s          r   test_xorr     sb   
AAbqb"1"fIAabb!""fI:ag&&LE5
	5;;==%++--0113A			Aoo'' F F
dd"""1yyA#%%%'8'?'?'E'E%%%d2221yyA#%%%'8'?'?'E'E%%%%F Fr   c                     t          t                                          t                    D ]0\  \  } }} ||d          }|                    t
          j        t
          j                   t          |	                    t
          j                  t
          j                  }|dk    sJ d
                    | ||                       ||dd          }|                    t
          j        t
          j                   t          |	                    t
          j                  t
          j                  }|dk    sJ d
                    | ||                      2d S )Nr   r   rV   z0Failed with {0}, criterion = {1} and score = {2}rM   r   rK   )r   r   r   CLF_CRITERIONSr   rb   datatargetr   r   rq   )r   r$   r   r   r   s        r   	test_irisr   3  s*   #*9??+<+<n#M#M 
 
tidYQ777	4;'''s{{4955t{CCs{{{NUU)U
 
{{{ dYQQGGG	4;'''s{{4955t{CCs{{{NUU)U
 
{{{{
 
r   z
name, Treec                 8    ||d          }|                     t          j        t          j                   t	          t          j        |                    t          j                            }|t          j        d          k    sJ d|  d| d|             d S )Nr   r   zFailed with z, criterion = z and score = )r   rc   r   r   r   r   pytestapprox)r   r$   r   r   r   s        r   test_diabetes_overfitr   E  s    
 $
3
3
3CGGHM8?+++xHM0J0JKKEFM	    IdII)II%II    r   z&criterion, max_depth, metric, max_lossr3      <   r4   r5   r6   c                      |||dd          }|                     t          j        t          j                    |t          j        |                    t          j                            }d|cxk     r|k     sn J d S )NrJ   r   )r   	max_depthr   rX   )r   rc   r   r   r   )r   r$   r   r   metricmax_lossr   losss           r   test_diabetes_underfitr   R  s     $iaVW
X
X
XCGGHM8?+++6(/3;;x}#=#=>>Dthr   c            	      B   t                                           D ]\  } } |ddd          }|                    t          j        t          j                   |                    t          j                  }t          t          j	        |d          t          j
        t          j        j        d                   d                    |                      t          t          j        |d          |                    t          j                  d                    |                      t!          |                    t          j                  t          j        |                    t          j                            dd                    |                      d S )Nr9   *   r   r   rX   r   r   rn   rL   )r   r   r   rb   r   r   predict_probar'   rt   ry   r   r   rq   r(   argmaxr   r&   exppredict_log_proba)r   r$   r   prob_predicts       r   test_probabilityr   g  sg     oo'' 
 

ddQQR@@@	4;'''((33!F<##GDIOA&''%,,T22	
 	
 	
 	

 	IlA&&KK	""%,,T22	
 	
 	
 	

 	di((F3((3344%,,T22		
 	
 	
 	
 	

 
r   c                     t          j        d          d d t           j        f         } t          j        d          }t                                          D ](\  }} |d d          }|                    | |           )d S )Ni'  r   r   rX   )rt   arangenewaxis	REG_TREESr   r   r`   ra   r   r$   r   s        r   test_arrayreprr     s     		%BJ'A
	%Aoo''  
ddT2221 r   c                     ddgddgddgddgddgddgg} g d}t                                           D ]_\  }} |d          }|                    | |           t          |                    |           |d                    |          	           `t                                          D ]_\  }} |d          }|                    | |           t          |                    |           |d                    |          	           `d S )
NrB   r?   r9   rM   )r9   r9   r9   r9   r9   r9   r   r   r   rn   )r   r   r   r(   r   rq   r   r&   )r`   ra   r   TreeClassifierr   TreeRegressorr   s          r   test_pure_setr     s,   
bB8b"X1v1v1v>AA ) 1 1 V Vnn!,,,13;;q>>16G6N6Nt6T6TUUUUU(00 W Wmm+++1CKKNNA7H7O7OPT7U7UVVVVVW Wr   c            
         t          j        g dg dg dg dg dg dg dg          } t          j        g d          }t          j        d	
          5  t                                          D ]m\  }} |d          }|                    | |           |                    | |            |                    |  |           |                    |  |            n	 d d d            d S # 1 swxY w Y   d S )N)gs_c@d	a@籛 `8`@?c@)g_9a@g 8`@g-Vu]@g    @Xd@)gSW j_@r   r   r   )g ً`@4Ta@	lKa@{c@)g|@Y@g~G`a@gwI?lKa@g/"c@)g_@r   r   r   )g:^@r   r   r   )rO   gAw?gtQ?5??rT   g7G?gۺ?gb'?raise)allr   r   )rt   r   errstater   r   r   r   s        r   test_numerical_stabilityr     sh   
DDDDDDDDDDDDDDDDDDDDD	

	 
	A 	WWWXXA		!	!	!  #//++ 	 	JD$$A&&&CGGAqMMMGGArNNNGGQBNNNGGQBOOOO	                 s   BC++C/2C/c            	         t          j        ddddddd          \  } }t                                          D ]\  }} |d          }|                    | |           |j        }t          j        |dk              }|j        d         dk    sJ d		                    |                      |dk    sJ d		                    |                      t          d          }|                    t          j        t          j                   t          dt          t          j                  
          }|                    t          j        t          j                   t          |j        |j                   d S )N  rD   r<   r   FrY   rZ   n_informativen_redundant
n_repeatedshufflerX   r   皙?r   rX   max_leaf_nodes)r   make_classificationr   r   r   feature_importances_rt   ry   r   rq   r   rb   r   r   r   r(   )r`   ra   r   r$   r   importancesn_importantclf2s           r   test_importancesr     se   '  DAq  oo'' @ @
dd"""1.f[3.// #r)))+<+C+CD+I+I)))a!2!9!9$!?!? !a
0
0
0CGGDIt{###!qTYPPPDHHTY$$$s/1JKKKKKr   c                      t                      } t          j        t                    5  t	          | d           d d d            d S # 1 swxY w Y   d S )Nr   )r   r   raises
ValueErrorgetattr)r   s    r   test_importances_raisesr     s    
 
"
"C	z	"	" - -+,,,- - - - - - - - - - - - - - - - - -s   AA
A
c            	      .   t          j        ddddddd          \  } }t          ddd	                              | |          }t	          d
dd	                              | |          }t          |j        |j                   t          |j        j	        |j        j	                   t          |j        j
        |j        j
                   t          |j        j        |j        j                   t          |j        j        |j        j                   d S )Ni  rD   r<   r   Fr   r1   r;   )r   r   rX   r3   )r   r   r   r   r   r&   r   r(   tree_rv   rs   rr   rx   )r`   ra   r   r   s       r   )test_importances_gini_equal_squared_errorr     s    '  DAq !6QQ
O
O
O
S
S	1 C  !QQ  	c!Qii  0#2JKKKsy(#)*;<<<sy.	0GHHHsy/1IJJJsy/1IJJJJJr   c                     t                                           D ]\  } } |d          }|                    t          j        t          j                   |j        t          t          j	        t          j        j
        d                             k    sJ  |d          }|                    t          j        t          j                   |j        t          t          j        t          j        j
        d                             k    sJ  |d          }|                    t          j        t          j                   |j        dk    sJ  |d          }|                    t          j        t          j                   |j        dk    sJ  |d          }|                    t          j        t          j                   |j        dk    sJ  |d          }|                    t          j        t          j                   |j        t          dt          j        j
        d         z            k    sJ  |d          }|                    t          j        t          j                   |j        t          j        j
        d         k    sJ  |d           }|                    t          j        t          j                   |j        t          j        j
        d         k    sJ d S )	Nsqrt)r   r9   log2r<   rS   rK   rO   )r7   r   r   rb   r   r   max_features_intrt   r   r   r   )r   TreeEstimatorests      r   test_max_featuresr     s{   (00 7 7mm000	4;''' C	0B(C(C$D$DDDDDm000	4;''' C	0B(C(C$D$DDDDDm+++	4;''' A%%%%m+++	4;''' A%%%%m...	4;''' A%%%%m---	4;''' Cdioa.@(@$A$AAAAAm---	4;''' DIOA$66666m...	4;''' DIOA$666666?7 7r   c                  z
   t                                           D ]r\  } } |            }t          j        t                    5  |                    t                     d d d            n# 1 swxY w Y   |                    t          t                     g dg}t          j        t                    5  |                    |           d d d            n# 1 swxY w Y    |            }t          d d         }t          j        t                    5  |                    t          |           d d d            n# 1 swxY w Y   t          j        t                    } |            }|                    |t                     t          |                    t                    t                      |            }t          j        t                    5  |                    t                     d d d            n# 1 swxY w Y   |                    t          t                     t          j        t                    }t          j        t                    5  |                    |d d dd f                    d d d            n# 1 swxY w Y   t          j        t                    j        } |            }|                    t          j        t          |          t                     t          j        t                    5  |                    t                     d d d            n# 1 swxY w Y   t          j        t                    5  |                    t                     d d d            n# 1 swxY w Y    |            }|                    t          t                     t          j        t                    5  |                    |           d d d            n# 1 swxY w Y   t          j        t                    5  |                    |           d d d            n# 1 swxY w Y    |            }t          j        t                    5  |                    t                     d d d            n# 1 swxY w Y   tt)          d          }t          j        t          d          5  |                    g dgg d	           d d d            n# 1 swxY w Y   t          j        t          d
          5  |                    g dgg d           d d d            d S # 1 swxY w Y   d S )N)rB   r?   r9   r?   r9   r6   r   zy is not positive.*Poissonmatchr   r9   rM   )r   r   r   zSome.*y are negative.*Poisson)r;   grM   )r   r   r   r   r   r   r`   r   ra   r   rt   asfortranarrayr&   r   r   r   asarrayr   dotapplyr   )	r   r   r   X2y2XftXtr   s	            r   
test_errorr    s   (00 6 6mmoo]>** 	! 	!a   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	1kk]]:&& 	" 	"b!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" moossV]:&& 	 	GGArNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 q!!mooACKKNNK888 moo]>** 	 	KKNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	1JqMM]:&& 	" 	"KK!!!QRR%!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" Xa[[]mooq"q!!!]:&& 	 	KKNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]:&& 	 	IIaLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 moo1]:&& 	 	KKOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]:&& 	 	IIbMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 moo]>** 	 	IIaLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  )
4
4
4C	z)E	F	F	F ( (YYY'''( ( ( ( ( ( ( ( ( ( ( ( ( ( (	z)H	I	I	I + +\\\***+ + + + + + + + + + + + + + + + + +s   A**A.	1A.	3CC	C	D::D>	D>	G::G>	G>	"JJ		J		L++L/	2L/	M66M:	=M:	O&&O*	-O*	
P,,P0	3P0	RR	R	9S!!S%(S%T00T47T4c                     t          j        t          j        t          j        j                  } t          j        }t          dt          
                                          D ]\  }}t          |         } |d|d          }|                    | |           |j        j        |j        j        dk             }t          j        |          dk    sJ d                    |                       |d	|d          }|                    | |           |j        j        |j        j        dk             }t          j        |          dk    sJ d                    |                      d
S )z Test min_samples_split parameterdtypeN  rD   r   )min_samples_splitr   rX   r?   	   r   r>   N)rt   r  rb   r   r	   _treeDTYPEr   r   r7   keysr   r   rx   rs   r   rq   )r`   ra   r   r   r   r   node_sampless          r   test_min_samples_splitr  _  sc   
$)4:+;<<<AA !(inn6F6F G G H H!$ m a
 
 
 	1y/	0G20MNvl##a'''):)A)A$)G)G''' m!.q
 
 
 	1y/	0G20MNvl##a'''):)A)A$)G)G''''+H Hr   c                  @   t          j        t          j        t          j        j                  } t          j        }t          dt          
                                          D ]9\  }}t          |         } |d|d          }|                    | |           |j                            |           }t          j        |          }||dk             }t          j        |          dk    sJ d                    |                       |d|d          }|                    | |           |j                            |           }t          j        |          }||dk             }t          j        |          dk    sJ d                    |                      ;d S )	Nr  r  r;   r   )min_samples_leafr   rX   r8   r   r   )rt   r  rb   r   r	   r  r  r   r   r7   r  r   r   r  bincountr   rq   )	r`   ra   r   r   r   r   outnode_counts
leaf_counts	            r   test_min_samples_leafr   ~  s   
$)4:+;<<<AA !(inn6F6F G G F F!$ m~A
 
 
 	1iooa  k#&& !12
vj!!A%%%'8'?'?'E'E%%% m a
 
 
 	1iooa  k#&& !12
vj!!A%%%'8'?'?'E'E%%%%/F Fr   c                 <   t           |         d                             t          j                  }| ||          }t           |         d         }t                              |j        d                   }t          j        |          }t          |          }t          dt          j
        ddd                    D ]\  }}	 ||	|d          }
|
                    |||	           |-|
j                            |                                          }n|
j                            |          }t          j        ||
          }||dk             }t          j        |          ||
j        z  k    s#J d                    | |
j                              |j        d         }t          dt          j
        ddd                    D ]\  }}	 ||	|d          }
|
                    ||           |-|
j                            |                                          }n|
j                            |          }t          j        |          }||dk             }t          j        |          ||
j        z  k    s#J d                    | |
j                              dS )zPTest if leaves contain at least min_weight_fraction_leaf of the
    training setr`   Nra   r   r  rK   rJ   )min_weight_fraction_leafr   rX   r   )weightsz,Failed with {0} min_weight_fraction_leaf={1})DATASETSastypert   float32rngrandr   ry   r7   r   linspacer   r   r  tocsrr  r   r"  rq   )r   r   sparse_containerr`   ra   r#  total_weightr   r   fracr   r  node_weightsleaf_weightss                 r   check_min_weight_fraction_leafr0    s    	3&&rz22A#Q3Ahhqwqz""G6'??LdOM !(bk!S!6L6L M M 
 
m%).WX
 
 
 	1G,,,')//!'')),,CC)//!$$C{3888#LA$56F<  L33O$OOOO9@@#.
 
 POOO 71:L 'bk!S!6L6L M M 
 
m%).WX
 
 
 	1')//!'')),,CC)//!$$C{3''#LA$56F<  L33O$OOOO9@@#.
 
 POOO
 
r   r   c                 &    t          | d           d S Nrb   r0  r   s    r   ,test_min_weight_fraction_leaf_on_dense_inputr5    s    "400000r   csc_containerc                 *    t          | d|           d S Nrh   )r+  r3  r   r6  s     r   -test_min_weight_fraction_leaf_on_sparse_inputr:    s     #4VVVVVVr   c                 &   t           |         d                             t          j                  }| ||          }t           |         d         }|j        d         }t
          |          }t          dt          j        ddd                    D ]\  }} |||dd	          }	|	                    ||           |-|	j	        
                    |                                          }
n|	j	        
                    |          }
t          j        |
          }||dk             }t          j        |          t          ||	j        z  d          k    s)J d
                    | |	j        |	j                              t          dt          j        ddd                    D ]\  }} |||dd	          }	|	                    ||           |-|	j	        
                    |                                          }
n|	j	        
                    |          }
t          j        |
          }||dk             }t          j        |          t          ||	j        z  ||	j        z            k    s)J d
                    | |	j        |	j                              dS )zzTest the interaction between min_weight_fraction_leaf and
    min_samples_leaf when sample_weights is not provided in fit.r`   Nra   r   r  rK   r<   r;   )r"  r   r  rX   zBFailed with {0} min_weight_fraction_leaf={1}, min_samples_leaf={2}r   )r$  r%  rt   r&  r   r7   r   r)  r   r   r  r*  r  r   maxr"  rq   r  )r   r   r+  r`   ra   r,  r   r   r-  r   r  r.  r/  s                r   4check_min_weight_fraction_leaf_with_min_samples_leafr=    s   
 	3&&rz22A#Q3A71:LdOM 'bk!S!6L6L M M 
 
m%))	
 
 
 	1')//!'')),,CC)//!$$C{3''#LA$56vl##sC881(
 (
 
 
 
OVV#.0D
 

 
 
 

 !(bk!S!6L6L M M 
 
m%)) 	
 
 
 	1')//!'')),,CC)//!$$C{3''#LA$56vl##sC88C00(
 (
 
 
 
 PVV#.0D
 

 
 
 
%
 
r   c                 &    t          | d           d S r2  r=  r4  s    r   Btest_min_weight_fraction_leaf_with_min_samples_leaf_on_dense_inputr@  "  s    8vFFFFFr   c                 *    t          | d|           d S r8  r?  r9  s     r   Ctest_min_weight_fraction_leaf_with_min_samples_leaf_on_sparse_inputrB  '  s,    
 9l]     r   c                 $   t          j        d|           \  }}t          dt                                                    D ]\  }}t          |         } ||d          } ||dd          } ||dd          } ||d	d          }	|d
f|df|df|	d	ffD ]s\  }
}|
j        |k    s#J d                    |
j        |                      |
                    ||           t          |
j	        j
                  D ]}|
j	        j        |         t          k    r|
j	        j        |         }|
j	        j        |         }|
j	        j        |         }|
j	        j        |         }|
j	        j        |         }||z  }|
j	        j        |         }|
j	        j        |         }|
j	        j        |         }||z  }||z   }||z  }|
j	        j        |         |j        d         z  }|||z
  z  }||k    sJ d                    ||                      ud S )Nd   rY   rX   r  r   r   rX   rQ   )r   min_impurity_decreaserX   g-C6?r   gHz>z)Failed, min_impurity_decrease = {0} > {1}z2Failed with {0} expected min_impurity_decrease={1})r   r   r   r7   r  rG  rq   r   ranger   rp   rs   r   rz   weighted_n_node_samplesrr   r   )global_random_seedr`   ra   r   r   r   est1est2est3est4r   expected_decreasenode
imp_parent
wtd_n_nodeleft
wtd_n_leftimp_leftwtd_imp_leftrightwtd_n_right	imp_rightwtd_imp_rightwtd_avg_left_right_impfractional_node_weightactual_decreases                             r   test_min_impurity_decreaser^  1  s    '#DVWWWDAq !(inn6F6F G G > >!$ }NKKK})TU
 
 
 })VW
 
 
 })ST
 
 

 4L4L6N3K	'
 ,	 ,	"C" )->>>>:AA)+<  ?>> GGAqMMMci233     9*40I==!$!3D!9J!$!B4!HJ9248D!$!B4!HJ"y1$7H#-#8LI4T:E"%)"CE"JK #	 25 9I$/)$;M-:\-I**j8* 	9$?!'!*L + '="%;;'O
 (+<<<<KRR'):  =<<; ,	%> >r   c            
         t                                           D ]6\  } }d| v rt          j        t          j        }}nt
          j        t
          j        }} |d                              ||                               ||          }g d}fd|D             }t          j	                  }t          j
        |          }t          |          j        k    sJ |                    ||          }	||	k    sJ d                    |                       |D ]3}
t          t          |j        |
          ||
         d|
 d|  	           48d
S )z8Test pickling preserves Tree properties and performance.
Classifierr   r   )r   rp   capacity	n_classesrs   rr   n_leavesrv   rw   rz   rx   rI  r{   c                 <    i | ]}|t          j        |          S  )r   r   ).0	attributer   s     r   
<dictcomp>ztest_pickle.<locals>.<dictcomp>  s4     
 
 
9BIwsy)44
 
 
r   z6Failed to generate same score  after pickling with {0}z"Failed to generate same attribute z after pickling with rn   N)r7   r   rb   r   r   rc   r   r   pickledumpsloadstype	__class__rq   r(   r   r   )r   r   r`   ra   r   
attributesfitted_attributeserialized_objectrL  score2rg  r   s              @r   test_picklerr  y  s   (00 . .m49dkqAA=(/qAm+++1		!Q
 
 


 
 
 
FP
 
 
 #L--|-..DzzS]****Aq!!VOOOCJJ4PP OO) 	 	I
I.. +   	    	M. .r   c                     ddgddgddgddgddgddgddgddgddgddgddgddgg} ddgddgddgddgddgddgddgddgddgddgddgddgg}ddgddgddgddgg}ddgddgddgddgg}t                                           D ]\  }} |d          }|                    | |                              |          }t	          ||           |j        dk    sJ |                    |          }t          |          dk    sJ |d         j        dk    sJ |d         j        d	k    sJ |                    |          }	t          |	          dk    sJ |	d         j        dk    sJ |	d         j        d	k    sJ t                                          D ]W\  }}
 |
d          }|                    | |                              |          }t          ||           |j        dk    sJ Xd S )
NrB   r?   r9   rM   r   r<   r   r8   rM   )r8   r8   )r   r   r   r   r(   r   r   r   r   r   r&   )r`   ra   r   y_truer   r   r   y_hatproba	log_probar   r   s               r   test_multioutputry    s    
R	R	R	
A	
A	
A	Q	Q	Q	
B	
B	
B	A  
Q	Q	Q	
A	
A	
A	Q	Q	Q	
A	
A	
A	A bAq6B7QG,A1g1vAwA/F !* 1 1 , ,nn!,,,1%%a((5&))){f$$$$!!!$$5zzQQx~''''Qx~''''))!,,	9~~""""|!V++++|!V+++++  )00 % %mm+++1%%a((E6***{f$$$$$	% %r   c                  v   t                                           D ]\  } } |d          }|                    t          t                     |j        dk    sJ t          |j        ddg           t          j	        t          t          j
        t                    dz  f          j        } |d          }|                    t          |           t          |j                  dk    sJ t          |j                  dk    sJ t          |j        ddg           t          |j        ddgddgg           d S )Nr   r   rM   r?   r9   rB   )r   r   r   r`   ra   
n_classes_r(   classes_rt   r   r   r   r   )r   r   r   _ys       r   test_classes_shaper~    s,    ) 1 1 = =nn!,,,1~""""3<"a111 Y28A;;?+,,.n!,,,23>""a''''3<  A%%%%3>Aq62223<2q'B7);<<<<= =r   c                  B   t           j        d d         } t           j        d d         }t          d|          }t                                          D ]L\  }} |d          }|                    | ||           t          |                    |           |           Md S )N}   balancedr   r   r   )	rb   r   r   r%   r   r   r   r&   r   )unbalanced_Xunbalanced_yr   r   r   r   s         r   test_unbalanced_irisr    s    9TcT?L;tt$L)*lCCM ) 1 1 E Enn!,,,l-HHHCKK55|DDDDE Er   c                  D   t          t                                          t          j        t          j        g          D ]\  \  } }} |d          }t          j        t          j        |          }t          j	        }t          |                    ||                              |          |           t          j        t          j        d|          }t          j	        }t          |                    ||                              |          |           t          j        t          j        d|          }t          j	        }t          |                    ||                              |          |           t          j        t          j        |          }t          j	        }t          |                    ||                              |          |           t          D ]\} |t          j        |          }t          j	        }t          |                    ||                              |          |           ]t          D ]\} |t          j        |          }t          j	        }t          |                    ||                              |          |           ]t          j        t          j        d d d         |          }t          j	        d d d         }t          |                    ||                              |          |           d S )Nr   r   r  C)orderr  Fr<   )r   r7   r   rt   float64r&  r  rb   r   r   r(   r   r   ascontiguousarrayr/   r.   )r   r   r  r   r`   ra   csr_containerr6  s           r   test_memory_layoutr    s   (/BJ
3) ) (8 (8$}u m+++ Jty...K3771a==0033Q777 Jty5999K3771a==0033Q777 Jty5999K3771a==0033Q777  %888K3771a==0033Q777 , 	< 	<Mdiu555AAswwq!}}44Q77;;;; , 	< 	<Mdiu555AAswwq!}}44Q77;;;; Jty1~U333K!3771a==0033Q7777Q(8 (8r   c                     t          j        d          d d t           j        f         } t          j        d          }d|d d<   t          j        d          }d||dk    <   t	          d          }|                    | ||           t          |                    |           t          j        d                     t          j        d          d d t           j        f         } t          j        d          }d|dd<   d	|dd<   d| dddf<   t          j        d          }d
||d	k    <   t	          dd          }|                    | ||           |j	        j
        d         dk    sJ d||d	k    <   t	          dd          }|                    | ||           |j	        j
        d         dk    sJ t          j        } t          j        }t                              d| j        d         d          }t	          d          }|                    | |         ||                    t          j        || j        d                   }t	          d          }|                    | ||           |j	        j        t&          j        j        k    }t-          |j	        j
        |         |j	        j
        |                    d S )NrD  rT   2   r   r   r      r9   rM   gRQ?r   g     b@rK   g     H@)	minlength)rt   r   r   r   r   r   r(   r   rl   r   rw   rb   r   r   r'  randintr   r  rs   r	   r  r   r'   )r`   ra   r   r   
duplicatesr   r   s          r   test_sample_weightr  5  s    		#qqq"*}%A
AAcrcFGCLLMM!q&
 a
0
0
0CGGAqG...s{{1~~rws||444 		#qqq"*}%A
AAbfIAc#gJAc#gqjMGCLLM M!q&
 11
=
=
=CGGAqG...9q!U****M!q&
 11
=
=
=CGGAqG...9q!T)))) 		AAQ
C00J
 a
0
0
0CGGAjM1Z=)))K
agajAAAM!q111DHHQH///y&$**>>H	H%tz';H'E    r   c                  f   t          j        d          d d t           j        f         } t          j        d          }d|d d<   t	          d          }t           j                            dd          }t          j        t                    5  |
                    | ||           d d d            n# 1 swxY w Y   t          j        d          }t          j        d          }t          j        t          |	          5  |
                    | ||           d d d            d S # 1 swxY w Y   d S )
NrD  rT   r  r   r   r9   r   zgInput should have at least 1 dimension i.e. satisfy `len(x.shape) > 0`, got scalar `array(0.)` instead.r  )rt   r   r   r   r   randomr(  r   r   r   r   r   reescape	TypeError)r`   ra   r   r   expected_errs        r   test_sample_weight_invalidr  i  s   
	#qqq"*}%A
AAcrcF
 a
0
0
0CINN3**M	z	"	" 3 31M2223 3 3 3 3 3 3 3 3 3 3 3 3 3 3 HQKKM9B L 
y	5	5	5 3 31M2223 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3s$   B22B69B6 D&&D*-D*c                    t           |          } |d          }|                    t          j        t          j                    |dd          }|                    t          j        t          j                   t          |j        |j                   t          j        t          j        t          j        t          j        f          j	        } |ddddddddddddgd          }|                    t          j        |           t          |j        |j                    |dd          }|                    t          j        |           t          |j        |j                   t          j
        t          j        j                  }|t          j        dk    xx         d	z  cc<   dd
dd} |d          }|                    t          j        t          j        |            ||d          }|                    t          j        t          j                   t          |j        |j                    |d          }|                    t          j        t          j        |dz              ||d          }|                    t          j        t          j        |           t          |j        |j                   d S )Nr   r   r  class_weightrX   g       @rO   r  r9   rD  g      Y@rM   )r   r   rb   r   r   r&   r   rt   r   r   r   r   )	r   r   clf1r   
iris_multiclf3clf4r   r  s	            r   test_class_weightsr    s    t_N >q)))DHHTY$$$>zBBBDHHTY$$$143LMMM DKdkBCCEJ>$$$$$$

   D 	HHTY
###143LMMM>zBBBDHHTY
###143LMMM GDK-..M$+"###s*###u--L>q)))DHHTY]333>|!DDDDHHTY$$$143LMMM >q)))DHHTY]A%5666>|!DDDDHHTY]333143LMMMMMr   c                 X   t           |          }t          j        t          t          j        t                    dz  f          j        } |dddgd          }d}t          j        t          |          5  |	                    t          |           d d d            d S # 1 swxY w Y   d S )	NrM   rK   rO   r?   r9   r   r  zBnumber of elements in class_weight should match number of outputs.r  )r   rt   r   ra   r   r   r   r   r   r   r`   )r   r   r}  r   ro   s        r   test_class_weight_errorsr    s     t_N	Arx{{Q'	(	(	*B .CC'8'8&9
J
J
JCRG	z	1	1	1  2                 s   6BB#&B#c                      t          j        dd          \  } }d}t                                          D ]F\  }} |d |dz                                 | |          }|                                |dz   k    sJ Gd S NrD  r9   rE  r8   )r   r   )r   make_hastie_10_2r7   r   r   get_n_leavesr`   ra   kr   r   r   s         r   test_max_leaf_nodesr    s    $sCCCDAq	A(00 + +mmd1q5AAAEEaKK!!QU*****+ +r   c                      t          j        dd          \  } }d}t                                          D ]@\  }} |d|                              | |          }|                                dk    sJ Ad S r  )r   r  r7   r   r   	get_depthr  s         r   test_max_leaf_nodes_max_depthr    s    $sCCCDAq	A(00 $ $mma:::>>q!DD}}!#####$ $r   c                      dD ]a} t          t                                          dgdggddg          j        |           }d|j        d         cxk    rdk     sn J d            bd S )N)rb  r{   rs   rr   rw   rz   rv   rx   r   r9   rC   r<   z Array points to arbitrary memory)r   r   r   r   flat)attrr{   s     r   test_arrays_persistr    s    	 K K .0044qcA3Z!QHHNPTUUUZ]&&&&Q&&&&&(J&&&&K Kr   c                      t          d          } t          j        d          }|                     ddd          }t                                          D ]9\  }} |d          }|                    ||           |j        j        dk    sJ :d S )Nr   )rD   r[   rM   )rD   r   )	r0   rt   rl   r  r7   r   r   r   r   )rX   r`   ra   r   r   r   s         r   test_only_constant_featuresr    s    %a((L
AQ5))A(00 ( (mm+++1y"a'''''( (r   c                  \   t          j        t          j        g dgt          j        d          f                    } g d}t                                          D ]P\  }}d|vrG |dd          }|                    | |           |j        j        dk    sJ |j        j	        d	k    sJ Qd S )
N)r   r   r   r   r   r9   rM   r8   r;   rJ      )r8   rI   )r   r   r   r9   r9   rM   rM   rM   r<   r<   r<   	ExtraTreer   r9   r   rM   r;   )
rt   	transposer   rl   r7   r   r   r   r   rp   r`   ra   r   r   r   s        r   ,test_behaviour_constant_feature_after_splitsr    s    

	55568I8IJKK	 	A 	*))A(00 - -md""-QQ???CGGAqMMM9&!++++9'1,,,,- -r   c                     t          j        t          j        dgdgdgdgg          t          j        d          g          } t          j        g d          }t                                          D ]p\  }} |dd          }|                    | |           |j        j        dk    sJ t          |
                    |           t          j        dd	                     qt                                          D ]p\  }} |dd          }|                    | |           |j        j        dk    sJ t          |                    |           t          j        d
d	                     qd S )NrO   rT   )r8   r  )rT   rO   rT   rO   r   r9   r   rt  rK   )r8   )rt   hstackr   rl   r   r   r   r   r   r(   r   r   r   r   r  s        r   (test_with_only_one_non_constant_featuresr    se   
	28cUSEC53%89928I;N;NOPPA
%%%&&A(00 G Gmm;;;1y"a''''3,,Q//1E1EFFFF(00 ? ?mm;;;1y"a''''3;;q>>274+=+=>>>>	? ?r   c                  F   t          j        dd                              t           j                                      dd          } t                      }t          j        t          d          5  |	                    | g d           d d d            d S # 1 swxY w Y   d S )Ng\)c=Hr8   r?   r9   r&  r  )r   r9   r   r9   )
rt   repeatr%  r  reshaper   r   r   r   r   )r`   r   s     r   test_big_inputr    s    
	(A%%bj1199"a@@A
 
"
"C	z	3	3	3 ! !<<<   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !s   0BBBc                      ddl m}  t          j        t                    5   |              d d d            d S # 1 swxY w Y   d S )Nr   _realloc_test)sklearn.tree._utilsr  r   r   MemoryErrorr  s    r   test_reallocr    s    111111	{	#	#                   s   8<<c                  >   dt          j        d          z  } t          j                            dd          }t          j                            ddd          }d| dz   z  }t          d|          }t          j        t                    5  |
                    ||           d d d            n# 1 swxY w Y   d| dz
  z  dz
  }t          d|          }t          j        t                    5  |
                    ||           d d d            d S # 1 swxY w Y   d S )	NrL   PrD   rM   r   r9   best)splitterr   )structcalcsizert   r  randnr  r   r   r   	Exceptionr   r  )n_bitsr`   ra   huger   s        r   test_huge_allocationsr    s   %%%F
	AA
	!Q##A !D
 &
F
F
FC	y	!	!  1              
 !q D
 &
F
F
FC	{	#	#  1                 s$   B..B25B2.DDDc                    t           |          }t          |         d         }t          |         d         }|dv r$|j        d         dz  }|d |         }|d |         }t          t          z   t
          z   D ]i} ||          } |d|                              ||          }	 |d|                              ||          }
t          |	j        |
j        d	                    |                      |	
                    |          }| t          v r*|	                    |          }|	                    |          }t          t
          z   t          z   D ]} ||t          j                  }t!          |

                    |          |           | t          v rFt!          |
                    |          |           t!          |
                    |          |           kd S )	Nr`   ra   )rd   rc   r   r;   rX   r   5{0} with dense and sparse format gave different treesr  )r7   r$  r   r-   r.   r/   r   r   r   rq   r   r   r   r   rt   r&  r'   )r	   datasetr   r   r`   ra   rY   r+  X_sparser|   r}   y_predy_probay_log_probasparse_container_testX_sparse_tests                   r   check_sparse_inputr  /  s   dOM#A#A (((GAJ!O	jyjMjyjM*^;nL  ##A&& MqI>>>BB1aHHMqI>>>BB8QOOGGCJJ4PP	
 	
 	
 19ooa((G--a00K%3n%D~%U 		 		!11("*MMMM%aii&>&>GGGy  )!//-*H*H'RRR)''66  		% r   	tree_typer  )rf   re   rd   rh   ri   rj   rk   rl   c                 <    |dk    rdnd }t          | ||           d S )Nrd   r<   r  )r  r  r   s      r   test_sparse_inputr  X  s/     ((dIy'955555r   rc   rg   c                 (    t          | |d           d S )NrM   r  )r  r  s     r   test_sparse_input_reg_treesr  k  s    
 y'1-----r   )ri   rj   rk   rl   c                    t           |          }t          |         d         } ||          }t          |         d         } |ddd                              ||          } |ddd                              ||          }t          |j        |j        d                    |                      t          |                    |          |                    |                      |ddd	                              ||          } |ddd	                              ||          }t          |j        |j        d                    |                      t          |                    |          |                    |                      |d|j        d         dz  
                              ||          } |d|j        d         dz  
                              ||          }t          |j        |j        d                    |                      t          |                    |          |                    |                      |dd                              ||          } |dd                              ||          }t          |j        |j        d                    |                      t          |                    |          |                    |                     d S )Nr`   ra   r   r9   rM   )rX   r   r   r  rD   )rX   r   r  )rX   r  r<   r   )	r7   r$  r   r   r   rq   r'   r   r   )	r  r  r6  r   r`   r  ra   r|   r}   s	            r   test_sparse_parametersr  s  s    i(M#A}QH#A 	11BBBFFq!LLA11BBBFFxQRSSA		?FFyQQ  
 aiillAIIaLL999 	11KKKOOPQSTUUA11KKKOO!	 	A 		?FFyQQ  
 aiillAIIaLL999 	1x~a7HA7MNNNRRSTVWXXA1x~a7HA7MNNNRR!	 	A 		?FFyQQ  
 aiillAIIaLL999 	1Q777;;AqAAA1Q777;;HaHHA		?FFyQQ  
 aiillAIIaLL99999r   ztree_type, criterionc                 $    g | ]}|t           v |S re  )r   rf  r	   s     r   
<listcomp>r    s"    EEE4493D3D$3D3D3Dr   c                 $    g | ]}|t           v |S re  )r   r  s     r   r  r    s"    DDD$$)2C2C2C2C2Cr   c                    t           |          }t          |         d         } ||          }t          |         d         } |dd|                              ||          } |dd|                              ||          }	t          |j        |	j        d                    |                      t          |	                    |          |                    |                     d S )Nr`   ra   r   r<   rX   r   r   r  )r7   r$  r   r   r   rq   r'   r   )
r  r  r6  r   r   r`   r  ra   r|   r}   s
             r   test_sparse_criteriar    s     i(M#A}QH#A1YGGGKKAqQQA1YGGGKKHVWXXA		?FFyQQ  
 aiillAIIaLL99999r   zcsc_container,csr_containerc                 
   t           |          }d}d}|}t          j        |          }t          d          }g }	g }
d}|g}t	          |          D ]}|                    |d          }|                    |          d |         }|	                    |           |                    dd|f          dz
  }|
                    |           ||z  }|                    |           t          j        |	          	                    t          j
                  }	t          j        |t          j
                  }t          j        t          j        |
          t          j                  }
 ||
|	|f||f          }|                                } ||
|	|f||f          }|                                }|                    dd|f          }|                                }|j        d	k                                    dk    sJ |j        d	k                                    dk    sJ  |d|
                              ||          } |d|
                              ||          }t'          |j        |j        d                    t,                               ||f}t/          ||          D ]N\  }}t1          |j                            |          |j                            |                     t1          |                    |          |                    |                     t1          |                    |          |j                            |                     t1          |j                            |                                          |j                            |                                                     t1          |                    |                                          |                    |                                                     t1          |                    |                                          |j                            |                                                     t1          |                    |          |                    |                     t,          t8          v r6t1          |                    |          |                    |                     Pd S )Nr<   rD   r   rK   r\   r9   r  r   rT   r  r  )r7   rt   r   r0   rH  binomialpermutationappendconcatenater%  int32r   r&  toarrayr  copyr   ry   r   r   r   rq   r	   r   r'   r  decision_pathr   r   r   )r  r6  r  r   r   rZ   rY   samplesrX   r   r   offsetindptrin_nonzero_i	indices_idata_ir  r`   r  X_testra   r|   r}   XsX1r  s                              r   test_explicit_sparse_zerosr    s   
 i(MIJ Ii	""G &a((LGDFXF:  "++Is;; ,,W55l{lC	y!!!&&q#[N&CCaGF+fnW%%,,RX66GXfBH---F8BN4((
;;;D}dGV4Y
<STTTHA!M	w	:'>  M ""$$FQ55A "&&((M MS %%''!++++#%**,,q0000 	1	:::>>q!DDA1	:::>>xKKA		?FFtLL   -	 B"b// P PB!!'--"3"3QW]]25F5FGGG!!''"++qwwr{{;;;!!''"++qw}}R/@/@AAA!G!!"%%--//1F1Fr1J1J1R1R1T1T	
 	
 	
 	"OOB''))1??2+>+>+F+F+H+H	
 	
 	
 	"OOB''))17+@+@+D+D+L+L+N+N	
 	
 	
 	"!))B--2???9%aoob&9&91??2;N;NOOO%P Pr   c                 P   t           |          }t          j        d d df                                         }t          j        d d df                             d          }t          j        }t          j        t                    5   |d          	                    ||           d d d            n# 1 swxY w Y    |d          }|	                    ||           t          j        t                    5  |
                    |g           d d d            d S # 1 swxY w Y   d S )Nr   r  r   )r7   rb   r   r   r  r   r   r   r   r   r   )r   r   r`   X_2dra   r   s         r   check_raise_error_on_1d_inputr    s   dOM	!!!Q$A9QQQT?""7++DA	z	"	" 0 01%%%))!Q///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -Q
'
'
'CGGD!	z	"	"  QC                 s$   !B11B58B57DD"Dc                 r    t                      5  t          |            d d d            d S # 1 swxY w Y   d S N)r*   r  r4  s    r   test_1d_inputr  "  s    			 , ,%d+++, , , , , , , , , , , , , , , , , ,s   ,00r+  c                 `   t           |          }t          j        dgdgdgdgdgg          }g d}g d}| ||          } |d          }|                    |||           |j        j        dk    sJ  |dd          }|                    |||           |j        j        dk    sJ d S )	Nr   r9   )r   r   r   r   r9   )r>   r>   r>   r>   r>   r   r   g?)rX   r"  )r7   rt   r   r   r   r   )r   r+  r   r`   ra   r   r   s          r    test_min_weight_leaf_split_levelr
  (  s     dOM
1#sQC!qc*++AA---M#Q
-Q
'
'
'CGGAqG...9!####
-Q
E
E
ECGGAqG...9!######r   c                 D   t                               t          j        j        d          }t          |                      }|                    t           t                     t          |	                    t                     |j
        	                    |                     d S NFr  X_smallr%  r	   r  r  r7   r   y_smallr(   r  r   )r   	X_small32r   s      r   test_public_apply_all_treesr  <  so    tz/e<<I
D/

CGGGWsyy))39??9+E+EFFFFFr   r  c                 V    |t                               t          j        j        d                    }t          |                      }|                    t           t                     t          |	                    t                     |j
        	                    |                     d S r  r  )r   r  r  r   s       r   test_public_apply_sparse_treesr  E  s{     gnnTZ-=EnJJKKI
D/

CGGGWsyy))39??9+E+EFFFFFr   c                  
   t           j        } t           j        }t          dd                              | |          }|                    | d d                                                   }t          |g dg dg           d S )Nr   r9   r  rM   )r9   r9   r   r9   r   r9   )rb   r   r   r   r   r  r  r(   )r`   ra   r   node_indicators       r   test_decision_path_hardcodedr  O  s|    	AA
 a1
=
=
=
A
A!Q
G
GC&&q!u--5577N~			999'=>>>>>r   c                    t           j        }t           j        }|j        d         }t          |          } |dd          }|                    ||           |                    |          }|                                j        ||j        j	        fk    sJ |
                    |          }fdt          |          D             }t          |t          j        |                     |j        j        t           k    }	t          t          j        |	          t          j        |                                         d                                          }
|j        j        |
k    sJ d S )Nr   rM   r  c                 *    g | ]\  }}||f         S re  re  )rf  r  jr  s      r   r  z&test_decision_path.<locals>.<listcomp>g  s&    JJJ1~ad+JJJr   r  r9   axis)rb   r   r   r   r7   r   r  r  r   rp   r  	enumerater'   rt   r   rs   r   r  ry   r<  r   )r   r`   ra   rY   r   r   node_indicator_csrleavesleave_indicator
all_leavesr   r  s              @r   test_decision_pathr#  W  s]   	AA
IdOM
-Q!
4
4
4CGGAqMMM**1--'//11NIsy/C#DDDDD YYq\\FJJJJ	&8I8IJJJOorwY/G/G/GHHH (I5J
~z**BG),D,D,D  
 """**..00I9)++++++r   c                     t            |t                    }}t          |          }t          j        t
                    5   |d                              ||           d d d            d S # 1 swxY w Y   d S Nr   r   )X_multilabely_multilabelr7   r   r   r  r   )r   r  r`   ra   r   s        r   test_no_sparse_y_supportr(  u  s     |44qAdOM	y	!	! 0 01%%%))!Q///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0s   !A,,A03A0c                     t          ddd          } |                     dgdgdgdgdggg dg d	
           t          | j        j        g d           t          | j        j        j        g d           |                     dgdgdgdgdggg dt          j	        d          
           t          | j        j        g d           t          | j        j        j        g d           |                     dgdgdgdgdggg d           t          | j        j        g d           t          | j        j        j        g d           dS )aQ	  Check MAE criterion produces correct results on small toy dataset:

    ------------------
    | X | y | weight |
    ------------------
    | 3 | 3 |  0.1   |
    | 5 | 3 |  0.3   |
    | 8 | 4 |  1.0   |
    | 3 | 6 |  0.6   |
    | 5 | 7 |  0.3   |
    ------------------
    |sum wt:|  2.3   |
    ------------------

    Because we are dealing with sample weights, we cannot find the median by
    simply choosing/averaging the centre value(s), instead we consider the
    median where 50% of the cumulative weight is found (in a y sorted data set)
    . Therefore with regards to this test data, the cumulative weight is >= 50%
    when y = 4.  Therefore:
    Median = 4

    For all the samples, we can get the total error by summing:
    Absolute(Median - y) * weight

    I.e., total error = (Absolute(4 - 3) * 0.1)
                      + (Absolute(4 - 3) * 0.3)
                      + (Absolute(4 - 4) * 1.0)
                      + (Absolute(4 - 6) * 0.6)
                      + (Absolute(4 - 7) * 0.3)
                      = 2.5

    Impurity = Total error / total weight
             = 2.5 / 2.3
             = 1.08695652173913
             ------------------

    From this root node, the next best split is between X values of 3 and 5.
    Thus, we have left and right child nodes:

    LEFT                    RIGHT
    ------------------      ------------------
    | X | y | weight |      | X | y | weight |
    ------------------      ------------------
    | 3 | 3 |  0.1   |      | 5 | 3 |  0.3   |
    | 3 | 6 |  0.6   |      | 8 | 4 |  1.0   |
    ------------------      | 5 | 7 |  0.3   |
    |sum wt:|  0.7   |      ------------------
    ------------------      |sum wt:|  1.6   |
                            ------------------

    Impurity is found in the same way:
    Left node Median = 6
    Total error = (Absolute(6 - 3) * 0.1)
                + (Absolute(6 - 6) * 0.6)
                = 0.3

    Left Impurity = Total error / total weight
            = 0.3 / 0.7
            = 0.428571428571429
            -------------------

    Likewise for Right node:
    Right node Median = 4
    Total error = (Absolute(4 - 3) * 0.3)
                + (Absolute(4 - 4) * 1.0)
                + (Absolute(4 - 7) * 0.3)
                = 1.2

    Right Impurity = Total error / total weight
            = 1.2 / 1.6
            = 0.75
            ------
    r   r4   rM   )rX   r   r   r<   r;   rL   )rJ   r  r<   r8   r<   )333333?333333?r   rO   r+  )r`   ra   r   )g,d?gܶm۶m?g?)      @g      @r,  )ffffff?rN   gUUUUUU?)r8   rU   r,  r_   N)
r   r   r   r   rz   r(   r{   r  rt   r   )dt_maes    r   test_maer/    s   T #"21  F
 JJ3aS1#s
#
/////    
 FL)+L+L+LMMMv|).@@@ JJ1#sQC!qc*oooRWUVZZJXXXv|,.C.C.CDDDv|).>>>
 JJ1#sQC!qc*oooJ>>>v|,.C.C.CDDDv|).>>>>>r   c                  (   d} t          j        dt           j                  }d}d }t          j        t          j        |fD ]}t          j                    D ]W\  }} || |          } ||                                          }|\  }	\  }
}}||	k    sJ | |
k    sJ t          ||           Xt          j                    D ]O\  }} || |          } ||                                          }|\  }	\  }
}}||	k    sJ | |
k    sJ ||k    sJ Pd S )Nr<   r  rD  c                 N    t          j        t          j        |                     S r  )ri  rk  rj  )objs    r   _pickle_copyz)test_criterion_copy.<locals>._pickle_copy  s    |FL--...r   )
rt   r   intpr  deepcopyr   r   
__reduce__r(   r   )	n_outputsrb  rY   r3  	copy_func_typenamecriteriaresult	typename_
n_outputs_r{  
n_samples_s                r   test_criterion_copyr@    s{    I	!27+++II/ / / i= + +	'-// 	6 	6KAxx	955HYx((3355F5;2I/
Jy((((
****y*5555'-// 	+ 	+KAxx	955HYx((3355F5;2I/
Jy((((
****
*****	++ +r   c                    t           j                            d                              dd          dz  }t          j        |                    d                    }|d d d df         }|  | |          }|d d df         }t          d                              ||          } |j        |          }t          t          j
        |j        j        t          k              d                   }|                    |          }t          j
        t          j        |j        j                             d         }t#          |          dk    sJ t#          |          dk    sJ d S )Nr   rD  rI   g*Gr&  r?   r   )rt   r  RandomStater  
nan_to_numr%  r   r   r  setwherer   rs   r   
differenceisfiniterw   r   )	r+  r   r`   ra   r	   terminal_regions	left_leaf
empty_leafinfinite_thresholds	            r   "test_empty_leaf_infinite_thresholdrL    sM    9  ##))#r22T9D=Y//00DQQQVA#QQQQUA a00044Q::D!tz!}}BHTZ5BCCAFGGI%%&677J2;tz/C#D#D"DEEaH!""a''''z??ar   tree_clsc                 v   t           |          } | d         | d         }} |dd          }|                    ||          }|j        }|j        }t	          j        t	          j        |          dk              sJ t	          j        t	          j        |          dk              sJ t          ||||           d S Nr`   ra   r[   r   rF  r$  cost_complexity_pruning_path
ccp_alphas
impuritiesrt   r   diffassert_pruning_creates_subtreer  rM  r`   ra   r   infopruning_pathrS  s           r   'test_prune_tree_classifier_are_subtreesrY    s    
 wG3<qA
("1
5
5
5C++Aq11D?LJ6"',''1,-----6"'*%%*+++++"8Q<@@@@@r   c                 v   t           |          } | d         | d         }} |dd          }|                    ||          }|j        }|j        }t	          j        t	          j        |          dk              sJ t	          j        t	          j        |          dk              sJ t          ||||           d S rO  rP  rV  s           r   'test_prune_tree_regression_are_subtreesr[  $  s     wG3<qA
("1
5
5
5C++Aq11D?LJ6"',''1,-----6"'*%%*+++++"8Q<@@@@@r   c                      t          d          } |                     dgdggddg           t          dd          }|                    dgdggddg           t          | j        |j                   d S )Nr   r   r9   rD   )rX   	ccp_alpha)r   r   assert_is_subtreer   )r  r   s     r   test_prune_single_node_treer_  5  s    !q111DHHqcA3Z!Q    "qB???DHHqcA3Z!Q   dj$*-----r   c                     g }|D ]9} | d|d                               ||          }|                    |           :t          ||dd                    D ]\  }}t          |j        |j                    d S )Nr[   r   )r   r]  rX   r9   )r   r  zipr^  r   )	estimator_clsr`   ra   rX  
estimatorsr]  r   prev_estnext_ests	            r   rU  rU  A  s    J!  	m2QRSSSWWq
 
 	# "*jn== : :((.(.9999: :r   c                 8   | j         |j         k    sJ | j        |j        k    sJ | j        }| j        }|j        }|j        }dg}|rS|                                \  }}t          | j        |         |j        |                    t          | j        |         |j        |                    t          | j	        |         |j	        |                    t          | j
        |         |j
        |                    ||         ||         k    r!t          t          |j        |                    nlt          | j        |         |j        |                    |                    ||         ||         f           |                    ||         ||         f           |Qd S d S )N)r   r   )rp   r   rs   rr   popr'   r{   r&   rz   rx   rI  r   rw   r  )	r	   subtreetree_c_lefttree_c_rightsubtree_c_leftsubtree_c_rightstacktree_node_idxsubtree_node_idxs	            r   r^  r^  P  s   ?g00000>W.....$K&L*N,OHE
 */))++''!J}%w}5E'F	
 	
 	
 	M-('*:;K*L	
 	
 	
 	.0FGW0X	
 	
 	
 	(7+,<=	
 	
 	

 *+?O/PPP0ABR0STTTT  }-w/@AQ/R   LL+m4nEU6VWXXXLLm,o>N.OP  3      r   r  r  r  c                 j   t           d         }|d                             t          j        j        d          }|t          |          }nt ||d                   }t          j        |j        t          j        j                  |_        t          |j        |j	        |j
        f          \  |_        |_	        |_
        t          t          j        t          t          j        j                            }t          |          |          }|                    ||           t          |                    |          |                    |                     t          |                    |                                          |                    |                                                     d S )Nrf   r`   Fr  r  )r  )r$  r%  r	   r  r  r)   rt   r   r   r   r  r  r7   r   r(   r   r  todense)r   r  r+  r  r  
X_readonly
y_readonlyr   s           r   "test_apply_path_readonly_all_treesrt  x  st    {#Gcl!!$*"2!??G.w77

%%gcl33
(:?$*:JKKK

 &_j0*2CD
 
		
O
 +28G4:CS+T+T+TUUJ
D/8
,
,
,CGGJ
###s{{:..G0D0DEEE*%%--//1B1B71K1K1S1S1U1U    r   )r3   r5   r6   c                    t           j        t           j        }} ||           }|                    ||           t	          j        |                    |                    t          j        t	          j        |                    k    sJ d S )Nr   )	rc   r   r   r   rt   ry   r   r   r   )r   r$   r`   ra   r   s        r   test_balance_propertyrv    sq     =(/qA
$
#
#
#CGGAqMMM6#++a..!!V]26!99%=%=======r   seedc           	         ddgddgddgddgddgddgddgddgg}g d}t          d|           }|                    ||           t          j        |                    |                    dk    sJ t          d|           }|                    ||           t          j        |                    |          dk              sJ d	}t          j        |dz  dz  d
d||dz  dz  |           \  }}d|d|k     |dk     z  <   t          j        |          }t          d|           }|                    ||           t          j        |                    |          dk              sJ d S )Nr   r9   rM   r<   )r   r   r   r   r9   rM   r<   r8   r3   r   r6   rD   r*  r  )effective_ranktail_strengthrY   rZ   r   rX   r?   )	r   r   rt   aminr   r   r   make_regressionr   )rw  r`   ra   r   rZ   s        r   test_poisson_zero_nodesr}    s    Q!Q!Q!Q!Q!Q!Q!QHA   A  /
M
M
MCGGAqMMM73;;q>>""a''''
)$
G
G
GCGGAqMMM6#++a..1$%%%%% J#!A~* 1n)  DAq ArAv!a%
q		A
)$
G
G
GCGGAqMMM6#++a..1$%%%%%%%r   c            	         t           j                            d          } d\  }}}t          j        ||z   ||           }|                     dd|          t          j        |d          z  }|                     t          j        ||z            	          }t          |||| 
          \  }}}	}
t          dd|           }t          dd|           }|                    ||	           |                    ||	           t          d                              ||	          }||	df||
dffD ]\  }}}t          ||                    |                    }t          |t          j        |                    |          dd                     }t          ||                    |                    }|dk    r|d|z  k     sJ |d|z  k     sJ d S )Nr   )  r  rD   rY   rZ   rX   rB   rM   )lowhighr]   r   r  )lam)	test_sizerX   r6   rD   )r   r  rX   r3   mean)strategytraintestgV瞯<rK   g      ?)rt   r  rB  r   make_low_rank_matrixuniformr<  r6   r   r   r   r   r
   r   r   clip)r'  n_trainn_testrZ   r`   coefra   X_trainr  r   r   tree_poitree_msedummyval
metric_poi
metric_msemetric_dummys                     r   test_poisson_vs_mser    s   
 )


#
#C".GVZ%F"z	 	 	A
 ;;2AJ;77"&:K:K:KKDq4x(())A'7	1S( ( ($GVWf %r  H %!Rc  H LL'"""LL'"""F+++//AAE1FFF3KL 
0 
0	1c*1h.>.>q.A.ABB
*1bgh6F6Fq6I6I5RV.W.WXX
,Qa0@0@AA &==j 00000D<//////
0 
0r   rb  c                 v   d\  }}t          j        ||||dd          \  }} | dd                              ||          } | dd                              ||          }t          |j        |j        | d	           t          |                    |          |                    |                     d
S )z3Test that criterion=entropy gives same as log_loss.)r  r;   r   r   )rb  rY   rZ   r   r   rX   r2   +   r   entropyz> with criterion 'entropy' and 'log_loss' gave different trees.N)r   r   r   r   r   r   r   )r$   rb  rY   rZ   r`   ra   tree_log_losstree_entropys           r   'test_criterion_entropy_same_as_log_lossr    s     "Iz'   DAq D:B???CCAqIIM4)"===AA!QGGLQQQ  
 M))!,,l.B.B1.E.EFFFFFr   c                  X   t          j        d          \  } }t          dd                              | |                               | |          }d fd}t          j         |                      }|                    | |          }t          j        ||          sJ d S )Nr   r   r<   r  c                     |                                                      | j                                                                                  S r  )byteswapviewr  newbyteorderr6  )arrs    r   reduce_ndarrayz8test_different_endianness_pickle.<locals>.reduce_ndarray  s8    ||~~""39#9#9#;#;<<GGIIIr   c                     t          j                    } t          j        |           }t          j                                        |_        |j        t          j        <   |	                               | 
                    d           | S Nr   )ioBytesIOri  Picklercopyregdispatch_tabler  rt   ndarraydumpseek)fpr   r  s     r    get_pickle_non_native_endiannesszJtest_different_endianness_pickle.<locals>.get_pickle_non_native_endianness  sf    JLLN1"16688'5$	s	q			r   )	r   r   r   r   r   ri  loadrt   isclose)r`   ra   r   r  new_clf	new_scorer   r  s         @@r    test_different_endianness_pickler    s    'Q777DAq
 a1
=
=
=CGGAqMMMIIaOOEJ J J      k::<<==Ga##I:eY'''''''r   c                  x   t          j        d          \  } }t          dd                              | |                               | |          } G d dt
                    fd}t          j         |                      }|                    | |          }t          j	        ||          sJ d S )Nr   r   r<   r  c                        e Zd Z fdZ xZS )Ptest_different_endianness_joblib_pickle.<locals>.NonNativeEndiannessNumpyPicklerc                     t          |t          j                  r>|                                                    |j                                                  }t                                          |           d S r  )	
isinstancert   r  r  r  r  r  supersave)selfr2  rm  s     r   r  zUtest_different_endianness_joblib_pickle.<locals>.NonNativeEndiannessNumpyPickler.save(  s]    #rz** Dllnn))#)*@*@*B*BCCGGLLr   )__name__
__module____qualname__r  __classcell__)rm  s   @r   NonNativeEndiannessNumpyPicklerr  '  s8        	 	 	 	 	 	 	 	 	r   r  c                      t          j                    }  |           }|                               |                     d           | S r  )r  r  r  r  )r  r  r  r   s     r   'get_joblib_pickle_non_native_endiannesszXtest_different_endianness_joblib_pickle.<locals>.get_joblib_pickle_non_native_endianness-  sA    JLL++A..	s	q			r   )
r   r   r   r   r   r   joblibr  rt   r  )r`   ra   r   r  r  r  r  r   s         @@r   'test_different_endianness_joblib_pickler     s    'Q777DAq
 a1
=
=
=CGGAqMMMIIaOOE    ,         kAACCDDGa##I:eY'''''''r   c                    t           rt          j        nt          j        }g d}d | j        j                                        D             }|D ]}|||<   t          j        t          |                                          t          |	                                          d          }| 
                    |d          S )N)
left_childright_childrv   rx   c                      i | ]\  }\  }}||S re  re  rf  r   r  r9  s       r   rh  z6get_different_bitness_node_ndarray.<locals>.<dictcomp>@  /       (juae  r   namesformats	same_kindcasting)r,   rt   int64r  r  fieldsr   listr  valuesr%  )node_ndarraynew_dtype_for_indexing_fieldsindexing_field_namesnew_dtype_dictr   	new_dtypes         r   "get_different_bitness_node_ndarrayr  :  s    09$GBHHrx! VUU ,8,>,E,K,K,M,M  N % = =<t~**,,--$~?T?T?V?V:W:WXX I y+>>>r   c                    d | j         j                                        D             }d | j         j                                        D             }d |D             }t	          j         t          |                                          t          |                                          |d          }|                     |d          S )Nc                      i | ]\  }\  }}||S re  re  r  s       r   rh  z8get_different_alignment_node_ndarray.<locals>.<dictcomp>M  r  r   c                     g | ]\  }}|S re  re  )rf  r  r  s      r   r  z8get_different_alignment_node_ndarray.<locals>.<listcomp>P  s    NNN-%vNNNr   c                     g | ]}d |z   S )rL   re  )rf  r  s     r   r  z8get_different_alignment_node_ndarray.<locals>.<listcomp>Q  s    888fq6z888r   )r  r  offsetsr  r  )r  r  r   r  rt   r  r  r%  )r  r  r  shifted_offsetsr  s        r   $get_different_alignment_node_ndarrayr  L  s     ,8,>,E,K,K,M,M  N ON<+=+D+K+K+M+MNNNG88888O.--//00N113344&	
 	
 I y+>>>r   c                    t           rt          j        nt          j        } | j                    \  }\  }}}}|                    |d          }|                                }t          |d                   |d<   ||||f|fS )Nr  r  nodes)r,   rt   r  r  r6  r%  r  r  )	r	   r  rM  rZ   rb  r7  statenew_n_classes	new_states	            r   "reduce_tree_with_different_bitnessr  ]  s    %328I:I$/:K:K7H0z9i%$$Y$DDM

I;Ig<NOOIgz=)<iHHr   c                  T   t          j        d          \  } }t          dd                              | |                               | |          }fd}t          j         |                      }|                    | |          }|t          j        |          k    sJ d S )Nr   r   r<   r  c                     t          j                    } t          j        |           }t          j                                        |_        t          |j        t          <   |	                               | 
                    d           | S r  )r  r  ri  r  r  r  r  r  
CythonTreer  r  r  r  r   s     r   "pickle_dump_with_different_bitnesszItest_different_bitness_pickle.<locals>.pickle_dump_with_different_bitnesso  sd    JLLN1"16688'I$	s	q			r   )	r   r   r   r   r   ri  r  r   r   )r`   ra   r   r  r  r  r   s         @r   test_different_bitness_pickler  h  s    'Q777DAq
 a1
=
=
=CGGAqMMMIIaOOE     k<<>>??Ga##IFM),,,,,,,,r   c                  T   t          j        d          \  } }t          dd                              | |                               | |          }fd}t          j         |                      }|                    | |          }|t          j        |          k    sJ d S )Nr   r   r<   r  c                     t          j                    } t          |           }t          j                                        |_        t          |j        t          <   |                               | 	                    d           | S r  )
r  r  r   r  r  r  r  r  r  r  r  s     r   "joblib_dump_with_different_bitnesszPtest_different_bitness_joblib_pickle.<locals>.joblib_dump_with_different_bitness  s`    JLLOO"16688'I$	s	q			r   )	r   r   r   r   r   r  r  r   r   )r`   ra   r   r  r  r  r   s         @r   $test_different_bitness_joblib_pickler  ~  s     'Q777DAq
 a1
=
=
=CGGAqMMMIIaOOE     k<<>>??Ga##IFM),,,,,,,,r   c                      t           rt          j        t          j                  nt          j        t          j                  } t          j        t          j                  t          j        t          j                  g}|d |D             z  }t          j        ddg|           }|D ]%}t          |                    |          |            &t          j	        t          d          5  t          j        ddgg|           }t          ||            d d d            n# 1 swxY w Y   t          j	        t          d          5  |                    t          j                  }t          ||            d d d            d S # 1 swxY w Y   d S )Nc                 6    g | ]}|                                 S re  )r  )rf  dts     r   r  z(test_check_n_classes.<locals>.<listcomp>  s"    BBBRr((BBBr   r   r9   r  zWrong dimensions.+n_classesr  zn_classes.+incompatible dtype)r,   rt   r  r  r  r   r!   r%  r   r   r   r  )expected_dtypeallowed_dtypesrb  r  wrong_dim_n_classeswrong_dtype_n_classess         r   test_check_n_classesr    s   +4LRXbh'''"(28:L:LNhrx(("(28*<*<=NBB>BBBBN!Q~666I ? ?))"--~>>>>	z)F	G	G	G > > hAx~FFF,n===> > > > > > > > > > > > > > > 
z)H	I	I	I @ @ ) 0 0 < <.???@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @s$   **D  D$'D$0FF
Fc                      t          j        t           j                  } d}t          j        ||           }| |                                 g}|D ]}t          |||           t          j        t          d          5  t          || d           d d d            n# 1 swxY w Y   |d d d d d df         t          j	        |          fD ]L}t          j        t          d          5  t          || |j
                   d d d            n# 1 swxY w Y   Mt          j        t          d	          5  t          |                    t           j                  | |           d d d            d S # 1 swxY w Y   d S )
N)r;   r9   rM   r  )r  expected_shapezWrong shape.+value arrayr  )r9   rM   r9   zvalue array.+C-contiguouszvalue array.+incompatible dtype)rt   r  r  rl   r  r#   r   r   r   r  r   r%  r&  )r  r  value_ndarrayr  r  problematic_arrs         r   test_check_value_ndarrayr    sr   Xbj))NNH^>BBBM$n&A&A&C&CDN 
 
"^	
 	
 	
 	
 	
 
z)C	D	D	D 
 
.	
 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 

 *!!!QQQ(3R5F}5U5UV  ]:-HIII 	 	 -.4   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 
z)J	K	K	K 
 
  ,,))	
 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s6   ?BB"%B"+DD	D	60E33E7:E7c                     t           } t          j        d|           }|t          |          t	          |          g}|d |D             z  }|D ]}t          ||            t          j        t          d          5  t          j        d|           }t          ||            d d d            n# 1 swxY w Y   t          j        t          d          5  |d d d	         }t          ||            d d d            n# 1 swxY w Y   d
 |j	        j
                                        D             }|                                }t          j        |d<   t          j	        t          |                                          t          |                                          d          }|                    |          }t          j        t          d          5  t          ||            d d d            n# 1 swxY w Y   |                                }t          j        |d<   t          j	        t          |                                          t          |                                          d          }|                    |          }t          j        t          d          5  t          ||            d d d            d S # 1 swxY w Y   d S )N)r;   r  c                 f    g | ].}|                     |j                                                  /S re  )r%  r  r  )rf  r  s     r   r  z+test_check_node_ndarray.<locals>.<listcomp>  s?       14

39))++,,  r   )r  zWrong dimensions.+node arrayr  )r;   rM   znode array.+C-contiguousrM   c                      i | ]\  }\  }}||S re  re  r  s       r   rh  z+test_check_node_ndarray.<locals>.<dictcomp>  s#    XXX"2$
$XXXr   rw   r  znode array.+incompatible dtyper  )r   rt   rl   r  r  r"   r   r   r   r  r  r   r  r  r  r  r  r%  r  )r  r  valid_node_ndarraysr  problematic_node_ndarray
dtype_dictr  r  s           r   test_check_node_ndarrayr    s    N8D777L 	*<88,\::
   8K    # I ILHHHHH	z)G	H	H	H U U#%8F.#I#I#I 4^TTTTU U U U U U U U U U U U U U U 
z)C	D	D	D U U#/!#4 4^TTTTU U U U U U U U U U U U U U U YXl6H6O6U6U6W6WXXXJ  __&&N"$(N;~**,,--$~?T?T?V?V:W:WXX I  ,229==	z)I	J	J	J U U4^TTTTU U U U U U U U U U U U U U U  __&&N#%:N< ~**,,--$~?T?T?V?V:W:WXX I  ,229==	z)I	J	J	J U U4^TTTTU U U U U U U U U U U U U U U U U UsH   =(B11B58B5D  DDG99G= G=,KKKSplitterc                 l   t           j                            d          }d}dt          j        ddgt           j                  }}t          d         ||          } | ||dd|d	
          }t          j        |          }t          j        |          }|j	        |k    sJ t          ||           sJ d	S )z&Check that splitters are serializable.r   rD   rM   r<   r  r1   r;   rK   N)monotonic_cst)rt   r  rB  r   r4  r   ri  rj  rk  r   r  )	r	  r'  r   r7  rb  r   r  splitter_serializesplitter_backs	            r   test_splitter_serializabler   	  s    
 )


#
#CLbh1vRW===yIV$Y	::Ix	<CDQQQHh//L!344M%5555mX.......r   c                 6   t          |                     d                    }t          d          }|                    t          t
                     t          j        ||           t          j        |d          }t          |j
        |j
        d           dS )zhCheck that Trees can be deserialized with read only buffers.

    Non-regression test for gh-25584.
    z
clf.joblibr   r   r)	mmap_modez?The trees of the original and loaded classifiers are not equal.N)strjoinr   r   r  r  r  r  r  r   r   )tmpdirpickle_pathr   
loaded_clfs       r   /test_tree_deserialization_from_read_only_bufferr  	  s    
 fkk,//00K
 a
0
0
0CGGGW
K[!!![C888J	I    r   c                 L   t          j        ddgddgg          }t          j        ddg          } | d                              ||            | d          }d}t          j        t
          |          5   |j        ||           ddd           dS # 1 swxY w Y   dS )zhCheck that an error is raised when min_sample_split=1.

    non-regression test for issue gh-25481.
    r   r9   rO   )r  zb'min_samples_split' .* must be an int in the range \[2, inf\) or a float in the range \(0.0, 1.0\]r  N)rt   r   r   r   r   r   )r$   r`   ra   r	   msgs        r   test_min_sample_split_1_errorr  %	  s    	1a&1a&!""A
!QA 	D3##Aq))) 4!$$$D	0  
z	-	-	-  A                 s   :BB Bc                 b   t          j        g dg          j        }t          j        g d          }t          dd|           }|                    ||           |                    t           j        gg          }t          |t          j        |dd                   g           |dd         }|dd         }t          dd|           }|                    ||           |                    t           j        gg          }t          |t          j        |d	d                   g           dS )
z=Check missing values goes to correct node during predictions.	r   r9   rM   r<   rL   r  rI      r   	r   r>   r+  r>   r-  r-  rN   g?g@r   r9   r  r=   Nr?   r:   )	rt   r   r   r   r   r   nanr   r  )r   r`   ra   dtcr  X_equaly_equals          r   ;test_missing_values_best_splitter_on_equal_nodes_no_missingr#  ;	  s    	0001224A
>>>??A
R1	
R
R
RCGGAqMMM [[26($$FFRWQrssV__-... fGfG
R1	
R
R
RCGGGW [[26($$FFRWWRSS\22344444r   c                 @   t          j        g dg          j        }t          j        g d          }t          |d|           }|                    ||           |j        j        d         }|j        j        d         }|j        j        |         }|j        j        |         }||k    }	|j        j	        |         d         }
|j        j	        |         d         }|
                    t           j        gg          }|	rt          |
|           dS t          ||           dS )zCheck missing values go to the correct node during predictions for ExtraTree.

    Since ETC use random splits, we use different seeds to verify that the
    left/right node is chosen correctly when the splits occur.
    r  r  r9   r  r   N)rt   r   r   r   r   r   rs   rr   rI  r{   r   r  r   )r   rw  r`   ra   etrr  r  left_samplesright_samples	went_lefty_pred_lefty_pred_rightr  s                r   =test_missing_values_random_splitter_on_equal_nodes_no_missingr+  U	  s    	0001224A
>>>??A
$!y
Q
Q
QCGGAqMMM (+J)*1-K 94Z@LI5kBM},I )/*-a0K9?;/2L [[26($$F .V,,,,,f-----r   r  r1   c                    d}t          j        t           j        gdz  g dz   g          j        }t          j        |gdz  dgdz  z   dgdz  z             }t	          dd|           }|                    ||           t          j        t           j        dd	gg          j        }|                    |          }t          ||ddg           d
S )zITest when missing values are uniquely present in a class among 3 classes.r   r8   )r   r9   rM   r<   rL   r  rI   r  r9   rM   r   r  r<   r  Nrt   r   r  r   r   r   r   r(   )r   missing_values_classr`   ra   r   r  
y_nan_preds          r   /test_missing_values_best_splitter_three_classesr0  x	  s     
26(Q,!;!;!;;<==?A
&'!+qcAg5a?@@A
 bA
S
S
SCGGAqMMMX2'((*FV$$Jz$8!Q#?@@@@@r   c                    t          j        t           j        gdz  g dz   g          j        }t          j        dgdz  dgdz  z             }t	          dd|           }|                    ||           t          j        t           j        d	t           j        gg          j        }|                    |          }t          |g d
           dS )zMissing values spanning only one class at fit-time must make missing
    values at predict-time be classified has belonging to this class.r8   r   r9   rM   r<   r8   r;   r   r9   rJ   r   rM   r  r;   )r   r9   r   Nr-  r   r`   ra   r   r  r  s         r   )test_missing_values_best_splitter_to_leftr4  	  s     	26(Q,!3!3!334557A
!qA37"##A
 bA
S
S
SCGGAqMMMX26*+,,.F[[  Fvyyy)))))r   c                    t          j        t           j        gdz  g dz   g          j        }t          j        dgdz  dgdz  z   dgdz  z             }t	          dd|           }|                    ||           t          j        t           j        dd	gg          j        }|                    |          }t          |g d
           dS )zMissing values and non-missing values sharing one class at fit-time
    must make missing values at predict-time be classified has belonging
    to this class.r8   r2  r9   r   rM   r   r  rP   g333333@r  Nr-  r3  s         r   *test_missing_values_best_splitter_to_rightr6  	  s    
 	26(Q,!3!3!334557A
!qA37"aS1W,--A
 bA
S
S
SCGGAqMMMXS)*++-F[[  Fvyyy)))))r   c                    t          j        ddddt           j        ddddt           j        g
g          j        }t          j        d	gdz  dgdz  z             }t	          d
d|           }|                    ||           t          j        t           j        ddgg          j        }|                    |          }t          |g d           dS )zNCheck behavior of missing value when there is one missing value in each class.r9   rM   r<   r;   rD   r[   rW   r   r   r   r  gffffff@gA@r  Nr-  r3  s         r   >test_missing_values_best_splitter_missing_both_classes_has_nanr8  	  s     	1aArvr2r2rv>?@@BA
!qA37"##A
 bA
S
S
SCGGAqMMMXT*+,,.F[[  F vyyy)))))r   r	   r   c                 X   t          j        ddddt           j        ddddt           j        g
g          j        }t          j        d	gdz  dgdz  z             }|  | |          }t	          j        t          d          5   |j        ||           d
d
d
           d
S # 1 swxY w Y   d
S )z4Check unsupported configurations for missing values.r9   rM   r<   r;   rD   r[   rW   r   r   NzInput X contains NaNr  )rt   r   r  r   r   r   r   r   )r+  r	   r`   ra   s       r   test_missing_value_errorsr:  	  s     	1aArvr2r2rv>?@@BA
!qA37"##A#Q	z)?	@	@	@  A                 s    BB#&B#c                 N   t           j                                        t           j        }}t          j        |ddddf<   t          j        |ddddf<    | dd          }|                    ||           |                    |          }|d	k                                    sJ dS )
z5Smoke test for poisson regression and missing values.Nr;   r   rJ   r?   r6   r   r   rT   )	rc   r   r  r   rt   r  r   r   r   )r$   r`   ra   r   r  s        r   test_missing_values_poissonr<  	  s     =qA Accc1fIAccc2gJ
$
4
4
4CGGAqMMM[[^^FcM       r   c                  >    t          j        | i |\  }}|dk    }||fS )N   )r   make_friedman1)argskwargsr`   ra   s       r   make_friedman1_classificationrB  	  s-    "D3F33DAq	BAa4Kr   zmake_data, Tree, tolerancegQ?gQ?gQ?sample_weight_trainr   c                    d\  }} | ||d|          \  }}|                                 }	t          j                            |          }
t          j        |	|
                    ddg|j        ddg          <   t          |	||	          \  }}}}|d
k    r t          j        |j        d                   }nd}d} |||          }|	                    |||           |
                    ||          }t          t                       |||                    }|	                    ||           |
                    ||          }||z   |k    sJ d|d| d|             dS )zFCheck that trees can deal with missing values have decent performance.)r   rD   rO   )rY   rZ   noiserX   FTrV   r   r]   r  r   r   r   NrD   r   r   zscore_native_tree=z + z! should be strictly greater than )r  rt   r  rB  r  choicer   r   r   r   r   r   r   )	make_datar$   rC  rJ  	tolerancerY   rZ   r`   ra   	X_missingr'  X_missing_trainX_missing_testr   r   r   r   native_treescore_native_treetree_with_imputerscore_tree_with_imputers                        r   !test_missing_values_is_resiliencerQ  	  s   ( &Iz9'	  DAq I
)

 2
3
3CGIvIcjj%QWc
jCCD7G1#58 8 84O^Wf f$$ 5a 899 I$9KLLLKOOOWMOJJJ#)).&AA%	@RSSS  /7333/55nfMMy(+BBBB	& 	& 	&) 	& 	&#	& 	& CBBBBr   zTree, expected_scoreg333333?g(\?c                    t           j                            d          }d}|                    |df          }t          j        t          j        |dz            t          j        |dz            g          }|                    ddg|dd	g
          }|                                	                    t                    }||          ||<   |                    |          }	t           j        |	|<   |	|dddf<    | |          }
t          |
||d                                          }||k    sJ d| d|             dS )z@Check the tree learns when only the missing value is predictive.r   r  r[   r\   rM   FTgffffff?rQ   rF  Nr;   r   )cvzExpected CV score: z	 but got )rt   r  rB  standard_normalr  rl   r   rG  r  r%  boolr  r   r  )r$   expected_scorerJ  r'  rY   r`   ra   X_random_masky_maskX_predictiver	   tree_cv_scores               r    test_missing_value_is_predictiver[   
  sP    )


"
"CI)R11A
a00"')q.2I2IJKKA JJt}9tJMMMVVXX__T""F#M22F=&&I&66L6LAaaadG4/000D $D!Q1555::<<M'''E^EEmEE 	(''''r   zmake_data, Treec                 >   t           j                            d          }d\  }} | |||          \  }}t           j        ||                    ddg|j        ddg          <   t          j        |j        d                   }d	|d
d
d<    |d          }|                    |||            |d          }	|	                    |dd
dd
d
f         |dd
d                    t          |		                    |          |	                    |                     d
S )z=Check sample weight is correctly handled with missing values.r   )r  rD   r  FTrV   r   rF  rT   NrM   r   r   r9   )
rt   r  rB  r  rG  r   r   r   r   r   )
rH  r$   r'  rY   rZ   r`   ra   r   tree_with_swtree_samples_removeds
             r   test_sample_weight_non_uniformr_  >
  s5    )


"
"C$Iz9yZcRRRDAq @BvAcjj%QWc
j;;< GAGAJ''MM##A#4Q'''LQ7774Q///Qqt!tQQQwZ14a4111(0033\5I5I!5L5LMMMMMr   c                  F   t          d                              t          j        t          j                  } t          d                              t          j        t          j                  }t          j        |           }t          j        |          }||k    sJ d S r%  )r   r   rb   r   r   ri  rj  )tree1tree2pickle1pickle2s       r   test_deterministic_picklere  [
  s     #22266ty$+NNE"22266ty$+NNEl5!!Gl5!!Ggr   r`   r;   rJ   c                    |                     dd          }t          j        d          } | |d                              ||          }t	          |                              |                     dd          |          }|j        j        }t          |dk              sJ |                                            t          |j        j        dd         |j        j        dd                    t          j
        |j        j        dk    |j        j        dk    z            }t          |j        j        |         d           dS )	a'  Check that we properly handle missing values in regression trees using a toy
    dataset.

    The regression targeted by this test was that we were not reinitializing the
    criterion when it comes to the number of missing values. Therefore, the value
    of the critetion (i.e. MSE) was completely wrong.

    This test check that the MSE is null when there is a single sample in the leaf.

    Non-regression test for:
    https://github.com/scikit-learn/scikit-learn/issues/28254
    https://github.com/scikit-learn/scikit-learn/issues/28316
    r?   r9   rJ   r   r   NrM   rT   )r  rt   r   r   r   r   rz   r   r   r   flatnonzerors   rx   )r$   r`   r   ra   r	   tree_refrz   
leaves_idxs           r   'test_regression_tree_missing_values_toyrj  h
  s    6 	
		"aA
	!A4)!44488A>>DT{{qyyQ//33Hz"Hx1}--x||~~--- DJ'+X^-DRaR-HIII 		!R	'DJ,E,JK J DJ'
3S99999r   c                    t           j                            |           }d}t          j        |t           j                                      dd          }t           j        |dd d d f<   |                    |           t          j        |          }t          | d          	                    ||          }|j
        j        }t          |dk              s
J |            d S )	NrD  r  r?   r9   ir;   r  r   )rt   r  rB  r   r  r  r  r   r   r   r   rz   r   )rJ  r'  rY   r`   ra   r	   rz   s          r   -test_regression_extra_tree_missing_values_toyrl  
  s    
)

 2
3
3CI
	)2:...66r1==AAcddAAAgJKKNNN
	)A+=KKKOOPQSTUUDz"Hx1}''x'''''r   c                  $   t          j        d          \  } }t          j                            d          }|                                 }|                    t          j        dt          j                  | dddgf         dz  	          	                    t                    }t          j        ||<   t          ||d
          \  }}}}t          j        g dt          j                  }t          ddd          }	 |	j        ||         ||                    t!          |	j        j        dk              sJ t          j        |	j        j        dk    |	j        j        dk    z            }
t-          |	j        j        |
         d           dS )a  Check that we properly handle missing values in clasification trees using a toy
    dataset.

    The test is more involved because we use a case where we detected a regression
    in a random forest. We therefore define the seed and bootstrap indices to detect
    one of the non-frequent regression.

    Here, we check that the impurity is null or positive in the leaves.

    Non-regression test for:
    https://github.com/scikit-learn/scikit-learn/issues/28254
    T)
return_X_yr   )r9   r8   )r   r  NrM   rL   )nr     r   )prM   Q   '   a   [   &   .      e   rp  Y   R   rD  r   E      rq     I   J   3   /   k      K   n   r[   r   h   9      r   r  O   #   M   Z   r  rv  rp  ^   rt     rL   ]   r  r~  r  r  rp  r  m   r     rD   r  r  r|  \   4   r[   r  rL   rL      r|  r  r  r  r  r  r   rW   rw  N   r  r  i   r  r   r~  r  f   r  rp  rw  r9   r{  rI       r  r  j   r  r   8   r  r  >   U   rq  rr  P   r}  ?   rJ   r  T   r<   r<   L   r  r  r<   r   iHnr   r   r?   r9   rT   )r   	load_irisrt   r  rB  r  r  r   r  r%  rU  r  r   r   r   r   r   r   rz   rg  rs   rx   r   )r`   ra   r'  rJ  maskr  r9  r   r   r	   ri  s              r   +test_classification_tree_missing_values_toyr  
  s    ...DAq
)


#
#CI<<
'bh
/
/
/1QQQV9q=   fTll 	 fIdO-iLLLGQ h    X  G "&z  D DHWWww/000tz"a'(((((		!R	'DJ,E,JK J DJ'
3S99999r   c                     t          dd          }  | j        t          j        t          j                   t          j        | j                  }t          | j	        || j
                  }t          j        | j        j        t
          j                  }d|d<   t          || j        |           | j        j        dk    sJ |j        dk    sJ t!          j        t$                    5  t'          | j        j        |j                   ddd           n# 1 swxY w Y   t'          | j        j        d         |j        d                    t          | j	        || j
                  }t          j        | j        j        t
          j                  }d|dd<   t          || j        |           | j        j        dk    sJ |j        dk    sJ |j                    t'          | j        j        |j                   dS )zHTest pruning a tree with the Python caller of the Cythonized prune tree.r   r9   r  r  r<   N)r   r   rb   r   r   rt   
atleast_1dr{  r  n_features_in_r>  rl   r   rp   uint8r    r   r   AssertionErrorr(   r{   r	   rb  pruned_treeleave_in_subtrees       r   test_build_pruned_tree_pyr  
  s   !qA>>>DDHTY$$$do..IT0)T_MMK x
 5RXFFFQ+tz3CDDD: A%%%%!Q&&&&	~	&	& @ @4:+[->???@ @ @ @ @ @ @ @ @ @ @ @ @ @ @tz'*K,=a,@AAA T0)T_MMKx
 5RXFFFQRR +tz3CDDD: A%%%%!Q&&&(>&&&tz'):;;;;;s   ( DDDc                     t          dd          }  | j        t          j        t          j                   t          j        | j                  }t          | j	        || j
                  }t          j        | j        j        t
          j                  }d|d<   t          j        t"          d          5  t%          || j        |           ddd           dS # 1 swxY w Y   dS )z8Test pruning a tree does not result in an infinite loop.r   r9   r  r  z,Node has reached a leaf in the original treer  N)r   r   rb   r   r   rt   r  r{  r  r  r>  rl   r   rp   r  r   r   r   r    r  s       r   $test_build_pruned_tree_infinite_loopr  
  s*    "qA>>>DDHTY$$$do..IT0)T_MMK x
 5RXFFFQ	H
 
 
 I I 	k4:7GHHHI I I I I I I I I I I I I I I I I Is   5CC Cc                  P   t           j                            d          } |                     ddd                              t           j                  }t          j        |gdz            }t          j        d          }t          ||d           g d}t          ||           d	S )
zNon-regression test for gh-30554.

    Using log2 and log in sort correctly sorts feature_values, but the tie breaking is
    different which can results in placing samples in a different order.
    r  rT   g      $@rD   )locscaler]   r;   r  )2r   (   rW   r[   rD      rr     1   r  -   r   r  r;      rI   rw  )   r9         r  rM   r   r  r  rp  r  r<   !   rJ   $   rv  r}  r  r8   r>  r  "   ,   r|  r  r  %   r  rL   ru  0   r     N)
rt   r  default_rngnormalr%  r&  r  r   r   r(   )r'  somefeature_valuesr  expected_sampless        r   test_sort_log2_buildr    s     )


#
#C::#T:33::2:FFD^TFQJ//NimmG^Wb)))   w 011111r   r  )__doc__r  r  r  ri  r  r  	itertoolsr   r   r  numpyrt   r   joblib.numpy_pickler   numpy.testingr   sklearnr   r   r	   sklearn.dummyr
   sklearn.exceptionsr   sklearn.imputer   sklearn.metricsr   r   r   sklearn.model_selectionr   r   sklearn.pipeliner   sklearn.random_projectionr   sklearn.treer   r   r   r   sklearn.tree._classesr   r   r   r   sklearn.tree._partitionerr   sklearn.tree._treer   r   r   r    r!   r"   r#   r$   r  sklearn.utilsr%   sklearn.utils._testingr&   r'   r(   r)   r*   r+   sklearn.utils.fixesr,   r-   r.   r/   sklearn.utils.validationr0   r   REG_CRITERIONSr   r   dictr7   __annotations__updateSPARSE_TREESr   r  r  y_small_regr`   ra   r   r   r  rb   r  rB  r'  r  r   r]   permr   load_diabetesrc   load_digitsrd   rX   make_multilabel_classificationr&  r'  r  X_sparse_posr  y_randomr  X_sparse_mixrl   r$  r   r   r   markparametrizer  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r0  r5  r:  r=  r@  rB  r^  rr  ry  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  sortedrD  intersectionr  r  r  r  ra  r  r  r  r
  r  r  r  r#  r(  r/  r@  rL  r  rY  r[  r_  rU  r^  rt  rv  rH  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r#  r+  r0  r4  r6  r8  r:  r<  rB  r?  rQ  r[  r|  r   r_  re  r  rj  rl  r  r  r  r  re  r   r   <module>r     s       				  				  $ $ $ $ $ $ $ $       , , , , , , ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ( ( ( ( ( ( - - - - - - ( ( ( ( ( ( U U U U U U U U U U E E E E E E E E * * * * * * ; ; ; ; ; ;                       / . . . . .                  2 1 1 1 1 1 / / / / / /                           8 7 7 7 7 7%O 5. 	 3, 	
 $&&	4    	      	        "(555666<<<999444:::@@@>>>>>>@@@777444555444555???@@@AAA888444555444444/ 8 P
O
O  6 	"XBx"bAq6Aq6Aq6:"X1v1vjj xiA
t{'((IdO	k$ "8!##
x+,,d#/$'				
v})**k$d#!!!$$DXDbR   l
 ###11$'\S  !1511$$RTJJJRRTT )$+..m(/::Kfm44W--[11$<88$844%H55$84428G$$844 $ $ $N	X 	X 	X	X 	X 	X !1!1!3!344n55, , 65 54,*F F F*
 
 
$ y'8'899n55J J 65 :9J y'8'899,	"0"5	2126	/4	B-r2	    :9 
 
 
4  W W W   2L L L>- - -K K K<!7 !7 !7H?+ ?+ ?+DH H H>F F FB8
 8
 8
 8
v ++1 1 ,+1 ...99W W :9 /.W
 &*:
 :
 :
 :
z ++G G ,+G ...99  :9 /.E E EP0 0 0f9% 9% 9%x= = =(	E 	E 	E*8 *8 *8Z1 1 1h3 3 30 ++,N ,N ,+,N^ ++	 	 ,+	+ + +$ $ $K K K$( ( (- - -? ? ?"! ! !    *& & & &R l33	 6 6  436
 ffSS->->-K-KI-V-V&W&WXXZ$=>>. . ?> YX. l33$W$W$WXX.990: 0: :9 YX 430:f DEE<EEE~	V	VWW
dDD,DDDnUU   $W$W$WXX.99: : :9 YX :" l33!33~~#F#F HP HP  43HPV    ++, , ,+,
 +++dVn-DEE$ $ FE ,+$$ ++G G ,+G ...99G G :9 /.G? ? ? ++, , ,+,: ++.990 0 :9 ,+0a? a? a?H+ + +8 +dVn-DEE    FE $ vvcc(--//**k:-FFGG  &<>Q%RSSA A TS A HMMOO44&;=O%PQQA A RQ 54A	. 	. 	.: : :% % %P ++fh%788+dVn-D~-UVV  WV 98 ,+4 &R&R&RSS!1!1!3!344	> 	> 54 TS	> q**& & +*&B'0 '0 '0T "8:M!NOOq!f--G G .- POG,( ( (2( ( (4? ? ?$? ? ?"I I I- - -,- - -6@ @ @$
 
 
B1U 1U 1Uh ,o,..0G0@0G0I0IJJ / / /  & !1!1!3!344  54* &GHH5 5 IH52 q**&GHH. . IH +*.B y&&9::A A ;:A y&&9::* * ;:* y&&9::* * ;:*  y&&9::* * ;:* +dVn-DEE
(8999%5666 
 
  FE
 !1!1!3!344! ! 54!     
	 "7;		 "4d;	&(>E	&(;TB  .v??' ' @?  'Z /Y5E5E5G5G$PT1V1VWWF F XWF: 		!#89		%'=> N N N,
 
 
 "79K!LMM 	"&!RVQ1-.."&"&!Q1-..!Q1bfbf-..!Q261bf-..
 
 &GHH: : IH
 
 NM:B( ( (,: ,: ,:^< < <>I I I$2 2 2 2 2r   