
    0Ph!                        U d 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	 ddl
mZmZ ddlmZ ddlZddlZddlZddlmZ ddlZdd	l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#m$Z$ ddl%m&Z&m'Z' ddl(m)Z) ddl*m+Z+m,Z,m-Z-m.Z. ddl/m0Z0m1Z1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z> ddl?m@Z@mAZAmBZB ddlCmDZD ddlEmFZF ddlGmHZH ddgddgddgddgddgddggZIg dZJddgddgddggZKg dZL ej        d d!dddd"d#          \  ZMZN ejO                    ZP eHd          ZQeQR                    ePjS        jT                  ZUePjV        eU         eP_V        ePjS        eU         eP_S         ejW        d d!d$          \  ZXZY ej        d%d&          \  ZZZ[eZ\                    ej]                  ZZej^        _                                d         j`        Zae e"d'Zbe!e#d(Zcd)e$iZd ee            Zfeegef         ehd*<   efi                    eb           efi                    ec           efi                    ed           ebj                                Zkeegef         ehd+<   eki                    ec           ejl        m                    d,eb          d-             Znejl        m                    d,eb          ejl        m                    d.d/          d0                         Zoejl        m                    d,ec          ejl        m                    d.d1          d2                         Zpd3 Zqejl        m                    d.d4          d5             Zrejl        m                    d,ec          d6             Zsejl        m                    d,eb          d7             Ztejl        m                    d8eju        ej]        f          ejl        m                    d9 ejv         e	ebd:d;g           e	ecg d<                              d=                         Zwd> Zxejl        m                    d,ef          d?             Zyejl        m                    d@ebz                                          ejl        m                    dAg dB          ejl        m                    dCg  ej        dDddE          dFR g  ej        dGddHdI          dJR ePjV        ePjS        dz  dz   dJfg  ej{        dDd&          dKR g          ejl        m                    dLdM ee,dNO          g          dP                                                 Z|ejl        m                    dQecz                                          ejl        m                    dAg dB          ejl        m                    dRg  ejW        d d!ddS          dTR g  ejW        d d!ddS          dUR g          ejl        m                    dLdMe+g          dV                                                 Z}ejl        m                    dWekz                                          dX             Z~ejl        m                    dWekz                                          dY             Zejl        m                    d@ebz                                          dZ             Zejl        m                    dQecz                                          d[             Zejl        m                    dLdMd"g          d\             Zejl        m                    d,eb          d]             Zejl        m                    d,ek          d^             Zejl        m                    d,ek          d_             Zejl        m                    d,ek          d`             Zejl        m                    d,eb          da             Zejl        m                    d,eb          db             Zdc Zdd Zde Zejl        m                    dfeA          dg             Zdh Zdi Zejl        m                    d,ef          dj             Zejl        m                    d,ef          dk             Zejl        m                    d,ef          dl             Zejl        m                    d,ef          dm             Zejl        m                    d,ef          ejl        m                    dne@eAz   eBz             do                         Zejl        m                    d,ek          ejl        m                    d8eju        ej]        f          dp                         Zejl        m                    d,ef          dq             Zejl        m                    d,eb          dr             Zejl        m                    d,eb          ds             Zejl        m                    d,eb          dt             Zejl        m                    d,ef          du             Zejl        m                    d,ef          dv             Zejl        m                    d,ef          dw             Zejl        m                    d,ef          dx             Zejl        m                    d,ek          dy             Zejl        m                    d,ek          dz             Zdd|Zejl        m                    d,ek          d}             Zd~ Zd Z G d dea          Z ej        de           e>d             Zd Zd Zejl        m                    d,ek          d             Zejl        m                    d,ek          d             Zejl        m                    d,ec          d             Zejl        m                    d,eb          d             Zejl        m                    deB          d             Zejl        m                    de"e#g          d             Zejl        m                    dec          d             Zd Zejl        m                    deB          d             Zejl        m                    dddg          d             Zejl        m                    dddg          ejl        m                    ddMd"g          ejl        m                    dekz                                          d                                     Zejl        m                    dejW        e#fej        e"fejW        e!fej        e fg          d             Zejl        m                    de"e#e!e g          d             Zejl        m                    decz                                          d             ZdS )z:
Testing for the forest module (sklearn.ensemble.forest).
    N)defaultdict)partial)combinationsproduct)AnyDict)patch)comb)clonedatasets)make_classificationmake_hastie_10_2)TruncatedSVD)DummyRegressor)ExtraTreesClassifierExtraTreesRegressorRandomForestClassifierRandomForestRegressorRandomTreesEmbedding)_generate_unsampled_indices_get_n_samples_bootstrap)NotFittedError)explained_variance_scoref1_scoremean_poisson_deviancemean_squared_error)GridSearchCVcross_val_scoretrain_test_split)	LinearSVC)SPARSE_SPLITTERS)_convert_containerassert_allcloseassert_almost_equalassert_array_almost_equalassert_array_equalignore_warningsskip_if_no_parallel)COO_CONTAINERSCSC_CONTAINERSCSR_CONTAINERS)type_of_target)Parallel)check_random_state      )r0   r0   r0   r1   r1   r1      )r0   r1   r1     
   F)	n_samples
n_featuresn_informativen_redundant
n_repeatedshufflerandom_stater6   r7   r<      r6   r<   )r   r   )r   r   r   FOREST_ESTIMATORSFOREST_CLASSIFIERS_REGRESSORSnamec                 ^   t           |          } |dd          }|                    t          t                     t	          |                    t                    t                     dt          |          k    sJ  |ddd          }|                    t          t                     t	          |                    t                    t                     dt          |          k    sJ |	                    t                    }|j
        t          t                    |j        fk    sJ dS )z&Check classification on a toy dataset.r5   r1   n_estimatorsr<   )rE   max_featuresr<   N)FOREST_CLASSIFIERSfitXyr&   predictTtrue_resultlenapplyshaperE   )rB   ForestClassifierclfleaf_indicess       b/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/ensemble/tests/test_forest.pytest_classification_toyrU   y   s     *$/


;
;
;CGGAqMMMs{{1~~{333S>>>>


K
K
KCGGAqMMMs{{1~~{333S>>>> 99Q<<L#a&&#*:!;;;;;;;    	criterion)ginilog_lossc                    t           |          } |d|d          }|                    t          j        t          j                   |                    t          j        t          j                  }|dk    sJ d||fz               |d|dd          }|                    t          j        t          j                   |                    t          j        t          j                  }|dk    sJ d||fz              d S )	Nr5   r1   rE   rW   r<   ?z'Failed with criterion %s and score = %fr2   rE   rW   rF   r<         ?)rG   rH   irisdatatargetscore)rB   rW   rQ   rR   rb   s        rT   test_iris_criterionrc      s     *$/

ia
P
P
PCGGDIt{###IIdi--E3;;;AYPUDVV;;;

911  C GGDIt{###IIdi--E3;;;AYPUDVV;;;;;rV   )squared_errorabsolute_errorfriedman_msec                    t           |          } |d|d          }|                    t          t                     |                    t          t                    }|dk    sJ d||fz               |d|dd          }|                    t          t                     |                    t          t                    }|dk    sJ d	||fz              d S )
N   r1   r[   g(\?z:Failed with max_features=None, criterion %s and score = %f   r]   gq=
ףp?z7Failed with max_features=6, criterion %s and score = %f)FOREST_REGRESSORSrH   X_regy_regrb   )rB   rW   ForestRegressorregrb   s        rT   test_regression_criterionro      s     (-O
/qIA
N
N
NCGGE5IIeU##ECG  	 /)!!  C GGE5IIeU##E4<<<RV <<<<<rV   c            	         t           j                            d          } d\  }}}t          j        ||z   ||           }|                     dd|          t          j        |d          z  }|                     t          j        ||z            	          }t          |||| 
          \  }}}	}
t          ddd|           }t          ddd|           }|                    ||	           |                    ||	           t          d                              ||	          }||	df||
dffD ]\  }}}t          ||                    |                    }t          |t          j        |                    |          dd                    }t          ||                    |                    }|dk    r||k     sJ |d|z  k     sJ dS )zTest that random forest with poisson criterion performs better than
    mse for a poisson target.

    There is a similar test for DecisionTreeRegressor.
    *   r4   r4   r5   r=   r/   r2   lowhighsizer   axislam	test_sizer<   poissonr5   sqrt)rW   min_samples_leafrF   r<   rd   mean)strategytraintestgư>N皙?)nprandomRandomStater   make_low_rank_matrixuniformmaxr}   expr   r   rH   r   r   rK   clip)rngn_trainn_testr7   rI   coefrJ   X_trainX_testy_trainy_test
forest_poi
forest_msedummy	data_name
metric_poi
metric_msemetric_dummys                     rT   test_poisson_vs_mser      s    )


#
#C".GVZ%F"z	 	 	A
 ;;2AJ;77"&:K:K:KKDq4x(())A'7	1S( ( ($GVWf 'bvTW  J '!	  J NN7G$$$NN7G$$$F+++//AAE$gw7&&&9QR / /1i*1j.@.@.C.CDD
 +rwz))!,,dD99
 

 -Qa0@0@AA 
****C,......#/ /rV   )r}   rd   c                 ,   t           j                            d          }d\  }}}t          j        ||z   ||          }|                    dd|          t          j        |d          z  }|                    t          j        ||z            	          }t          | d
d|          }|
                    ||           t          j        |                    |                    t          j        t          j        |                    k    sJ dS )z9 "Test that sum(y_pred)==sum(y_true) on the training set.rq   rr   r=   r/   r2   rs   r   rw   ry   r5   F)rW   rE   	bootstrapr<   N)r   r   r   r   r   r   r   r}   r   r   rH   sumrK   pytestapprox)	rW   r   r   r   r7   rI   r   rJ   rn   s	            rT   #test_balance_property_random_forestr      s    )


#
#C".GVZ%F"z	 	 	A ;;2AJ;77"&:K:K:KKDq4x(())A
"C  C GGAqMMM6#++a..!!V]26!99%=%=======rV   c                     t          |          d          }t          |d          rJ t          |d          rJ |                    g dg dgddg           t          |d          rJ t          |d          rJ d S )	Nr   r<   classes_
n_classes_r1   r2   r3      rh   ri   r1   r2   )rj   hasattrrH   )rB   rs     rT   test_regressor_attributesr     s     	$Q///Aq*%%%%%q,'''''EE999iii
 1a&)))q*%%%%%q,'''''''rV   c           	      v   t           |          }t          j        d          5   |dddd          }|                    t          j        t          j                   t          t          j        |	                    t          j                  d          t          j
        t          j        j        d                              t          |	                    t          j                  t          j        |                    t          j                                       d d d            d S # 1 swxY w Y   d S )Nignoredivider5   r1   )rE   r<   rF   	max_depthrw   r   )rG   r   errstaterH   r_   r`   ra   r%   r   predict_probaonesrP   r   predict_log_proba)rB   rQ   rR   s      rT   test_probabilityr     sM    *$/	H	%	%	% 

 

!!q
 
 
 		4;'''!F3$$TY//a888"'$)/RSBT:U:U	
 	
 	
 	"di(("&1F1Fty1Q1Q*R*R	
 	
 	


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

s   C>D..D25D2dtypezname, criterionrX   rY   )rd   rf   re   c                    d}|t           v r|dk    rd}t                              | d          }t                              | d          }t          |         } |d|d          }|                    ||           |j        }t          j        |d	k              }	|j	        d         dk    sJ |	d
k    sJ t          j
        |d d
         d	k              sJ |j        }|                    d           |j        }
t          ||
           t          d                              ddt          |                    } |dd|          }|                    |||           |j        }t          j
        |dk              sJ dD ]a} |dd|          }|                    ||||z             |j        }t          j        ||z
                                            |k     sJ bd S )N{Gz?re   皙?Fcopyr5   r   r[   皙?r3   r2   n_jobsr1   )rE   r<   rW   sample_weight        )r^   d   )rj   X_largeastypey_larger@   rH   feature_importances_r   r   rP   all
set_paramsr%   r.   randintrN   absr   )r   rB   rW   	tolerancerI   rJ   ForestEstimatorestimportancesn_importantimportances_parallelr   scaleimportances_biss                 rT   test_importancesr   #  s$    I   Y2B%B%B	 	u5))Au5))A'-O
/rYQ
O
O
OCGGAqMMM*K &s*++KQ2%%%%!6+bqb/C'((((( *KNN!N3k+?@@@ 'q))11!RQ@@M
/rY
O
O
OCGGAqG...*K6+$%%%%% H Ho2ASSS1EM$9:::2vkO34499;;iGGGGG	H HrV   c                    	
 d 	d 
	
fd} t          j        g dg dg dg dg dg d	g d
g dg dg dg
          }t          j        |d d d df         t                    |d d df         }}|j        d         }t          j        |          }t          |          D ]} | |||          ||<   t          dddd                              ||          }t          d |j	        D                       |j
        z  }t           
|          t          |                     t          j        ||z
                                            dk     sJ d S )Nc                 v    | dk     s| |k    rdn+t          t          |          t          |           d          S )Nr   T)exact)r
   int)kns     rT   binomialz-test_importances_asymptotic.<locals>.binomialZ  s7    EEQUUqqSVVSVV4(H(H(HHrV   c                     t          |           }d}t          j        |           D ]*}d|z  |z  }|dk    r||t          j        |          z  z  }+|S )Nr         ?r   )rN   r   bincountlog2)samplesr6   entropycountps        rT   r   z,test_importances_asymptotic.<locals>.entropy]  s^    LL	[)) 	* 	*Eei'A1uu1rwqzz>)rV   c           
      P   j         \  }}t          t          |                    }|                    |            fdt          |          D             d}t          |          D ]7}d ||          ||z
  z  z  }t	          ||          D ]t          fdt          |          D              D ]}	t          j        |t                    }
t          |          D ]!}|
d d |         f         |	|         k    z  }
"|
d d f         ||
         }}t          |          dk    rog }|          D ]-}|d d | f         |k    }|
                    ||                    .||dz  |z  z   |          t          fd|D                       z
  z  z  }9|S )Nc                 L    g | ] }t          j        d d |f                   !S )N)r   unique).0irI   s     rT   
<listcomp>zGtest_importances_asymptotic.<locals>.mdi_importance.<locals>.<listcomp>m  s/    @@@")AaaadG$$@@@rV   r   r   c                 ,    g | ]}|                  S  r   )r   jBvaluess     rT   r   zGtest_importances_asymptotic.<locals>.mdi_importance.<locals>.<listcomp>x  s!    "B"B"BA6!A$<"B"B"BrV   r   r   c                 L    g | ] } |          t          |          z  z  !S r   )rN   )r   cr   n_samples_bs     rT   r   zGtest_importances_asymptotic.<locals>.mdi_importance.<locals>.<listcomp>  sA     %& %& %&,- )0

SVV(;k(I%& %& %&rV   )rP   listrangepopr   r   r   r   boolrN   appendr   )X_mrI   rJ   r6   r7   featuresimpr   r   bmask_br   X_y_childrenximask_xir   r   r   r   r   s    `               @@@rT   mdi_importancez3test_importances_asymptotic.<locals>.mdi_importanceh  s&    !	:j))**S@@@@eJ.?.?@@@z"" #	 #	A((1j11Z!^DED "(A..   "B"B"B"B"Bq"B"B"BC  AWYd;;;F"1XX 5 5!AAAqtG*!"44vqqqy\1V9B"%b''K"Q#%"(+ 9 9B&(CjB&6G$OOBwK8888 "[09<> !("%%& %& %& %& %&19%& %& %&#" #"!"
!@ 
rV   )r   r   r1   r   r   r1   r   r1   )r1   r   r1   r1   r1   r   r1   r2   )r1   r   r1   r1   r   r1   r1   r3   )r   r1   r1   r1   r   r1   r   r   )r1   r1   r   r1   r   r1   r1   rh   )r1   r1   r   r1   r1   r1   r1   ri   )r1   r   r1   r   r   r1   r      )r1   r1   r1   r1   r1   r1   r1      )r1   r1   r1   r1   r   r1   r1   	   )r1   r1   r1   r   r1   r1   r1   r   r  r   r1   r4   rY   r   )rE   rF   rW   r<   c              3   L   K   | ]}|j                             d           V   dS )F)	normalizeN)tree_compute_feature_importancesr   trees     rT   	<genexpr>z.test_importances_asymptotic.<locals>.<genexpr>  sI       
 
 J22U2CC
 
 
 
 
 
rV   r   )r   arrayr   rP   zerosr   r   rH   r   estimators_rE   r$   r   r   )r  r`   rI   rJ   r7   true_importancesr   rR   r   r   r   s            @@rT   test_importances_asymptoticr  U  s   
I I I	 	 	. . . . . .` 8$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$	
 D 8DBQBKt,,,d111a4jqAJ x
++: 6 6,nQ155 qJQ  	c!Qii 
 	 
 

 
 
 	
 	
 
		  

C$4$45556"[01166884??????rV   c                     d                     |           }t          j        t          |          5  t	          t          |                      d           d d d            d S # 1 swxY w Y   d S )NzfThis {} instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator.matchr   )formatr   raisesr   getattrr@   )rB   err_msgs     rT   !test_unfitted_feature_importancesr    s    	==CVD\\  
~W	5	5	5 C C!$'))+ABBBC C C C C C C C C C C C C C C C C Cs   #A!!A%(A%rQ   X_type)r  
sparse_csr
sparse_csczX, y, lower_bound_accuracy,  )r6   	n_classesr<   r\     ri   )r6   r  r8   r<   g?g
ףp=
?	oob_scoreTmicro)averagec                 \   t          ||          }t          ||dd          \  }}}}	 | dd|d          }
t          |
d          rJ t          |
d	          rJ |
                    ||           t	          |          r  ||	|
                    |                    }n#|
                    ||	          }|
j        |k    sJ t          ||
j        z
            }|d
k    sJ d|d            t          |
d          sJ t          |
d          rJ t          |
d	          sJ |j	        dk    r*|j
        d         t          t          |                    f}n?|j
        d         t          t          |dddf                             |j
        d         f}|
j        j
        |k    sJ dS )z5Check that OOB score is close to score on a test set.constructor_namer^   r   r{   (   TrE   r   r   r<   
oob_score_oob_decision_function_g)\(?z	abs_diff=z is greater than 0.11oob_prediction_r1   N)r"   r   r   rH   callablerK   rb   r(  r   ndimrP   rN   setr)  )rQ   rI   rJ   r  lower_bound_accuracyr   r   r   r   r   
classifier
test_scoreabs_diffexpected_shapes                 rT   test_forest_classifier_oobr3    s   > 	1v666A'7			( ( ($GVWf "!	  J z<00000z#;<<<<<NN7G$$$	 =Yvz'9'9&'A'ABB

%%ff55
$(<<<<<:
 5566Ht@@@@:|,,,,,z#455555:788888v{{!-*CAKK8!-*CAaaadG,=,=qwqzJ,2nDDDDDDrV   rm   zX, y, lower_bound_r2)r6   r7   	n_targetsr<   ffffff?g?c                    t          ||          }t          ||dd          \  }}}}	 | dd|d          }
t          |
d          rJ t          |
d	          rJ |
                    ||           t	          |          r  ||	|
                    |                    }n#|
                    ||	          }|
j        |k    sJ t          ||
j        z
            d
k    sJ t          |
d          sJ t          |
d	          sJ t          |
d          rJ |j	        dk    r|j
        d         f}n|j
        d         |j	        f}|
j        j
        |k    sJ dS )z\Check that forest-based regressor provide an OOB score close to the
    score on a test set.r$  r^   r   r{   2   Tr'  r(  r*  r   r)  r1   N)r"   r   r   rH   r+  rK   rb   r(  r   r,  rP   r*  )rm   rI   rJ   r  lower_bound_r2r   r   r   r   r   	regressorr0  r2  s                rT   test_forest_regressor_oobr:    s   . 	1v666A'7			( ( ($GVWf  	  I y,/////y"344444MM'7###	 6Yvy'8'8'@'@AA

__VV44
#~5555zI0011S88889l+++++9/00000y":;;;;;v{{!-*,!-*AF3$*n<<<<<<rV   r   c                      | dddd          }t          j        t          d          5  |                    t          j        t          j                   ddd           dS # 1 swxY w Y   dS )zfCheck that a warning is raised when not enough estimator and the OOB
    estimates will be inaccurate.r1   Tr   rE   r   r   r<   z"Some inputs do not have OOB scoresr  N)r   warnsUserWarningrH   r_   r`   ra   )r   	estimators     rT   test_forest_oob_warningr@  M  s      	  I 
k)M	N	N	N . .di---. . . . . . . . . . . . . . . . . .s   +A##A'*A'c                     t           j        }t           j        }d} | dd          }t          j        t
          |          5  |                    ||           ddd           dS # 1 swxY w Y   dS )zaCheck that we raise an error if OOB score is requested without
    activating bootstrapping.
    z6Out of bag estimation only available if bootstrap=TrueTFr   r   r  N)r_   r`   ra   r   r  
ValueErrorrH   )r   rI   rJ   r  r?  s        rT   (test_forest_oob_score_requires_bootstraprD  [  s    
 		AAFG$%@@@I	z	1	1	1  a                 s   A''A+.A+c                    t           j                            d          }t          j        }|                    ddt          j        j        d         df          }t          |          }|dk    sJ  | dd          }d	}t          j	        t          |
          5  |                    ||           ddd           dS # 1 swxY w Y   dS )zwCheck that we raise an error with when requesting OOB score with
    multiclass-multioutput classification target.
    rq   r   rh   r2   rs   zmulticlass-multioutputTrB  z:The type of target cannot be used to compute OOB estimatesr  N)r   r   r   r_   r`   r   rP   r,   r   r  rC  rH   )rQ   r   rI   rJ   y_typer?  r  s          rT   6test_classifier_error_oob_score_multiclass_multioutputrG  h  s   
 )


#
#C	A);Q(?@@AAF-----  44@@@IJG	z	1	1	1  a                 s   C  CCc           	      ,   t           j                            d          }t          j        }|                    ddt          j        j        d         df          } | dddd          }|                    ||           t          t          |          |j
                  }|j        d         d	z  }t          j        |dg          }t          |d
|                   D ]\  }}	d}
t          j        d          }|j        D ]l}t          |j        t          |          |          }||v rC|
dz  }
||                    |	                    dd                                                    z  }m||
z  ||<   t'          ||j        d
|                    d
S )zCheck that multioutput regression with integral values is not interpreted
    as a multiclass-multioutput target and OOB score can be computed.
    rq   r   r5   r2   rs      Tr<  r   Nr1   r0   )r   r   r   r_   r`   r   rP   rH   r   rN   max_samplesr  	enumerater  r   r<   rK   reshapesqueezer#   r*  )rm   r   rI   rJ   r?  n_samples_bootstrapn_samples_testoob_pred
sample_idxsamplen_samples_ooboob_pred_sampler  oob_unsampled_indicess                 rT   2test_forest_multioutput_integral_regression_targetrV  x  s   
 )


#
#C	A$)/!*<a)@AAA44a  I MM!Q23q669;PQQWQZ1_Nx+,,H'/>/(:;; 
? 
?
F(1++) 	Q 	QD$?!3q66+>% %! 222"4<<q"0E0E#F#F#N#N#P#PP.>Hi7HIIIIIrV   c                 L   t          j        t          d          5  t          |            d d d            n# 1 swxY w Y   t          j        t          d          5  t                                          t          t                     d d d            d S # 1 swxY w Y   d S )Nz"got an unexpected keyword argumentr  r   zOOB score not supported)r   r  	TypeErrorr   NotImplementedError_set_oob_score_and_attributesrI   rJ   rX  s    rT   +test_random_trees_embedding_raise_error_oobr\    s)   	y(L	M	M	M 2 2y11112 2 2 2 2 2 2 2 2 2 2 2 2 2 2	*2K	L	L	L C C<<QBBBC C C C C C C C C C C C C C C C C Cs   9= =-BB Bc                     t          |                      }t          |ddd          }|                    t          j        t          j                   d S )Nr1   r2   )rE   r   )rG   r   rH   r_   r`   ra   )rB   forestrR   s      rT   test_gridsearchr`    sI      %''F
vVLL
M
MCGGDIt{#####rV   c                    | t           v rt          j        }t          j        }n| t          v rt
          }t          }t          |          } |ddd          }|                    ||           t          |          dk    sJ |
                    d           |                    |          }|
                    d           |                    |          }t          ||d           dS )	z-Check parallel computations in classificationr5   r3   r   rE   r   r<   r1   r   r2   N)rG   r_   r`   ra   rj   rk   rl   r@   rH   rN   r   rK   r%   )rB   rI   rJ   r   r_  y1y2s          rT   test_parallelre    s     !!!IK	"	"	"'-O_"QQGGGF
JJq!v;;"
Q			B
Q			Bb"a(((((rV   c                 
   | t           v r+t          j        d d d         }t          j        d d d         }n)| t          v r t
          d d d         }t          d d d         }t          |          } |d          }|                    ||           |	                    ||          }t          j        |          }t          j        |          }t          |          |j        k    sJ |	                    ||          }||k    sJ d S )Nr2   r   r   )rG   r_   r`   ra   rj   rk   rl   r@   rH   rb   pickledumpsloadstype	__class__)	rB   rI   rJ   r   objrb   pickle_objectobj2score2s	            rT   test_picklerp    s     !!!IcccNK!	"	"	"##A#J##A#J'-O
/q
)
)
)CGGAqMMMIIaOOEL%%M<&&D::&&&&ZZ1FF??????rV   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          ||           | t          v rt          j        d	
          5  |                    |          }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 	 d d d            d S # 1 swxY w Y   d S d S )Nr/   r0   r1   r2   r   r3   Fr<   r   r   r   r   r2   r   r   )r@   rH   rK   r%   rG   r   r   r   rN   rP   r   	rB   r   r   r   r   r   y_predproba	log_probas	            rT   test_multioutputry    s~   
 
R	R	R	
A	
A	
A	Q	Q	Q	
B	
B	
BG 
Q	Q	Q	
A	
A	
A	Q	Q	Q	
A	
A	
AG 2hAQ!R1F1g1vAwA/F
D
!qE
B
B
BCWWWg&&..v66Fff---!!![))) 		0 		0%%f--Eu::????8>V++++8>V++++--f55Iy>>Q&&&&Q<%////Q<%/////		0 		0 		0 		0 		0 		0 		0 		0 		0 		0 		0 		0 		0 		0 		0 		0 		0 		0 "!s   B!FF
F
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          ||           t	          j        d          5  |                    |          }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 	 d d d            d S # 1 swxY w Y   d S )Nr/   r0   r1   r2   redbluegreenpurpleyellowr   Frr  r   r   rs  rt  )
r@   rH   rK   r&   r   r   r   rN   rP   r   ru  s	            rT   test_multioutput_stringr    s}   
 
R	R	R	
A	
A	
A	Q	Q	Q	
B	
B	
BG 
			'	'	'				(	(	(G 2hAQ!R1F		'		(	F D
!qE
B
B
BCWWWg&&..v66Fvv&&&	H	%	%	% 	, 	,!!&))5zzQQx~''''Qx~''''))&11	9~~""""|!V++++|!V+++++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s   B!E==FFc                    t           |          } |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dg           t          |j        ddgddgg           d S )Nr   r   r2   r0   r1   r/   )rG   rH   rI   rJ   r   r&   r   r   vstackr  rL   )rB   rQ   rR   _ys       rT   test_classes_shaper  ?  s     *$/ 

*
*
*
.
.q!
4
4C>Qs|b!W--- 
Arx{{Q'	(	(	*B


*
*
*
.
.q"
5
5Cs~1v...s|r1gAw%788888rV   c                      t          dd          } t          j        d          \  }}|                     |          }t	          |t
          j                  sJ d S )Nr5   F)rE   sparse_outputr^   factor)r   r   make_circlesfit_transform
isinstancer   ndarray)hasherrI   rJ   X_transformeds       rT   test_random_trees_dense_typer  R  s`    
 "rGGGF ,,,DAq((++M mRZ0000000rV   c                     t          ddd          } t          ddd          }t          j        d          \  }}|                     |          }|                    |          }t	          |                                |           d S )Nr5   Fr   )rE   r  r<   Tr^   r  )r   r   r  r  r&   toarray)hasher_densehasher_sparserI   rJ   X_transformed_denseX_transformed_sparses         rT   test_random_trees_dense_equalr  _  s    
 (u1  L )t!  M  ,,,DAq&44Q77(66q99 +33557JKKKKKrV   c                     t          dd          } t          j        d          \  }}|                     |          }t          dd          } t	          |                     |                              |                                          |                                           |j        d         |j        d         k    sJ t	          |	                    d          | j
                   t          d	          }|                    |          }t                      }|                    ||           |                    ||          d
k    sJ d S )NrI  r1   rD   r^   r  r   rw   r2   )n_componentsr   )r   r   r  r  r&   rH   	transformr  rP   r   rE   r   r    rb   )r  rI   rJ   r  svd	X_reduced
linear_clfs          rT   test_random_hasherr  r  s@   
 "rBBBF ,,,DAq((++M "rBBBFvzz!}}..q1199;;]=R=R=T=TUUU q!QWQZ////}((a(00&2EFFF
A
&
&
&C!!-00IJNN9a   Iq))S000000rV   csc_containerc                 &   t          j        d          \  }}t          dd          }|                    |          }|                     | |                    }t	          |                                |                                           d S )Nr   r   rI  r1   rD   )r   make_multilabel_classificationr   r  r&   r  )r  rI   rJ   r  r  r  s         rT   test_random_hasher_sparse_datar    s    2BBBDAq!rBBBF((++M!//a0@0@AA+3355}7L7L7N7NOOOOOrV   c                  P  	 t          d          } d\  }}|                     ||          |                     dd|          		fddD             }|                     ||          fd|D             }t          ||dd                    D ]\  }}t	          ||           d S )	N!0  )P   rI  r   r2   c                 \    g | ](}t          d |d                                        )S )r>   i90  rb  )r   rH   )r   r   r   r   s     rT   r   z'test_parallel_train.<locals>.<listcomp>  sO         	BvERRRVVW	
 	
  rV   )r1   r2   r3   r         c                 :    g | ]}|                               S r   )r   )r   rR   r   s     rT   r   z'test_parallel_train.<locals>.<listcomp>  s'    888Cc''888rV   r1   )r.   randnr   zipr%   )
r   r6   r7   clfsprobasproba1proba2r   r   r   s
          @@@rT   test_parallel_trainr    s    
U
#
#C"Izii	:..Gkk!Q	**G     +	  D YYy*--F88884888FffQRRj11 2 2!&&11112 2rV   c                     t          d          } |                     ddd          }|                     d          }dt          d	                              ||          }t          t                    }|j        D ]S}d
                    d t          |j
        j        |j
        j                  D                       }||xx         dz  cc<   Tt          fd|                                D                       }t          |          dk    sJ d|d         d         k    sJ d|d         d         k    sJ d|d         d         k    sJ d|d         d         k    sJ |d         d         dk    sJ |d         d         dk    sJ t!          j        d          }t           j                            ddd          |d d df<   t           j                            ddd          |d d df<   |                     d          }t          dd                              ||          }t          t                    }|j        D ]S}d
                    d t          |j
        j        |j
        j                  D                       }||xx         dz  cc<   Td |                                D             }t          |          dk    sJ d S )Nr  r   r   )r  r1   rv   r  r4   rq   rD    c              3   T   K   | ]#\  }}|d k    rd|t          |          fz  ndV  $dS r   z%d,%d/-Nr   r   fts      rT   r  z$test_distribution.<locals>.<genexpr>  V       
 
1 ()AvvXCFF##3
 
 
 
 
 
rV   r1   c                 *    g | ]\  }}d |z  z  |fS )r   r   )r   r  r   n_treess      rT   r   z%test_distribution.<locals>.<listcomp>  s+    WWWesU{W,d3WWWrV   rh   g?r2   r3   333333?z0,1/0,0/--0,2/--)r  r2   )rF   r<   c              3   T   K   | ]#\  }}|d k    rd|t          |          fz  ndV  $dS r  r  r  s      rT   r  z$test_distribution.<locals>.<genexpr>  r  rV   c                     g | ]	\  }}||f
S r   r   )r   r  r   s      rT   r   z%test_distribution.<locals>.<listcomp>  s     @@@ut}@@@rV   r  )r.   r   randr   rH   r   r   r  joinr  r  feature	thresholdsorteditemsrN   r   emptyr   )r   rI   rJ   rn   uniquesr  r  s         @rT   test_distributionr    s   
U
#
#C 	Aqy))AAG
7
D
D
D
H
HA
N
NC#G  ww 
 
DJ.
0DEE
 
 
 
 

 	WWWWw}}WWWXXG w<<1'!*Q-'!*Q-'!*Q-'!*Q-1:a=31:a=..... 	Ai1d++AaaadGi1d++AaaadGA
11
=
=
=
A
A!Q
G
GC#G  ww 
 
DJ.
0DEE
 
 
 
 

 	@@@@@Gw<<1rV   c                 Z   t           t          }}t          |          } |dddd                              ||          }|j        d                                         dk    sJ  |ddd                              ||          }|j        d                                         dk    sJ d S )Nr1   r   r   )r   max_leaf_nodesrE   r<   )r   rE   r<   )hastie_Xhastie_yr@   rH   r  	get_depthrB   rI   rJ   r   r   s        rT   test_max_leaf_nodes_max_depthr    s    XqA (-O
/AAA  	c!Qii  ?1''))Q....
/AAA
F
F
F
J
J1a
P
PC?1''))Q......rV   c                    t           t          }}t          |          } |ddd          }|                    ||           |j        d         j        j        dk    }|j        d         j        j        |         }t          j	        |          t          |          dz  dz
  k    sJ d                    |                        |ddd          }|                    ||           |j        d         j        j        dk    }|j        d         j        j        |         }t          j	        |          t          |          dz  dz
  k    sJ d                    |                       d S )Nr5   r1   r   )min_samples_splitrE   r<   r0   r^   Failed with {0})r  r  r@   rH   r  r  children_leftn_node_samplesr   minrN   r  )rB   rI   rJ   r   r   node_idxnode_sampless          rT   test_min_samples_splitr    sG   XqA'-O
/BQQ
O
O
OCGGAqMMMq!'5;H?1%+:8DL6,#a&&3,"22224E4L4LT4R4R222
/Caa
P
P
PCGGAqMMMq!'5;H?1%+:8DL6,#a&&3,"22224E4L4LT4R4R22222rV   c                    t           t          }}t          |          } |ddd          }|                    ||           |j        d         j                            |          }t          j        |          }||dk             }t          j	        |          dk    sJ d
                    |                        |ddd          }|                    ||           |j        d         j                            |          }t          j        |          }||dk             }t          j	        |          t          |          dz  dz
  k    sJ d
                    |                       d S )Nrh   r1   r   )r   rE   r<   r   r  g      ?)r  r  r@   rH   r  r  rO   r   r   r  r  rN   )rB   rI   rJ   r   r   outnode_counts
leaf_counts           rT   test_min_samples_leafr    sT   XqA (-O
/111
M
M
MCGGAqMMM
/!

"
(
(
+
+C+c""K[A-.J6*!!!#4#;#;D#A#A!!!
/4aa
P
P
PCGGAqMMM
/!

"
(
(
+
+C+c""K[A-.J6*A 11113D3K3KD3Q3Q11111rV   c                    t           t          }}t          |          }t          j                            d          }|                    |j        d                   }t          j        |          }t          j	        ddd          D ]} ||dd          }d| v rd|_
        |                    |||           |j        d         j                            |          }	t          j        |	|	          }
|
|
dk             }t          j        |          ||j        z  k    s#J d
                    | |j                              d S )Nr   r^   ri   r1   )min_weight_fraction_leafrE   r<   RandomForestFr   )weightsz,Failed with {0} min_weight_fraction_leaf={1})r  r  r@   r   r   r   r  rP   r   linspacer   rH   r  r  rO   r   r  r  r  )rB   rI   rJ   r   r   r  total_weightfracr   r  node_weightsleaf_weightss               rT   test_min_weight_fraction_leafr    sL   XqA (-O
)


"
"Chhqwqz""G6'??L AsA&& 
 
o%)
 
 
 T!!!CM1G,,,oa &,,Q//{3888#LA$56F<  L33O$OOOO9@@#.
 
 POOO
 
rV   sparse_containerc                    t          j        dd          \  }}t          |          } |dd                              ||          } |dd                               ||          |          }t	          |                    |          |                    |                     | t          v s	| t          v rPt	          |                    |          |                    |                     t	          |j	        |j	                   | t          v rlt	          |
                    |          |
                    |                     t	          |                    |          |                    |                     | t          v rt	          |                    |                                          |                    |                                                     t	          |                    |                                          |                    |                                                     d S d S )Nr   r7  )r<   r6   r2   )r<   r   )r   r  r@   rH   r%   rO   rG   rj   rK   r   r   r   FOREST_TRANSFORMERSr  r  r  )rB   r  rI   rJ   r   densesparses          rT   test_sparse_inputr  6  s   
 2RPPPDAq'-OOa888<<QBBE_!q999==>N>Nq>Q>QSTUUFfll1oou{{1~~>>>!!!T->%>%>!&.."3"3U]]15E5EFFF!')C	
 	
 	
 !!!!&"6"6q"9"95;N;Nq;Q;QRRR!$$Q'')@)@)C)C	
 	
 	
 """!Q''))5??1+=+=+E+E+G+G	
 	
 	
 	"  ##++--u/B/B1/E/E/M/M/O/O	
 	
 	
 	
 	
	 #"rV   c                 \   t          |          dd          }t          j        i ft          j        ddift          j        ddift          j        i ffD ]]\  }} |t          j        fd|i|}t          j        }t          |                    ||          	                    |          |           ^|j
        j        t          v rtt          t          z   t          z   D ]\} |t          j        |          }t          j        }t          |                    ||          	                    |          |           ]t          j        t          j        d d d	         |          }t          j        d d d	         }t          |                    ||          	                    |          |           d S )
Nr   Frr  orderCFr   r   r3   )r@   r   asarrayascontiguousarrayr_   r`   ra   r%   rH   rK   r?  splitterr!   r)   r*   r+   )rB   r   r   	containerkwargsrI   rJ   r  s           rT   test_memory_layoutr  Y  s    D
!qE
B
B
BC 
R	gs^$	gs^$		r"	 ? ?	6 Idi77u777K!#''!Q--"7"7":":A>>>> }!111 . ?. P 	C 	C  %888AA%cggamm&;&;A&>&>BBBB 	
49SSqS>///ACCaCAcggamm33A66:::::rV   c                    t           j        d d df         }t           j        d d df                             d          }t           j        }t	                      5  t
          |          }t          j        t                    5   |dd          	                    ||           d d d            n# 1 swxY w Y    |d          }|	                    ||           | t          v s	| t          v rFt          j        t                    5  |                    |           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr   r0   r1   r1   rD   r   )r_   r`   rL  ra   r'   r@   r   r  rC  rH   rG   rj   rK   )rB   rI   X_2drJ   r   r   s         rT   test_1d_inputr  w  s   	!!!Q$A9QQQT?""7++DA			 
 
+D1]:&& 	F 	FO;;;??1EEE	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F o1---a%%%1B)B)Bz**  A              
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s[   'E"B/#E/B3	3E6B3	7AED)E)D-	-E0D-	1EEE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   balancedclass_weightr<          @r   r   r1   r2   r1   r   g      Y@r2   )rG   rH   r_   r`   ra   r$   r   r   r  rL   r   rP   )	rB   rQ   clf1clf2
iris_multiclf3clf4r   r  s	            rT   test_class_weightsr    s    *$/ +++DHHTY$$$!DDDDHHTY$$$143LMMM DKdkBCCEJ$$$$$$

   D 	HHTY
###143LMMM!DDDDHHTY
###143LMMM GDK-..M$+"###s*###u--L+++DHHTY]333AFFFDHHTY$$$143LMMM +++DHHTY]A%5666AFFFDHHTY]333143LMMMMMrV   c                    t           |          }t          j        t          t          j        t                    dz  f          j        } |dd          }|                    t          |            |ddddddgd          }|                    t          |            |d	d          }|                    t          |           d S )
Nr2   r  r   r  r^   r   r  )r/   r2   balanced_subsample)rG   r   r  rJ   r  rL   rH   rI   )rB   rQ   r  rR   s       rT   5test_class_weight_balanced_and_bootstrap_multi_outputr
    s     *$/	Arx{{Q'	(	(	*B



C
C
CCGGArNNN

3''cc):):;!  C GGArNNN

(<1
M
M
MCGGArNNNNNrV   c                 L   t           |          }t          j        t          t          j        t                    dz  f          j        } |ddd          }|                    t          t                     d}t          j	        t          |          5  |                    t          |           d d d            n# 1 swxY w Y    |dd	d
gd          }t          j        t                    5  |                    t          |           d d d            d S # 1 swxY w Y   d S )Nr2   r  Tr   )r  
warm_startr<   JWarm-start fitting without increasing n_estimators does not fit new trees.r  r^   r   r  r  )rG   r   r  rJ   r  rL   rH   rI   r   r=  r>  r  rC  )rB   rQ   r  rR   warn_msgs        rT   test_class_weight_errorsr    s    *$/	Arx{{Q'	(	(	*B 

tRS
T
T
TCGGAqMMM 	U  
k	2	2	2  2               
cc):):(;!
L
L
LC	z	"	"  2                 s$   B;;B?B?0DD Dc                 8   t           t          }}t          |          }d }dD ]T}| ||dd          }n|                    |           |                    ||           t          |          |k    sJ U |ddd          }|                    ||           t          d |D                       t          d	 |D                       k    sJ t          |                    |          |                    |          d
	                    |                      d S )N)rh   r5   rq   T)rE   r<   r  rE   r5   Fc                     g | ]	}|j         
S r   r   r
  s     rT   r   z#test_warm_start.<locals>.<listcomp>  s    555d!555rV   c                     g | ]	}|j         
S r   r   r
  s     rT   r   z#test_warm_start.<locals>.<listcomp>  s    111t	111rV   r  )r  )
r  r  r@   r   rH   rN   r-  r&   rO   r  )rB   rI   rJ   r   est_wsrE   	est_no_wss          rT   test_warm_startr    sZ    XqA'-OF + +>$_)t  FF <888

1a6{{l*****RbUSSSIMM!Q55f55566#11y111; ;     Q++5F5M5Md5S5S     rV   c                    t           t          }}t          |          } |dddd          }|                    ||            |dddd          }|                    ||           |                    dd           |                    ||           t          |                    |          |                    |                     d S )Nrh   r1   FrE   r   r  r<   Tr2   )r  r<   )r  r  r@   rH   r   r%   rO   )rB   rI   rJ   r   r   est_2s         rT   test_warm_start_clearr    s     XqA'-O
/qA%VW
X
X
XCGGAqMMMO!1  E 
IIaOOO	A666	IIaOOOekk!nnciill;;;;;rV   c                 @   t           t          }}t          |          } |ddd          }|                    ||           |                    d           t          j        t                    5  |                    ||           d d d            d S # 1 swxY w Y   d S )Nrh   r1   T)rE   r   r  r   r  )r  r  r@   rH   r   r   r  rC  r  s        rT   $test_warm_start_smaller_n_estimatorsr    s     XqA'-O
/qA$
G
G
GCGGAqMMMNNN"""	z	"	"  1                 s   /BBBc                    t           t          }}t          |          } |dddd          }|                    ||            |dddd          }|                    ||           |                    d           d}t          j        t          |	          5  |                    ||           d d d            n# 1 swxY w Y   t          |	                    |          |	                    |                     d S )
Nrh   r3   Tr1   r  r2   r   r  r  )
r  r  r@   rH   r   r   r=  r>  r&   rO   )rB   rI   rJ   r   r   r  r  s          rT   "test_warm_start_equal_n_estimatorsr    s=    XqA'-O
/qA$UV
W
W
WCGGAqMMMO!1  E 
IIaOOO 
!$$$T  
k	2	2	2  		!Q               syy||U[[^^44444s   B<<C C c                 z   t           t          }}t          |          } |dddddd          }|                    ||            |dddddd          }|                    ||           |                    ddd           |                    ||           t          |d	          sJ |j        |j        k    sJ  |dddddd          }|                    ||           t          |d	          rJ |                    d
            t          |j                  ||           |j        |j        k    sJ d S )N   r3   Fr1   T)rE   r   r  r<   r   r   rh   )r  r   rE   r(  rX  )r  r  r@   rH   r   r   r(  r'   )rB   rI   rJ   r   r   r  est_3s          rT   test_warm_start_oobr"  5  s    XqA'-O
/  C GGAqMMMO  E 
IIaOOO	2FFF	IIaOOO5,'''''>U----- O  E 
IIaOOOul+++++	t$$$OEIq!$$$>U-------rV   c                    t           t          }}t          |          } |dddd          }t          j        |d|j                  5 }|                    ||           t          j        t          d          5  |                    ||           d d d            n# 1 swxY w Y   |
                                 d d d            d S # 1 swxY w Y   d S )Nr5   T)rE   r  r   r   r[  )wrapsz%Warm-start fitting without increasingr  )r  r  r@   r	   objectr[  rH   r   r=  r>  assert_called_once)rB   rI   rJ   r   r   !mock_set_oob_score_and_attributess         rT   test_oob_not_computed_twicer(  h  s]    XqA'-O
/DDD  C 
,C4U
 
 
 ?	*1\+-TUUU 	 	GGAqMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	*<<>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?s6   2C9BCB 	 C#B 	$CCCr   c                    t          dd          }t          j        |           }d dd |          D             }|                    ||                              |          }t          |j        |           t          ||           d S )Nr   Frr  c                     g | ]}|S r   r   )r   chs     rT   r   z&test_dtype_convert.<locals>.<listcomp>  s    ::::::rV   ABCDEFGHIJKLMNOPQRSTU)r   r   eyerH   rK   r&   r   )r  r/  rI   rJ   results        rT   test_dtype_convertr/  }  s    'Q%HHHJ
yA::-jyj9:::A^^Aq!!))!,,Fz*A...vq!!!!!rV   c                   	
 t           t          }}|j        d         }t          |          } |dddd          }|                    ||           |                    |          \  	
	j        d         
d         k    sJ 	j        d         |k    sJ t          t          j        
          d |j	        D                        |
                    |          }t          |j        d                   D ]L	
fdt          |d d f                   D             }t          |t          j        |	                     Md S )
Nr   rh   r1   Fr  r0   c                 &    g | ]}|j         j        S r   )r  
node_count)r   es     rT   r   z&test_decision_path.<locals>.<listcomp>  s    KKKaqw1KKKrV   c                 <    g | ]\  }}|         |z   f         S r   r   )r   r   r   est_id	indicatorn_nodes_ptrs      rT   r   z&test_decision_path.<locals>.<listcomp>  sA     
 
 
1 aV,q001
 
 
rV   )rP   )r  r  rP   r@   rH   decision_pathr&   r   diffr  rO   r   rK  r%   r   )rB   rI   rJ   r6   r   r   leavesleave_indicatorr5  r6  r7  s           @@@rT   test_decision_pathr<    sp   XqA
I'-O
/qA%VW
X
X
XCGGAqMMM ..q11I{?1R0000?1****
KK3?KKK  
 YYq\\FQ(( M M
 
 
 
 
 
!&F"344
 
 
 	"/273K3K3KLLLLM MrV   c                      t          j        dd          \  } }t          t          t          t
          g}|D ];} |d          }|                    | |           |j        D ]}|j        dk    sJ <d S )Nr   r1   r?   r   )min_impurity_decrease)	r   r   r   r   r   r   rH   r  r>  )rI   rJ   all_estimators	Estimatorr   r  s         rT   test_min_impurity_decreaserA    s    $sCCCDAq	N $ 5 5	ic2221O 	5 	5D -44444	55 5rV   c                     t          d          } t          j        d          }g d}d}t          j        t
          |          5  |                     ||           d d d            n# 1 swxY w Y   g d}d}t          j        t
          |          5  |                     ||           d d d            d S # 1 swxY w Y   d S )	Nr}   rW   )r3   r3   )r0   r1   r3   zNSome value\(s\) of y are negative which is not allowed for Poisson regression.r  )r   r   r   zLSum of y is not strictly positive which is necessary for Poisson regression.)r   r   r  r   r  rC  rH   )r   rI   rJ   r  s       rT   test_poisson_y_positive_checkrD    sR   
)
4
4
4C
A

A	/  
z	1	1	1  1               			A	0  
z	1	1	1  1                 s$   A))A-0A-B99B= B=c                   (     e Zd Z fdZ fdZ xZS )	MyBackendc                 H    d| _          t                      j        |i | d S )Nr   )r   super__init__)selfargsr  rk  s      rT   rI  zMyBackend.__init__  s,    
$)&)))))rV   c                 d    | xj         dz  c_         t                                                      S )Nr1   )r   rH  
start_call)rJ  rk  s    rT   rM  zMyBackend.start_call  s(    

a

ww!!###rV   )__name__
__module____qualname__rI  rM  __classcell__)rk  s   @rT   rF  rF    sQ        * * * * *$ $ $ $ $ $ $ $ $rV   rF  testingc                     t          dd          } t          j        d          5 \  }}|                     t          t
                     d d d            n# 1 swxY w Y   |j        dk    sJ t          j        d          5 \  }}|                     t                     d d d            n# 1 swxY w Y   |j        dk    sJ d S )Nr5   r2   )rE   r   rR  r   )r   joblibparallel_backendrH   rI   rJ   r   r   )rR   bar   _s       rT   test_backend_respectedrX    s/   
 b
;
;
;C		 	+	+ |F1               8a<<<< 
	 	+	+ wA!               8q======s#   $AAAB,,B03B0c                      t          dddd          \  } }t          ddd                              | |          }t          j        d|j                                        d	
          sJ d S )Nr   r3   r1   )r6   r8   r<   r  rh   rq      )r   r<   rE   gHz>)abs_tol)r   r   rH   mathiscloser   r   )rI   rJ   rR   s      rT   #test_forest_feature_importances_sumr^    s    AA  DAq !#  	c!Qii  <3377994HHHHHHHHrV   c                     t          j        d          } t          j        d          }t          d                              | |          }t          |j        t          j        dt           j                             d S )N)r5   r5   )r5   r5   r  r   )r   r  r   r   rH   r&   r   float64)rI   rJ   gbrs      rT   *test_forest_degenerate_feature_importancesrb    sh    
A
A
R
0
0
0
4
4Q
:
:Cs/"BJ1O1O1OPPPPPrV   c                     t          |          dd          }d}t          j        t          |          5  |                    t
          t                     d d d            d S # 1 swxY w Y   d S )NFr^   r   rJ  zl`max_sample` cannot be set if `bootstrap=False`. Either switch to `bootstrap=True` or set `max_sample=None`.r  )rA   r   r  rC  rH   rI   rJ   )rB   r   r  s      rT   test_max_samples_bootstrapre    s     (
-3
O
O
OC	 
 
z	1	1	1  1                 s   !A##A'*A'c                     t          |          dt          d                    }d}t          j        t          |          5  |                    t          t                     d d d            d S # 1 swxY w Y   d S )NTg    eArd  z=`max_samples` must be <= n_samples=6 but got value 1000000000r  )rA   r   r   r  rC  rH   rI   rJ   )rB   r   r  s      rT    test_large_max_samples_exceptionrg    s     (
-#c((
S
S
SCKE	z	/	/	/  1                 s   !A00A47A4c                    t          t          t          ddd          \  }}}}t          |          ddd          }|                    ||                              |          }t          |          dd d          }|                    ||                              |          }t          ||          }	t          ||          }
|	t          j        |
          k    sJ d S )Nr5  r  r   )
train_sizer|   r<   Tr   r   rJ  r<   )	r   rk   rl   rj   rH   rK   r   r   r   )rB   r   r   r   r   
ms_1_modelms_1_predictms_None_modelms_None_predictms_1_ms
ms_None_mss              rT   $test_max_samples_boundary_regressorsrq    s    '7u!( ( ($GVWf #4(Ca  J >>'733;;FCCL%d+Dq  M $''99AA&IIO v66G#OV<<JfmJ////////rV   c                    t          t          t          dt                    \  }}}}t          |          ddd          }|                    ||                              |          }t          |          dd d          }|                    ||                              |          }t          j                            ||           d S )Nr   )r<   stratifyTr   rj  )	r   r   r   rG   rH   r   r   rR  r#   )	rB   r   r   r   rW  rk  
ms_1_probarm  ms_None_probas	            rT   %test_max_samples_boundary_classifiersrv  $  s    "2q7# # #GVWa $D)Ca  J 11??GGJ&t,Dq  M "%%gw77EEfMMMJz=99999rV   csr_containerc                     g dg} | g dg          }t                      }d}t          j        t          |          5  |                    ||           d d d            d S # 1 swxY w Y   d S )Nr   r   z3sparse multilabel-indicator for y is not supported.r  )r   r   r  rC  rH   )rw  rI   rJ   r   msgs        rT   test_forest_y_sparserz  7  s    	Ayyyk""A
 
"
"C
?C	z	-	-	-  1                 s   A##A'*A'ForestClassc                    t           j                            d          }|                    dd          }|                    d          dk    } | d|d           } | d|d          }|                    ||           |                    ||           |j        d         j        }|j        d         j        }d}|j        |j        k    s
J |            d S )Nr1   i'  r2   r   )rE   r<   rJ  z=Tree without `max_samples` restriction should have more nodes)r   r   r   r  rH   r  r  r2  )	r{  r   rI   rJ   est1est2tree1tree2ry  s	            rT   'test_little_tree_with_small_max_samplesr  A  s    
)


"
"C		%A		%1A ;  D ;  D 	HHQNNNHHQNNNQ%EQ%E
ICe.........rV   Forestc                     ddl m} t                              dd          }|j        \  }} |||          }t          |          dd|          }|                    t          |           d S )Nr   )MSEr0   r1   r2   )rE   r   rW   )sklearn.tree._criterionr  rl   rL  rP   rj   rH   rk   )r  r  rJ   r6   	n_outputsmse_criterionr   s          rT   -test_mse_criterion_object_segfault_smoke_testr  `  sy     ,+++++b!A7IyC	9--M
F
#1
V
V
VCGGE1rV   c                  @   t           j                            d          } t          j        |                     dd                    }t          dddd                              |          }|                                }d dD             }t          ||           d	S )
z3Check feature names out for Random Trees Embedding.r   r   r   r2   F)rE   r   r  r<   c                 $    g | ]\  }}d | d| S )randomtreesembedding_rW  r   )r   r  leafs      rT   r   zAtest_random_trees_embedding_feature_names_out.<locals>.<listcomp>x  s>        D$ 	.--t--  rV   ))r   r2   )r   r3   )r   rh   )r   ri   r^  )r1   r3   )r1   rh   )r1   ri   N)	r   r   r   r   r  r   rH   get_feature_names_outr&   )r<   rI   r  namesexpected_namess        rT   -test_random_trees_embedding_feature_names_outr  p  s    9((++L
|!!#q))**A!!5q  	c!ff  ((**E 	
	  N ~u-----rV   c                 F   |                     t          j        j        dt	          t
          d                     t          j                            d          }t          dd|          \  }} | |d	          }t          d
|          }t          |||d
           dS )zRandomForestClassifier must work on readonly sparse data.

    Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/25333
    r-   r   )
max_nbytesr   )seedrZ  r=   Tr   r2   )r   r<   )cvN)setattrsklearnensemble_forestr   r-   r   r   r   r   r   r   )rw  monkeypatchr   rI   rJ   rR   s         rT   test_read_only_bufferr    s      S)))  
 )

Q

'
'C3OOODAqad###A
 
<
<
<CCA!$$$$$$rV   r  r	  c                     t          j        d          \  }}t          dd| d          }|                    ||           dS )z^Check low max_samples works and is rounded to one.

    Non-regression test for gh-24037.
    T)
return_X_yr5   g-C6?r   )rE   rJ  r  r<   N)r   	load_winer   rH   )r  rI   rJ   r_  s       rT   .test_round_samples_to_one_when_samples_too_lowr    sU     ...DAq#TST  F JJq!rV   r  r   c                     t          dd          \  }}|rd}nd} | d|d||          }|                    ||           |j                                        }t	          ||j                   |j        }t          |t                    sJ t          |          t          |          k    sJ |d         j	        t          j        k    sJ t          t          |                    D ]}	|rlt          ||	                   t          |          d	z  k    sJ t          t          j        ||	                             t          ||	                   k     sJ pt          t          ||	                             t          |          k    sJ d}
||
         }||
         }||         }||         }|j        j        }t#          |          }|                    ||           |j        j        }t%          ||           dS )
zEstimators_samples_ property should be consistent.

    Tests consistency across fits and whether or not the seed for the random generator
    is set.
    rZ  r1   r?   r^   Nr5   )rE   rJ  rF   r<   r   r   r2   )r   rH   estimators_samples_r   r&   r  r  r   rN   r   r   int32r   r   r-  r  valuer   r#   )r{  r   r  rI   rJ   rJ  r   estimators_samples
estimatorsr   estimator_indexestimator_samplesr?  r   r   orig_tree_valuesnew_tree_valuess                    rT   test_estimators_samplesr    s"    c:::DAq 
+  C GGAqMMM05577 )3+BCCCJ($/////!""c*oo5555a &"(22223z??## = = 	=)!,--Q1<<<< ry!3A!677883?QRS?T;U;UUUUUUs-a01122c!ff<<<<<O*?;?+I!"G!"G ,i  IMM'7###o+O$o66666rV   zmake_data, Forestc                    t           j                            d          }d\  }} | |||          \  }}|                                }t           j        ||                    ddg|j        ddg          <   t          j        |                                          sJ t          ||d	          \  }}	}
} ||d
          }|
                    ||
           |                    |	|          }t          ||d	          \  }}}
} ||d
          }|
                    ||
           |                    ||          }|d|z  k    sJ dS )zJCheck that forest can deal with missing values and has decent performance.r   )r  r5   r=   FTffffff?r   rv   r   r   r7  )r<   rE   r   N)r   r   r   r   nanchoicerP   isnananyr   rH   rb   )	make_datar  r   r6   r7   rI   rJ   	X_missingX_missing_trainX_missing_testr   r   forest_with_missingscore_with_missingr   r   r_  score_without_missings                     rT    test_missing_values_is_resilientr    sw    )


"
"C$Iz9yZcRRRDAq IIKIcjj%QWtjEEF8I""$$$$$7G118 8 84O^Wf
 !&cCCCOW555,22>6JJ (811'M'M'M$GVWfV2666F
JJw   "LL88 (=!=======rV   c                 ,   t           j                            d          }d}d}|                    |df          }|                    dd|          }|                    dd	g|d
dg          }|                    t                    }||          ||<   |                    |          }t           j        ||<   t          j	        |          
                                sJ |                                }	||	dddf<   t          |	||d          \  }
}}}}} | d                              |
|          } | d                              ||          }|                    ||          }||k    sJ ||                    ||          k    sJ dS )z_Check that the forest learns when missing values are only present for
    a predictive feature.r   r  g      ?r5   r  r2   )ru   rv   FTr  r   r  Nrh   r   )r   r   r   standard_normalr   r  r   r   r  r  r  r   r   rH   rb   )r  r   r6   expected_scoreX_non_predictiverJ   X_random_masky_maskpredictive_featureX_predictiveX_predictive_trainX_predictive_testX_non_predictive_trainX_non_predictive_testr   r   forest_predictiveforest_non_predictivepredictive_test_scores                      rT    test_missing_value_is_predictiver    s    )


"
"CIN**B*@@AAI..A JJt}9tJMMMXXd^^F#M22F=,,),<<!#v8&''++-----#((**L+LA 	'7KKKA...223EwOO"F222667MwWW-334EvNN N2222 $9$?$?v% %      rV   c                    t          j        g dt           j        ddgg          }ddg} | d          }d}t          j        t
          |	          5  |                    ||           d
d
d
           d
S # 1 swxY w Y   d
S )zDRaise error for unsupported criterion when there are missing values.r  r   r   r^   r   re   rC  z .*does not accept missing valuesr  N)r   r  r  r   r  rC  rH   )r  rI   rJ   r_  ry  s        rT   =test_non_supported_criterion_raises_error_with_missing_valuesr  >  s     	)))bfa-.//A	c
AV.///F
,C	z	-	-	-  

1a                 s   A77A;>A;)r   )__doc__	itertoolsr\  rg  collectionsr   	functoolsr   r   r   typingr   r   unittest.mockr	   rT  numpyr   r   scipy.specialr
   r  r   r   sklearn.datasetsr   r   sklearn.decompositionr   sklearn.dummyr   sklearn.ensembler   r   r   r   r   sklearn.ensemble._forestr   r   sklearn.exceptionsr   sklearn.metricsr   r   r   r   sklearn.model_selectionr   r   r   sklearn.svmr    sklearn.tree._classesr!   sklearn.utils._testingr"   r#   r$   r%   r&   r'   r(   sklearn.utils.fixesr)   r*   r+   sklearn.utils.multiclassr,   sklearn.utils.parallelr-   sklearn.utils.validationr.   rI   rJ   rL   rM   r   r   	load_irisr_   r   permutationra   rv   permr`   make_regressionrk   rl   r  r  r   float32parallelget_active_backendrk  DEFAULT_JOBLIB_BACKENDrG   rj   r  dictr@   str__annotations__updater   rA   markparametrizerU   rc   ro   r   r   r   r   r`  chainr   r  r  r   r  r3  r:  r@  rD  rG  rV  r\  r`  re  rp  ry  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r  r  r  r  r"  r(  r/  r<  rA  rD  rF  register_parallel_backendrX  r^  rb  re  rg  rq  rv  rz  r  r  r  r  r  r  r  r  r  r   rV   rT   <module>r     s           # # # # # #       + + + + + + + +                            # # # # # # # # B B B B B B B B . . . . . . ( ( ( ( ( (                     . - - - - -            T S S S S S S S S S ! ! ! ! ! ! 2 2 2 2 2 2                  O N N N N N N N N N 3 3 3 3 3 3 + + + + + + 7 7 7 7 7 7 	"XBx"bAq6Aq6Aq6:"X1v1vjj 08/    x
t{'((IdO	k$ (x'#"STUUUu /X.!LLL (??2:&&  ;;==a@J  14   /2   0  %)DFF 4S> * * *   + , , ,   * + + +   , - - -0B0G0G0I0I tCH~ I I I  $ $%6 7 7 7 !344< < 54<& !344&:;;W W <; 54W" !233D    4322/ 2/ 2/j &BCC> > DC>& !233( ( 43( !344
 
 54
  2:rz":;;IO"VZ$899!#V#V#VWW  'H 'H  <;'HTj@ j@ j@Z !233C C 43C +-?-F-F-H-HII#H#H#HII 	
)X)C1STUUU	
	
 	
	
)X)!11  	
 		
 	
 IK!Oa	

	
4X4sQRSSS	
	
 	
! 0 tWWXw-O-O-O&PQQ'E 'E RQ1  JI JI6'ET *,=,D,D,F,FGG#H#H#HII	
%X%"  	
 		
 	
	
%X%"  	
 		
 	
 " t-E&FGG%= %= HG#  JI HG(%=P *,I,P,P,R,RSS
. 
. TS
. *,I,P,P,R,RSS	 	 TS	 +-?-F-F-H-HII  JI *,=,D,D,F,FGGJ J HGJ: tUm44C C 54C !344$ $ 54$ !>??) ) @?), !>??  @?* !>??00 00 @?00f !3444, 4, 544,n !3449 9 549$
1 
1 
1L L L&1 1 1. .99P P :9P2 2 2&3 3 3l !233/ / 43/ !233S S 43S& !233R R 43R. !233
 
 43
> !2337.H 
 
  43
> !>??2:rz":;;; ; <; @?;8 !233  43$ !344,N ,N 54,N^ !344  54 !344  54* !233  438 !233< < 43<" !233  43 !2335 5 4352 !>??/. /. @?/.d !>??? ? @??(" " " " !>??M M @?M05 5 5$  ,$ $ $ $ $& $ $ $ !  I 6 6 6   I I IQ Q Q !>??	 	 @?	 !>??  @? !2330 0 430* !344: : 54:$ .99  :9 )?AV(WXX4 4 YX4< #455  65. . .4 .99% % :9%& *>)EFF	 	 GF	 $++tUm44(E(L(L(N(NOO37 37 PO 54 ,+37l 		!#89		%'=>		!#67		%';<	 > > >> 	 & & &R #4#;#;#=#=>>	 	 ?>	 	 	rV   