
    ri<                        d 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mZ ddlmZmZmZmZmZmZmZmZ dd	lmZ dd
l m!Z! ddl"m#Z#m$Z$ 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/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5 ddl6m7Z7m8Z8m9Z9m:Z:m;Z; ddl<m=Z=m>Z> ddl?m@Z@ ddlAmBZBmCZCmDZD ddlEmFZFmGZG  e@d      ZH e       ZIeHj                  eIj                  j                        ZMeIj                  eM   eI_N        eIj                  eM   eI_K         e       ZOeHj                  eOj                  j                        ZMeOj                  eM   eO_N        eOj                  eM   eO_K        d ZPe	j                  j                  d eeGeFz   dddddddddddddd dddd!gg d"            d#        ZSd$ ZTe	j                  j                  d%eGeFz         d&        ZU G d' d(e      ZVd) ZWd* ZXd+ ZYd, ZZd- Z[d. Z\d/ Z]d0 Z^e	j                  j                  d1        Z`d2 Zae	j                  j                  d3        Zbd4 Zcdbd5Zdd6 Zed7 Zfd8 Zgd9 Zhd: Zid; Zj G d< d=e      Zk G d> d?e      Zle	j                  j                  d@eeg      e	j                  j                  dAddg      e	j                  j                  dBddg      e	j                  j                  dCdDdEg      dF                             ZmdG ZndH ZodI ZpdJ ZqdK ZrdL ZsdM ZtdN ZudO ZvdP ZwdQ ZxdR Zye	j                  j                  dS e edTU            df e edTU            df e e#             df e e5             dfg      dV        Zz edW      e	j                  j                  dX e edTY      dTZ       e edTY      dTZ      g      d[               Z{e	j                  j                  d\e9d]d]fe8d^d_fe7d^d]fg       edW      d`               Z|e	j                  j                  dX e edTY      dTZ       e edTY      dTZ      g      da        Z}y)czE
Testing for the bagging ensemble module (sklearn.ensemble.bagging).
    N)cycleproduct)config_context)BaseEstimator)load_diabetes	load_irismake_hastie_10_2)DummyClassifierDummyRegressor)AdaBoostClassifierAdaBoostRegressorBaggingClassifierBaggingRegressorHistGradientBoostingClassifierHistGradientBoostingRegressorRandomForestClassifierRandomForestRegressor)_get_n_samples_bootstrap)SelectKBest)LogisticRegression
Perceptron)GridSearchCVParameterGridtrain_test_split)KNeighborsClassifierKNeighborsRegressor)make_pipeline)FunctionTransformerscale)SparseRandomProjection)SVCSVR)"ConsumingClassifierWithOnlyPredict)ConsumingClassifierWithoutPredictLogProba&ConsumingClassifierWithoutPredictProba	_Registrycheck_recorded_metadata)DecisionTreeClassifierDecisionTreeRegressor)check_random_state)assert_allcloseassert_array_almost_equalassert_array_equal)CSC_CONTAINERSCSR_CONTAINERSc                     t        d      } t        t        j                  t        j                  |       \  }}}}t        ddgddgddgddgd	      }d t               t        d
      t        d      t               t               g}t        |t        |            D ]3  \  }}t        d|| dd|j                  ||      j                  |       5 y )Nr   random_state      ?      ?      TFmax_samplesmax_features	bootstrapbootstrap_features   max_iter   )	max_depth)	estimatorr2   n_estimators )r*   r   irisdatatargetr   r
   r   r(   r   r!   zipr   r   fitpredict)	rngX_trainX_testy_trainy_testgrid
estimatorsparamsrA   s	            a/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/sklearn/ensemble/tests/test_bagging.pytest_classificationrS   H   s    
Q
C'7		4;;S($GVWf :F#'-		
D 	B+J !uZ'89 0	 	
	
 		

 #gw
0    z sparse_container, params, methodr3   r?   Tr7   r4   r6   Fr9   r:   r;   r8   r:   r;   )rI   predict_probapredict_log_probadecision_functionc                 l    G d dt               }t        d      }t        t        t        j
                        t        j                  |      \  }}}} | |      }	 | |      }
t        d
 |dd      dd	|j                  |	|      } t        ||      |
      }t        d
 |dd      dd	|j                  ||      } t        ||      |      }t        ||       t        |	      }|j                  D cg c]  }|j                   }}t        |D cg c]  }||k(  	 c}      sJ y c c}w c c}w )Nc                   "     e Zd ZdZ fdZ xZS )-test_sparse_classification.<locals>.CustomSVC7SVC variant that records the nature of the training setc                 H    t         |   ||       t        |      | _        | S NsuperrH   type
data_type_selfXy	__class__s      rR   rH   z1test_sparse_classification.<locals>.CustomSVC.fit   !    GK1"1gDOKrT   __name__
__module____qualname____doc__rH   __classcell__rh   s   @rR   	CustomSVCr\          E	 	rT   rq   r   r1   linearovr)kerneldecision_function_shaper5   rA   r2   rC   )r!   r*   r   r   rD   rE   rF   r   rH   getattrr,   rb   estimators_rc   all)sparse_containerrQ   methodrq   rJ   rK   rL   rM   rN   X_train_sparseX_test_sparsesparse_classifiersparse_resultsdense_classifierdense_resultssparse_typeitypests                      rR   test_sparse_classificationr   i   sK   4C  Q
C'7dii$++C($GVWf &g.N$V,M) 8UK  
c.'"	 
 8W.7FN ) 8UK  
c'7	 
 6G,f5f=Mnm<~&K#4#@#@AaQ\\AEA%0Q[ 0111 B0s   8D,D1c                  t   t        d      } t        t        j                  d d t        j                  d d |       \  }}}}t        ddgddgddgddgd      }d t               t               t               t               fD ]6  }|D ]/  }t        d
|| d	|j                  ||      j                  |       1 8 y )Nr   2   r1   r3   r4   TFr7   rw   rC   )r*   r   diabetesrE   rF   r   r   r)   r   r"   r   rH   rI   )rJ   rK   rL   rM   rN   rO   rA   rQ   s           rR   test_regressionr      s    
Q
C'7crHOOCR0s($GVWf : #J#'-		
D 	 
	  	FMysMfMQQgfo	
rT   r{   c                    t        d      }t        t        j                  d d t        j                  d d |      \  }}}} G d dt
              }ddddd	d
dddd	ddddddddg} | |      } | |      }	|D ]  }
t        d |       dd|
j                  ||      }|j                  |	      }t        d |       dd|
j                  ||      j                  |      }t        |      }|j                  D cg c]  }|j                   }}t        ||       t        |D cg c]  }||k(  	 c}      sJ t        ||        y c c}w c c}w )Nr   r   r1   c                   "     e Zd ZdZ fdZ xZS ))test_sparse_regression.<locals>.CustomSVRr]   c                 H    t         |   ||       t        |      | _        | S r_   r`   rd   s      rR   rH   z-test_sparse_regression.<locals>.CustomSVR.fit   ri   rT   rj   rp   s   @rR   	CustomSVRr      rr   rT   r   r3   r?   Tr7   r4   r6   FrU   rV   r5   rw   rC   )r*   r   r   rE   rF   r"   r   rH   rI   rb   ry   rc   r,   rz   )r{   rJ   rK   rL   rM   rN   r   parameter_setsr}   r~   rQ   r   r   r   r   r   r   r   s                     rR   test_sparse_regressionr      s    Q
C'7crHOOCR0s($GVWfC  "&		
 "&		
 dK$eLN" &g.N$V,M  A, 
k
5;

#ng
& 	 +22=A My{MfMS'"WV_ 	 >*'8'D'DE!EE!.-@e4A$4555!.-@'A F 5s   <E
&E
c                       e Zd Zd Zd Zy)DummySizeEstimatorc                 `    |j                   d   | _        t        j                  |      | _        y Nr   )shapetraining_size_joblibhashtraining_hash_re   rf   rg   s      rR   rH   zDummySizeEstimator.fit   s"    ggaj$kk!nrT   c                 F    t        j                  |j                  d         S r   )nponesr   re   rf   s     rR   rI   zDummySizeEstimator.predict  s    wwqwwqz""rT   N)rk   rl   rm   rH   rI   rC   rT   rR   r   r      s    -#rT   r   c                  
   t        d      } t        t        j                  t        j                  |       \  }}}}t               j                  ||      }t        t               dd|       j                  ||      }|j                  ||      |j                  ||      k(  sJ t        t               dd|       j                  ||      }|j                  ||      |j                  ||      kD  sJ t        t               d      j                  ||      }g }|j                  D ];  }|j                  |j                  d   k(  sJ |j                  |j                         = t        t!        |            t        |      k(  sJ y )Nr   r1   r4   F)rA   r8   r:   r2   T)rA   r:   )r*   r   r   rE   rF   r)   rH   r   scorer   ry   r   r   appendr   lenset)rJ   rK   rL   rM   rN   rA   ensembletraining_hashs           rR   test_bootstrap_samplesr     sw   
Q
C'7xS($GVWf &'++GW=I  ')	
 
c'7  ??7G,w0PPPP  ')	
 
c'7  ??7G,x~~gw/OOOO
  *<*>$OSSH M)) 7	''7==+;;;;Y5567 s=!"c-&8888rT   c                  `   t        d      } t        t        j                  t        j                  |       \  }}}}t        t               dd|       j                  ||      }|j                  D ]D  }t        j                  j                  d   t        j                  |      j                  d   k(  rDJ  t        t               dd|       j                  ||      }|j                  D ]D  }t        j                  j                  d   t        j                  |      j                  d   kD  rDJ  y )Nr   r1   r4   F)rA   r9   r;   r2   r5   T)r*   r   r   rE   rF   r   r)   rH   estimators_features_r   r   unique)rJ   rK   rL   rM   rN   r   featuress          rR   test_bootstrap_featuresr   1  s   
Q
C'7xS($GVWf  ') 	
 
c'7  11 F}}""1%8)<)B)B1)EEEEF  ')	
 
c'7  11 E}}""1%		((;(A(A!(DDDDErT   c            	         t        d      } t        t        j                  t        j                  |       \  }}}}t        j                  dd      5  t        t               |       j                  ||      }t        t        j                  |j                  |      d      t        j                  t        |                   t        |j                  |      t        j                  |j!                  |                   t        t#               | d	      j                  ||      }t        t        j                  |j                  |      d      t        j                  t        |                   t        |j                  |      t        j                  |j!                  |                   d d d        y # 1 sw Y   y xY w)
Nr   r1   ignore)divideinvalidrw   r5   )axis   )rA   r2   r8   )r*   r   rD   rE   rF   r   errstater   r(   rH   r,   sumrW   r   r   exprX   r   rJ   rK   rL   rM   rN   r   s         rR   test_probabilityr   M  sY   
Q
C'7		4;;S($GVWf 
Hh	7 
$,.S

#gw
 	 	"FF8))&1:BGGCK<P	
 	"""6*BFF83M3Mf3U,V	

 %(*!

#gw
 	 	"FF8))&1:BGGCK<P	
 	"""6*BFF83M3Mf3U,V	
/
 
 
s   EF99Gc            	         t        d      } t        t        j                  t        j                  |       \  }}}}t               t               fD ]  }t        |ddd|       j                  ||      }|j                  ||      }t        ||j                  z
        dk  sJ d}t        j                  t        |      5  t        |d	dd|       }|j                  ||       d d d         y # 1 sw Y   xY w)
Nr   r1   d   TrA   rB   r:   	oob_scorer2   皙?{Some inputs do not have OOB scores. This probably means too few estimators were used to compute any reliable oob estimates.matchr5   )r*   r   rD   rE   rF   r(   r!   r   rH   r   abs
oob_score_pytestwarnsUserWarning)	rJ   rK   rL   rM   rN   rA   clf
test_scorewarn_msgs	            rR   test_oob_score_classificationr   p  s    Q
C'7		4;;S($GVWf -.6 &	
 #gw
 	 YYvv.
:./#555J 	 \\+X6 	&## C GGGW%	& 	&%&$	& 	&s   >#C,,C5	c                     t        d      } t        t        j                  t        j                  |       \  }}}}t        t               ddd|       j                  ||      }|j                  ||      }t        ||j                  z
        dk  sJ d}t        j                  t        |      5  t        t               d	dd|       }|j                  ||       d d d        y # 1 sw Y   y xY w)
Nr   r1   r   Tr   r   r   r   r5   )r*   r   r   rE   rF   r   r)   rH   r   r   r   r   r   r   )	rJ   rK   rL   rM   rN   r   r   r   regrs	            rR   test_oob_score_regressionr     s     Q
C'7xS($GVWf ') 
c'7  66*JzCNN*+c111	F  
k	2 #+-
 	'"# # #s   /+C##C,c                  P   t        d      } t        t        j                  t        j                  |       \  }}}}t        t               ddd|       j                  ||      }t               j                  ||      }t        |j                  |      |j                  |             y )Nr   r1   r5   F)rA   rB   r:   r;   r2   )
r*   r   r   rE   rF   r   r   rH   r,   rI   )rJ   rK   rL   rM   rN   clf1clf2s          rR   test_single_estimatorr     s    
Q
C'7xS($GVWf %'  
c'7 	  $$Wg6Ddll62DLL4HIrT   c                      t         j                  t         j                  }} t               }t	        t        |      j                  | |      d      rJ y )NrY   )rD   rE   rF   r(   hasattrr   rH   )rf   rg   bases      rR   
test_errorr     sB    99dkkqA!#D(.221a8:MNNNNrT   c                     t        t        j                  t        j                  d      \  } }}}t	        t               dd      j                  | |      }|j                  |      }|j                  d       |j                  |      }t        ||       t	        t               dd      j                  | |      }|j                  |      }t        ||       t	        t        d      dd      j                  | |      }|j                  |      }|j                  d       |j                  |      }	t        ||	       t	        t        d      dd      j                  | |      }|j                  |      }
t        ||
       y )	Nr   r1      n_jobsr2   r5   r   rt   )rv   )r   rD   rE   rF   r   r(   rH   rW   
set_paramsr,   r!   rY   )rK   rL   rM   rN   r   y1y2y3
decisions1
decisions2
decisions3s              rR   test_parallel_classificationr     sj   '7		4;;Q($GVWf ! 	c'7 
 
			'Bq!				'Bb"%  	c'7  
			'Bb"% !E*11	c'7  ++F3Jq!++F3Jj*5 E*11	c'7  ++F3Jj*5rT   c                     t        d      } t        t        j                  t        j                  |       \  }}}}t        t               dd      j                  ||      }|j                  d       |j                  |      }|j                  d       |j                  |      }t        ||       t        t               dd      j                  ||      }|j                  |      }t        ||       y )Nr   r1   r   r   r5   r   r?   )r*   r   r   rE   rF   r   r)   rH   r   rI   r,   )	rJ   rK   rL   rM   rN   r   r   r   r   s	            rR   test_parallel_regressionr     s     Q
C'7xS($GVWf   5 7PQRVVH q!			&	!Bq!			&	!Bb"% 5 7PQRVVH 
		&	!Bb"%rT   c                      t         j                  t         j                  }} d||dk(  <   ddd}t        t	        t                     |d      j                  | |       y )Nr5   r?   )r5   r?   )rB   estimator__Croc_auc)scoring)rD   rE   rF   r   r   r!   rH   )rf   rg   
parameterss      rR   test_gridsearchr     sP     99dkkqAAa1fI #)&AJ"35):yIMMaQRSrT   c                     t        d      } t        t        j                  t        j                  |       \  }}}}t        d dd      j                  ||      }t        |j                  t              sJ t        t               dd      j                  ||      }t        |j                  t              sJ t        t               dd      j                  ||      }t        |j                  t              sJ t        t        j                  t        j                  |       \  }}}}t        d dd      j                  ||      }t        |j                  t              sJ t        t               dd      j                  ||      }t        |j                  t              sJ t        t               dd      j                  ||      }t        |j                  t              sJ y )Nr   r1   r   r   )r*   r   rD   rE   rF   r   rH   
isinstance
estimator_r(   r   r   r   r)   r"   r   s         rR   test_estimatorr   (  s    Q
C (8		4;;S($GVWf !aa@DDWgVHh))+ABBB  	c'7  h))+ABBB aaHLLH h)):666 (8xS($GVWf  QQ?CCGWUHh))+@AAA 5 7PQRVVH h))+@AAAaa@DDWgVHh))3///rT   c                     t        t        t        d      t                     d      } | j	                  t
        j                  t
        j                         t        | d   j                  d   d   j                  t              sJ y )Nr5   )kr?   )r9   r   )r   r   r   r(   rH   rD   rE   rF   r   stepsr2   intrA   s    rR   test_bagging_with_pipeliner   U  sd    !kA&(>(@APQI MM$))T[[)il((,Q/<<cBBBrT   c                    t        dd      \  }}d }dD ]G  }|t        || d      }n|j                  |       |j                  ||       t	        |      |k(  rGJ  t        d| d	      }|j                  ||       t        |D cg c]  }|j                   c}      t        |D cg c]  }|j                   c}      k(  sJ y c c}w c c}w )
Nr<   r5   	n_samplesr2   )r   
   T)rB   r2   
warm_startrB   r   F)r	   r   r   rH   r   r   r2   )r2   rf   rg   clf_wsrB   	clf_no_wstrees          rR   test_warm_startr   ]  s     bq9DAqF +>&)QUF <8

1a6{l***+ "luI MM!Qf5d!!56#'01t		1;   51s   C	*C
c                     t        dd      \  } }t        dd      }|j                  | |       |j                  d       t	        j
                  t              5  |j                  | |       d d d        y # 1 sw Y   y xY w)	Nr<   r5   r   r   T)rB   r   r6   r   )r	   r   rH   r   r   raises
ValueErrorrf   rg   r   s      rR   $test_warm_start_smaller_n_estimatorsr  w  sg    bq9DAq
t
<CGGAqMNNN"	z	" 1  s   A77B c                  t   t        dd      \  } }t        | |d      \  }}}}t        ddd	      }|j                  ||       |j	                  |      }|d
z  }d}t        j                  t        |      5  |j                  ||       d d d        t        ||j	                  |             y # 1 sw Y   %xY w)Nr<   r5   r   +   r1   r   TS   rB   r   r2   r4   z;Warm-start fitting without increasing n_estimators does notr   )	r	   r   r   rH   rI   r   r   r   r-   )	rf   rg   rK   rL   rM   rN   r   y_predr   s	            rR   "test_warm_start_equal_n_estimatorsr	    s    bq9DAq'712'N$GVWf
t"
MCGGGW[[ FsNGLH	k	2 "!"vs{{623" "s   7B..B7c                  n   t        dd      \  } }t        | |d      \  }}}}t        ddd	      }|j                  ||       |j	                  d
       |j                  ||       |j                  |      }t        d
dd	      }|j                  ||       |j                  |      }	t        ||	       y )Nr<   r5   r   r  r1   r   TiE  r  r   r   F)r	   r   r   rH   r   rI   r,   )
rf   rg   rK   rL   rM   rN   r   r   r   r   s
             rR   test_warm_start_equivalencer    s     bq9DAq'712'N$GVWfA$TRF
JJw 
2&
JJw 		B
D
QCGGGW	V	Bb"%rT   c                      t        dd      \  } }t        ddd      }t        j                  t              5  |j                  | |       d d d        y # 1 sw Y   y xY w)Nr<   r5   r   r   T)rB   r   r   )r	   r   r   r   r  rH   r  s      rR   $test_warm_start_with_oob_score_failsr    sN    bq9DAq
tt
LC	z	" 1  s   AAc                      t         j                  t         j                  }} t        j                  |      }t        d      }d}t        j                  t        |      5  |j                  | ||       d d d        t        j                  t        j                  }} t        j                  |      }t        d      }d}t        j                  t        |      5  |j                  | ||       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)NF)r:   zYWhen fitting BaggingClassifier with sample_weight it is recommended to use bootstrap=Truer   sample_weightzXWhen fitting BaggingRegressor with sample_weight it is recommended to use bootstrap=True)rD   rE   rF   r   	ones_liker   r   r   r   rH   r   r   )rf   rg   r  r   r   regs         rR   $test_warning_bootstrap_sample_weightr    s    99dkkqALLOM
e
,C	2  
k	2 31M23 ==(//qALLOM
U
+C	2  
k	2 31M23 33 33 3s   C8D8DDc                     t         j                  t         j                  }} t        d      }t	        j
                  |      dt        |      z  z  }d}t        j                  t        |      5  |j                  | ||       d d d        t        dd      }t	        j
                  |      }d|d	<   t        j                  d
      }t        j                  t        |      5  t        j                  t        d      5  |j                  | ||       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nr4   )r8   r?   zUsing the fractional value max_samples=1.0 when the total sum of sample weights is 0.5(\d*) results in a low number \(1\) of bootstrap samples. We recommend passing `max_samples` as an integer.r   r  F)r:   r8   r   zRmax_samples=151 must be <= n_samples=150 to be able to sample without replacement.z1When fitting BaggingClassifier with sample_weight)rD   rE   rF   r   r   r  r   r   r   r   rH   reescaper   r  )rf   rg   r   r  expected_msgs        rR   =test_invalid_sample_weight_max_samples_bootstrap_combinationsr    s   99dkkqA 
,CLLOq3q6z2M	<  
k	6 31M23
 e
=CLLOMM"99	L 
z	6 7\\R
 	7 GGAqG6	77 73 3	7 	77 7s0   .D$"D<>D0D<$D-0D9	5D<<Ec                       e Zd ZdZddZd Zy)EstimatorAcceptingSampleWeightz&Fake estimator accepting sample_weightNc                 .    || _         || _        || _        yzRecord values passed during fitN)X_y_sample_weight_)re   rf   rg   r  s       rR   rH   z"EstimatorAcceptingSampleWeight.fit  s    +rT   c                      y r_   rC   r   s     rR   rI   z&EstimatorAcceptingSampleWeight.predict      rT   r_   rk   rl   rm   rn   rH   rI   rC   rT   rR   r  r    s    0,rT   r  c                       e Zd ZdZd Zd Zy)EstimatorRejectingSampleWeightz&Fake estimator rejecting sample_weightc                      || _         || _        yr  )r  r  r   s      rR   rH   z"EstimatorRejectingSampleWeight.fit  s    rT   c                      y r_   rC   r   s     rR   rI   z&EstimatorRejectingSampleWeight.predict  r!  rT   Nr"  rC   rT   rR   r$  r$    s    0
rT   r$  bagging_classaccept_sample_weightmetadata_routingr8   r   g?c                    t        j                  d      j                  dd      }t        j                  ddgd      }t        j                  d      }d|d<   d|d<   |rt               }n
t               }|j                  \  }}	t        |t              rt        ||j                         z        }
n|}
t        |	      5  |r|r|j                  d
      } | ||d      }|j                  |||       t        |j                   |j"                        D ]P  \  }}t        j$                  ||      }t        |      t'        |      cxk(  r|
k(  sJ  J t        j(                  |ddg      j+                         sJ |r||j,                  j                  ||	fk(  sJ |j.                  j                  |fk(  sJ t1        |j,                  |       t1        |j.                  |       t1        |j2                  |       |j,                  j                  |
|	fk(  sJ |j.                  j                  |
fk(  sJ t1        |j,                  ||          t1        |j.                  ||          S 	 d d d        y # 1 sw Y   y xY w)Nr   r   r5   r   r   r6   r?   r   enable_metadata_routingTr  )r8   rB   )	minlength)r   arangereshaperepeatzerosr  r$  r   r   floatr   r   r   set_fit_requestrH   rG   ry   estimators_samples_bincountr   isinrz   r  r  r+   r  )r'  r(  r)  r8   rf   rg   r  base_estimatorr   
n_featuresexpected_integer_max_samplesbaggingrA   samplescountss                  rR   %test_draw_indices_using_sample_weightr=    s7    			#r1%A
		1a&"AHHSMMM!M!7979GGIz+u% (+;9J9J9L+L'M$'2$	0@	A : 4+;;$;ONKVWXAq6"%g&9&97;V;V"W 	:Iw[[I>Fv;#g,N2NNNNNN777QF+//111# ||))i-DDDD ||))i\999	a0	a0	 8 8&A !||)).JJ-WWWW ||)).J-LLLL	aj9	aj9#	:: : :s   >F*I22I;c                  \   d\  } }}t        | ||      | k(  sJ d\  } }}t        | ||      |k(  sJ d\  } }}t        | ||      dk(  sJ d\  } }}d}t        j                  t        |      5  t        | ||      t	        || z        k(  sJ 	 d d d        d\  } }}t        j                  t        |      5  t        | ||      dk(  sJ 	 d d d        d}t
        j                  j                  d	      }d
d|j                  d
      }}} t        j                  t        |      5  t        | ||      t	        ||j                         z        k(  sJ 	 d d d        t        j                  d      }t        j                         5  t        j                  d       d\  } }}t        | ||      |k(  sJ dd|j                  d      }}} t        | ||      t	        ||j                         z        k(  sJ 	 d d d        y # 1 sw Y   rxY w# 1 sw Y   BxY w# 1 sw Y   xY w# 1 sw Y   y xY w)N)r   Nnot_used)r   r   r?  )r   h㈵>Nr5   )r   gQ?Nz?.+the number of samples.+low number.+max_samples.+as an integerr   zI.+the total sum of sample weights.+low number.+max_samples.+as an integerr   i@B r@  )sizer   error)r      Nr   r3   )r   r   r   r   r   r   randomdefault_rnguniformr   r   warningscatch_warningssimplefilter)r   r8   r  warning_msgwarning_msg_with_weightsrJ   s         rR   test_get_n_samples_bootstraprL  3  sj   ,@)I{M#I{MJiWWW,=)I{M KG;VV -;)I{M#I{MJaOOO,:)I{MSK	k	5 
'	;NRU)#S
 
 	
 


 -;)I{M	k	5 T'	;NRSSSST 	T  ))


"C,5tS[[i[=XM{I	k)A	B 
'	;NRU-++--S
 
 	
 


 GGAJM		 	 	" 
g&0=-	;$Y]K	
 14S#++3+:O;	'	;NRU-++--S
 
 	
 

 
)
 
T T
 

 
s1   ,G<5H	#-HA0H"<H	HH"H+c                  "   t        dd      \  } }t        dd      }|j                  | |       |j                  ddd	       |j                  | |       t	        j
                  t              5  t        |d
       d d d        y # 1 sw Y   y xY w)Nr   r5   r   r   T)rB   r   Fr   )r   r   rB   r   )r	   r   rH   r   r   r   AttributeErrorrx   r  s      rR   $test_oob_score_removed_on_warm_startrO  d  su    c:DAq
d
;CGGAqMNNde"NEGGAqM	~	& #\"# # #s   /BBc                      t        dd      \  } }t        t               dddd      }|j                  | |      j                  |j                  | |      j                  k(  sJ y )N   r5   r   r3   T)r8   r9   r   r2   )r	   r   r   rH   r   rf   rg   r:  s      rR   test_oob_score_consistencyrS  q  sb     c:DAqG ;;q!''7;;q!+<+G+GGGGrT   c                     t        dd      \  } }t        t               dddd      }|j                  | |       |j                  }|j
                  }|j                  }t        |      t        |      k(  sJ t        |d         t        |       dz  k(  sJ |d   j                  j                  d	k(  sJ d}||   }||   }||   }	| |   d d |f   }
||   }|	j                  }|	j                  |
|       |	j                  }t        ||       y )
NrQ  r5   r   r3   F)r8   r9   r2   r:   r   r?   r   )r	   r   r   rH   r4  r   ry   r   dtypekindcoef_r,   )rf   rg   r:  estimators_samplesestimators_featuresrP   estimator_indexestimator_samplesestimator_featuresrA   rK   rM   
orig_coefs	new_coefss                 rR   test_estimators_samplesr_    s1    c:DAqG KK1 !44!66$$J !"c*o555!!$%Q1444a &&++s222 O*?;,_=?+I"#Q(:%:;G!"GJMM'7#Ij)4rT   c                     t               } | j                  | j                  }}t        t	        d      t                     }t        |dd      }|j                  ||       |j                  d   j                  d   d   j                  j                         }|j                  d   }|j                  d   }|j                  d   }||   d d |f   }	||   }
|j                  |	|
       t        |j                  d   d   j                  |       y )Nr?   )n_componentsr3   r   )rA   r8   r2   r   r5   )r   rE   rF   r   r    r   r   rH   ry   r   rW  copyr4  r   r-   )rD   rf   rg   base_pipeliner   pipeline_estimator_coefrA   estimator_sampleestimator_featurerK   rM   s              rR   %test_estimators_samples_deterministicrg    s     ;D99dkkqA!A.0B0DM mST
UCGGAqM!ooa066r:1=CCHHJ"I..q1003!"A'8$89G !GMM'7#yr*1-335LMrT   c                      d} t        d| z  d      \  }}t        t               | dd      }|j                  ||       |j                  | k(  sJ y )Nr   r?   r5   r   r3   )r8   r9   r2   )r	   r   r   rH   _max_samples)r8   rf   rg   r:  s       rR   test_max_samples_consistencyrj    sZ     Ka+oAFDAq	G KK1;...rT   c                  H   d} dgdgdggdz  }g ddz  }g ddz  }g ddz  }t        d| 	      j                  ||      j                  }t        d| 	      j                  ||      j                  }t        d| 	      j                  ||      j                  }||g||gk(  sJ y )
Nr   r   r   r5   )ABC)r   r   r5   )r   r5   r?   T)r   r2   )r   rH   r   )r2   rf   Y1Y2Y3x1x2x3s           rR   !test_set_oob_score_label_encodingru    s     L
sQC1A	1	B	aB	QBD|D	Q	  	D|D	Q	  	D|D	Q	 
 8BxrT   c                 ^    | j                  dd      } d| t        j                  |        <   | S )Nr2  T)rb  r   )astyper   isfinite)rf   s    rR   replacery    s-    	t$AAr{{1~oHrT   c            	         t        j                  g dg ddt         j                  dgdt         j                  dgdt         j                   dgg      } t        j                  g d      t        j                  g dg dg dg dg dg      g}|D ]  }t	               }t        t        t              |      }|j                  | |      j                  |        t        |      }|j                  | |      j                  |       }|j                  |j                  k(  sJ t	               }t        |      }t        j                  t              5  |j                  | |       d d d        t        |      }t        j                  t              5  |j                  | |       d d d         y # 1 sw Y   LxY w# 1 sw Y   1xY w)Nr5   r   r   r?   N   r?   r}  )r?   r   r   r   r   )r?   r5   	   )r   r}     )r   arraynaninfr)   r   r   ry  rH   rI   r   r   r   r   r  )rf   y_valuesrg   	regressorpipelinebagging_regressory_hats          rR   *test_bagging_regressor_with_missing_inputsr    s   
NNO	
	A 	!
	
H  ()+	 !4W!=yIQ""1%,X6!%%a+33A6ww%++%%% *+	 +]]:& 	LLA	,X6]]:& 	(!!!Q'	( 	((	 		( 	(s   F+F7+F4	7G	c            	      t   t        j                  g dg ddt         j                  dgdt         j                  dgdt         j                   dgg      } t        j                  g d      }t	               }t        t        t              |      }|j                  | |      j                  |        t        |      }|j                  | |       |j                  |       }|j                  |j                  k(  sJ |j                  |        |j                  |        t	               }t        |      }t        j                  t               5  |j                  | |       d d d        t        |      }t        j                  t               5  |j                  | |       d d d        y # 1 sw Y   IxY w# 1 sw Y   y xY w)Nr{  r|  r?   r}  )r   r}  r}  r}  r}  )r   r  r  r  r(   r   r   ry  rH   rI   r   r   rX   rW   r   r   r  )rf   rg   
classifierr  bagging_classifierr  s         rR   +test_bagging_classifier_with_missing_inputsr    sh   
NNO	
	A 	!A')J09:FHLLAq!*841a &&q)E77ekk!!!((+$$Q' ()JZ(H	z	" Q*84	z	" %q!$% % % %s   F"F."F+.F7c                      t        j                  ddgddgg      } t        j                  ddg      }t        t               dd      }|j	                  | |       y )Nr5   r?   r   r6   r   g333333?)r9   r2   )r   r  r   r   rH   rR  s      rR   test_bagging_small_max_featuresr  :  sR     	1a&1a&!"A
!QA 2 43UVWGKK1rT   c                 X   t         j                  j                  |       }|j                  dd      }t        j                  d      } G d dt
              }t         |       dd      }|j                  ||       t        |j                  d   j                  |j                  d          y )N   r6   c                       e Zd ZdZd Zy)8test_bagging_get_estimators_indices.<locals>.MyEstimatorz7An estimator which stores y indices information at fit.c                     || _         y r_   )_sample_indicesr   s      rR   rH   z<test_bagging_get_estimators_indices.<locals>.MyEstimator.fitP  s
    #$D rT   N)rk   rl   rm   rn   rH   rC   rT   rR   MyEstimatorr  M  s
    E	%rT   r  r5   r   )rA   rB   r2   )r   rD  RandomStaterandnr.  r)   r   rH   r-   ry   r  r4  )global_random_seedrJ   rf   rg   r  r   s         rR   #test_bagging_get_estimators_indicesr  D  s    
 ))

 2
3C		"aA
		"A%+ % []QR
SCGGAqMsq)993;R;RST;UVrT   zbagging, expected_allow_nanr5   r=   c                 V    | j                         j                  j                  |k(  sJ y)z*Check that bagging inherits allow_nan tag.N)__sklearn_tags__
input_tags	allow_nan)r:  expected_allow_nans     rR   test_bagging_allow_nan_tagr  Y  s(     ##%00::>PPPPrT   r+  modelr   )rA   rB   c                 `    | j                  t        j                  t        j                         y)zAMake sure that metadata routing works with non-default estimator.NrH   rD   rE   rF   r  s    rR   "test_bagging_with_metadata_routingr  k  s     
IIdii%rT   zsub_estimator, caller, calleerI   rX   rW   c                    t        j                  ddgddgddgg      }g d}dgd}}t               } | |      }d	|z   d
z   }	 t        ||	      dd       t	        |      }
|
j                  ||        t        |
|      t        j                  ddgddgddgg      ||       t        |      sJ |D ]  }t        |||||        y)a  Test that metadata routing works in `BaggingClassifier` with dynamic selection of
    the sub-estimator's methods. Here we test only specific test cases, where
    sub-estimator methods are not present and are not tested with `ConsumingClassifier`
    (which possesses all the methods) in
    sklearn/tests/test_metaestimators_metadata_routing.py: `BaggingClassifier.predict()`
    dynamically routes to `predict` if the sub-estimator doesn't have `predict_proba`
    and `BaggingClassifier.predict_log_proba()` dynamically routes to `predict_proba` if
    the sub-estimator doesn't have `predict_log_proba`, or to `predict`, if it doesn't
    have it.
    r   r?   r5   r6   r}  )r5   r?   r   a)registryset__requestT)r  metadatar   r   )rf   r  r  )objr|   parentr  r  N)r   r  r&   rx   r   rH   r   r'   )sub_estimatorcallercalleerf   rg   r  r  r  rA   set_callee_requestr:  s              rR   3test_metadata_routing_with_dynamic_method_selectionr  |  s    0 	1a&1a&1a&)*AA c38M{Hx0I&:5*GI)*M)4GKK1GGV
((QFQFQF+
,# x== 
	'	

rT   c                 `    | j                  t        j                  t        j                         y)z^Make sure that we still can use an estimator that does not implement the
    metadata routing.Nr  r  s    rR   -test_bagging_without_support_metadata_routingr    s     
IIdii%rT   )*   )~rn   r  rG  	itertoolsr   r   r   numpyr   r   sklearnr   sklearn.baser   sklearn.datasetsr   r   r	   sklearn.dummyr
   r   sklearn.ensembler   r   r   r   r   r   r   r   sklearn.ensemble._baggingr   sklearn.feature_selectionr   sklearn.linear_modelr   r   sklearn.model_selectionr   r   r   sklearn.neighborsr   r   sklearn.pipeliner   sklearn.preprocessingr   r   sklearn.random_projectionr    sklearn.svmr!   r"   %sklearn.tests.metadata_routing_commonr#   r$   r%   r&   r'   sklearn.treer(   r)   sklearn.utilsr*   sklearn.utils._testingr+   r,   r-   sklearn.utils.fixesr.   r/   rJ   rD   permutationrF   rA  permrE   r   rS   markparametrizer   r   r   r   r   r   r   r   r   r   r   r   thread_unsafer   r   r   r   r   r  r	  r  r  r  r  r  r$  r=  rL  rO  rS  r_  rg  rj  ru  ry  r  r  r  r  r  r  r  r  rC   rT   rR   <module>r     s   
  $    " & G G 9	 	 	 ? 1 ? Q Q G * < <    G , 
 ? {
t{{''(IIdO	kk$ ?
x++,d#//$'0B &'  # !!&*	  # !!&*	 U$Od%P	
  	O%.&2/.&2R8 +^n-LM5A N5Ap# #'9TE8 
F"&J!#HJ(O&6V & &4	T )0 )0XC44$&&3,7@
] 
	] 	 +;=N*OP/%?+eT];S	2/: 3 < @ Q/:d.
b
#H%5PN6/ 4&(R%@W* !	91E	FM	7C	DdK	-/	0%8	#%	 %(	QQ -,!<1	
 	+;!	
	
&
 .&
 #	/IF5	

 
,-@)L -#
 .#
T (a8	
 	#4!#DSTU	&	&rT   