
    {KgXz                     &   d Z ddlmZmZ ddlZddlZddlZddl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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*m+Z+ ddl,m-Z- ddl.m/Z/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5 ddl6m7Z7m8Z8 ddl9m:Z:m;Z;  e5d      Z< e       Z=e<j}                  e=j~                  j                        ZAe=j                  eA   e=_B        e=j~                  eA   e=_?         e       ZCe<j}                  eCj~                  j                        ZAeCj                  eA   eC_B        eCj~                  eA   eC_?        d ZDej                  j                  d ee;e:z   ddddddddddddddddddgg d            d         ZGd! ZHej                  j                  d"e;e:z         d#        ZI G d$ d%e
      ZJd& ZKd' ZLd( ZMd) ZNd* ZOd+ ZPd, ZQd- ZRd. ZSd/ ZTd0 ZUd1 ZV G d2 d3e
      ZWd4 ZXdPd5ZYd6 ZZd7 Z[d8 Z\d9 Z]d: Z^d; Z_d< Z`d= Zad> Zbd? Zcd@ ZddA ZedB ZfdC ZgdD Zhej                  j                  dE e edFG            df e edFG            df e e             df e e0             dfg      dH        Ziej                  j                  dI e edFJ      dFK       e edFJ      dFK      g      dL        Zjej                  j                  dI e edFdMN      dFK       e edFJ      dFK      g      dO        Zky)QzE
Testing for the bagging ensemble module (sklearn.ensemble.bagging).
    )cycleproductN)BaseEstimator)load_diabetes	load_irismake_hastie_10_2)DummyClassifierDummyRegressor)AdaBoostClassifierAdaBoostRegressorBaggingClassifierBaggingRegressorHistGradientBoostingClassifierHistGradientBoostingRegressorRandomForestClassifierRandomForestRegressor)SelectKBest)LogisticRegression
Perceptron)GridSearchCVParameterGridtrain_test_split)KNeighborsClassifierKNeighborsRegressor)make_pipeline)FunctionTransformerscale)SparseRandomProjection)SVCSVR)DecisionTreeClassifierDecisionTreeRegressor)check_random_state)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)	estimatorr*   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paramsr9   s	            g/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/sklearn/ensemble/tests/test_bagging.pytest_classificationrK   9   s    
Q
C'7		4;;S($GVWf :F#'-		
D 	B+J !uZ'89	 	
	
 		

 #gw
 :    z sparse_container, params, methodr+   r7   Tr/   r,   r.   Fr1   r2   r3   r0   r2   r3   )rA   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superr@   type
data_type_selfXy	__class__s      rJ   r@   z1test_sparse_classification.<locals>.CustomSVC.fitw   !    GK1"1gDOKrL   __name__
__module____qualname____doc__r@   __classcell__r`   s   @rJ   	CustomSVCrT   t       E	 	rL   ri   r   r)   linearovr)kerneldecision_function_shaper-   r9   r*   r;   )r   r#   r   r   r<   r=   r>   r   r@   getattrr$   rZ   estimators_r[   all)sparse_containerrI   methodri   rB   rC   rD   rE   rF   X_train_sparseX_test_sparsesparse_classifiersparse_resultsdense_classifierdense_resultssparse_typeitypests                      rJ   test_sparse_classificationr   Z   sR   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#@#@A#@aQ\\#@EA%0%Q[ %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   r)   r+   r,   TFr/   ro   r;   )r#   r   diabetesr=   r>   r   r
   r"   r   r    r   r@   rA   )rB   rC   rD   rE   rF   rG   r9   rI   s           rJ   test_regressionr      s    
Q
C'7crHOOCR0s($GVWf : #J#'-		
D 		 FMysMfMQQgfo rL   rs   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   r)   c                   "     e Zd ZdZ fdZ xZS ))test_sparse_regression.<locals>.CustomSVRrU   c                 H    t         |   ||       t        |      | _        | S rW   rX   r\   s      rJ   r@   z-test_sparse_regression.<locals>.CustomSVR.fit   ra   rL   rb   rh   s   @rJ   	CustomSVRr      rj   rL   r   r+   r7   Tr/   r,   r.   FrM   rN   r-   ro   r;   )r#   r   r   r=   r>   r    r   r@   rA   rZ   rq   r[   r$   rr   )rs   rB   rC   rD   rE   rF   r   parameter_setsru   rv   rI   rw   rx   rz   r{   r|   r}   r~   s                     rJ   test_sparse_regressionr      s    Q
C'7crHOOCR0s($GVWfC  "&		
 "&		
 dK$eLN" &g.N$V,M , 
k
5;

#ng
& 	 +22=A My{MfMS'"WV_ 	 >*'8'D'DE'D!'DE!.-@e4eA$e4555!.-@' ! 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_r]   r^   r_   s      rJ   r@   zDummySizeEstimator.fit   s"    ggaj$kk!nrL   c                 F    t        j                  |j                  d         S r   )nponesr   r]   r^   s     rJ   rA   zDummySizeEstimator.predict   s    wwqwwqz""rL   Nrc   rd   re   r@   rA   r;   rL   rJ   r   r      s    -#rL   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   r)   r,   F)r9   r0   r2   r*   T)r9   r2   )r#   r   r   r=   r>   r"   r@   r   scorer   rq   r   r   appendr   lenset)rB   rC   rD   rE   rF   r9   ensembletraining_hashs           rJ   test_bootstrap_samplesr      sr   
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==+;;;;Y556 * s=!"c-&8888rL   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   r)   r,   F)r9   r1   r3   r*   r-   T)r#   r   r   r=   r>   r   r"   r@   estimators_features_r   r   unique)rB   rC   rD   rE   rF   r   featuress          rJ   test_bootstrap_featuresr   "  s   
Q
C'7xS($GVWf  ') 	
 
c'7  11}}""1%8)<)B)B1)EEEE 2  ')	
 
c'7  11}}""1%		((;(A(A!(DDDD 2rL   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   r)   ignore)divideinvalidro   r-   )axis   )r9   r*   r0   )r#   r   r<   r=   r>   r   errstater   r!   r@   r$   sumrO   r   r   exprP   r   rB   rC   rD   rE   rF   r   s         rJ   test_probabilityr   >  sP   
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	
/ 
8	7	7s   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   r)   d   Tr9   r:   r2   	oob_scorer*   皙?{Some inputs do not have OOB scores. This probably means too few estimators were used to compute any reliable oob estimates.matchr-   )r#   r   r<   r=   r>   r!   r   r   r@   r   abs
oob_score_pytestwarnsUserWarning)	rB   rC   rD   rE   rF   r9   clf
test_scorewarn_msgs	            rJ   test_oob_score_classificationr   a  s     Q
C'7		4;;S($GVWf -.6	
 #gw
 	 YYvv.
:./#555J 	 \\+X6## C GGGW% 76% 7$ 76s   >#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   r)   r   Tr   r   r   r   r-   )r#   r   r   r=   r>   r   r"   r@   r   r   r   r   r   r   )	rB   rC   rD   rE   rF   r   r   r   regrs	            rJ   test_oob_score_regressionr     s     Q
C'7xS($GVWf ') 
c'7  66*JzCNN*+c111	F  
k	2+-
 	'" 
3	2	2s   /+C##C,c                  P   t        d      } t        t        j                  t        j                  |       \  }}}}t        t               ddd|       j                  ||      }t               j                  ||      }t        |j                  |      |j                  |             y )Nr   r)   r-   F)r9   r:   r2   r3   r*   )
r#   r   r   r=   r>   r   r   r@   r$   rA   )rB   rC   rD   rE   rF   clf1clf2s          rJ   test_single_estimatorr     s    
Q
C'7xS($GVWf %'  
c'7 	  $$Wg6Ddll62DLL4HIrL   c                      t         j                  t         j                  }} t               }t	        t        |      j                  | |      d      rJ y )NrQ   )r<   r=   r>   r!   hasattrr   r@   )r^   r_   bases      rJ   
test_errorr     sB    99dkkqA!#D(.221a8:MNNNNrL   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   r)      n_jobsr*   r-   r   rl   )rn   )r   r<   r=   r>   r   r!   r@   rO   
set_paramsr$   r   rQ   )rC   rD   rE   rF   r   y1y2y3
decisions1
decisions2
decisions3s              rJ   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*5rL   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   r)   r   r   r-   r   r7   )r#   r   r   r=   r>   r   r"   r@   r   rA   r$   )	rB   rC   rD   rE   rF   r   r   r   r   s	            rJ   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"%rL   c                      t         j                  t         j                  }} d||dk(  <   ddd}t        t	        t                     |d      j                  | |       y )Nr-   r7   )r-   r7   )r:   estimator__Croc_auc)scoring)r<   r=   r>   r   r   r   r@   )r^   r_   
parameterss      rJ   test_gridsearchr     sP     99dkkqAAa1fI #)&AJ"35):yIMMaQRSrL   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   r)   r   r   )r#   r   r<   r=   r>   r   r@   
isinstance
estimator_r!   r   r   r   r"   r    r   s         rJ   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///rL   c                     t        t        t        d      t                     d      } | j	                  t
        j                  t
        j                         t        | d   j                  d   d   j                  t              sJ y )Nr-   )kr7   )r1   r   )r   r   r   r!   r@   r<   r=   r>   r   stepsr*   int)r9   s    rJ   test_bagging_with_pipeliner   @  sd    !kA&(>(@APQI MM$))T[[)il((,Q/<<cBBBrL   c                       e Zd Zd Zd Zy)DummyZeroEstimatorc                 :    t        j                  |      | _        | S rW   )r   r   classes_r   s      rJ   r@   zDummyZeroEstimator.fitI  s    		!rL   c                 l    | j                   t        j                  |j                  d   t                 S )Nr   )dtype)r   r   zerosr   r   r   s     rJ   rA   zDummyZeroEstimator.predictM  s$    }}RXXaggaj<==rL   Nr   r;   rL   rJ   r   r   H  s    >rL   r   c            
         t        t                     } t        d      }| j                  t        j
                  t        j                        j                  t        j
                         t        j                  t              5  | j                  t        j
                  t        j                  |j                  dt        j
                  j                  d                d d d        y # 1 sw Y   y xY w)Nr   
   )size)sample_weight)r   r   r#   r@   r<   r=   r>   rA   r   raises
ValueErrorrandintr   )r9   rB   s     rJ   1test_bagging_sample_weight_unsupported_but_passedr   Q  s    !"4"67I
Q
CMM$))T[[)11$))<	z	"IIKK++b		0B+D 	 	
 
#	"	"s   AC))C2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 )
Nr4   r-   	n_samplesr*   )r   r   T)r:   r*   
warm_startr:   r   F)r   r   r   r@   r   r   r*   )r*   r^   r_   clf_wsr:   	clf_no_wstrees          rJ   test_warm_startr  ^  s     bq9DAqF>&)QUF <8

1a6{l***   "luI MM!Qf5fd!!f56#'01yt		y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)	Nr4   r-   r   r   T)r:   r   r.   r   )r   r   r@   r   r   r   r   r^   r_   r   s      rJ   $test_warm_start_smaller_n_estimatorsr  x  s^    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)Nr4   r-   r   +   r)   r   TS   r:   r   r*   r,   z;Warm-start fitting without increasing n_estimators does notr   )	r   r   r   r@   rA   r   r   r   r%   )	r^   r_   rC   rD   rE   rF   r   y_predr   s	            rJ   "test_warm_start_equal_n_estimatorsr    s    bq9DAq'712'N$GVWf
t"
MCGGGW[[ FsNGLH	k	2! 
3vs{{623 
3	2s   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 )Nr4   r-   r   r	  r)   r   TiE  r  r   r   F)r   r   r   r@   r   rA   r$   )
r^   r_   rC   rD   rE   rF   r  r   r   r   s
             rJ   test_warm_start_equivalencer    s     bq9DAq'712'N$GVWfA$TRF
JJw 
2&
JJw 		B
D
QCGGGW	V	Bb"%rL   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)Nr4   r-   r   r   T)r:   r   r   )r   r   r   r   r   r@   r  s      rJ   $test_warm_start_with_oob_score_failsr    sE    bq9DAq
tt
LC	z	"1 
#	"	"s   AA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   r-   r   r   T)r:   r   Fr   )r   r   r:   r   )r   r   r@   r   r   r   AttributeErrorrp   r  s      rJ   $test_oob_score_removed_on_warm_startr    sl    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   r-   r   r+   T)r0   r1   r   r*   )r   r   r   r@   r   r^   r_   baggings      rJ   test_oob_score_consistencyr    sb     c:DAqG ;;q!''7;;q!+<+G+GGGGrL   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 )
Nr  r-   r   r+   F)r0   r1   r*   r2   r   r7   r|   )r   r   r   r@   estimators_samples_r   rq   r   r   kindcoef_r$   )r^   r_   r  estimators_samplesestimators_featuresrH   estimator_indexestimator_samplesestimator_featuresr9   rC   rE   
orig_coefs	new_coefss                 rJ   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)4rL   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 )Nr7   )n_componentsr+   r   )r9   r0   r*   r   r-   )r   r=   r>   r   r   r   r   r@   rq   r   r  copyr  r   r%   )r<   r^   r_   base_pipeliner   pipeline_estimator_coefr9   estimator_sampleestimator_featurerC   rE   s              rJ   %test_estimators_samples_deterministicr-    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MrL   c                      d} t        d| z  d      \  }}t        t               | dd      }|j                  ||       |j                  | k(  sJ y )Nr   r7   r-   r   r+   )r0   r1   r*   )r   r   r   r@   _max_samples)r0   r^   r_   r  s       rJ   test_max_samples_consistencyr0    sZ     Ka+oAFDAq	G KK1;...rL   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   r-   )ABC)r   r   r-   )r   r-   r7   T)r   r*   )r   r@   r   )r*   r^   Y1Y2Y3x1x2x3s           rJ   !test_set_oob_score_label_encodingr;    s     L
sQC1A	1	B	aB	QBD|D	Q	  	D|D	Q	  	D|D	Q	 
 8BxrL   c                 ^    | j                  dd      } d| t        j                  |        <   | S )NfloatT)r(  r   )astyper   isfinite)r^   s    rJ   replacer@  6  s-    	t$AAr{{1~oHrL   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r-   r   r   r7   N   r7   rD  )r7   r   r   r   r   )r7   r-   	   )r   rD     )r   arraynaninfr"   r   r   r@  r@   rA   r   r   r   r   r   )r^   y_valuesr_   	regressorpipelinebagging_regressory_hats          rJ   *test_bagging_regressor_with_missing_inputsrO  <  sj   
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)NrB  rC  r7   rD  )r   rD  rD  rD  rD  )r   rG  rH  rI  r!   r   r   r@  r@   rA   r   r   rP   rO   r   r   r   )r^   r_   
classifierrL  bagging_classifierrN  s         rJ   +test_bagging_classifier_with_missing_inputsrS  e  sX   
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 )Nr-   r7   r   r.   r   g333333?)r1   r*   )r   rG  r   r   r@   r  s      rJ   test_bagging_small_max_featuresrU    sR     	1a&1a&!"A
!QA 2 43UVWGKK1rL   c                  X   t         j                  j                  d      } | j                  dd      }t        j                  d      } G d dt
              }t         |       dd      }|j                  ||       t        |j                  d   j                  |j                  d          y )Nr      r.   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 rW   )_sample_indicesr   s      rJ   r@   z<test_bagging_get_estimators_indices.<locals>.MyEstimator.fit  s
    #$D rL   N)rc   rd   re   rf   r@   r;   rL   rJ   MyEstimatorrY    s
    E	%rL   r\  r-   )r9   r:   r*   )r   randomRandomStaterandnaranger"   r   r@   r%   rq   r[  r  )rB   r^   r_   r\  r   s        rJ   #test_bagging_get_estimators_indicesra    s    
 ))


"C		"aA
		"A%+ % []QR
SCGGAqMsq)993;R;RST;UVrL   zbagging, expected_allow_nanr-   r5   c                 4    | j                         d   |k(  sJ y)z*Check that bagging inherits allow_nan tag.	allow_nanN)	_get_tags)r  expected_allow_nans     rJ   test_bagging_allow_nan_tagrf    s!     {+/AAAArL   modelr   )r9   r:   c                     t        j                  d      5  | j                  t        j                  t        j
                         ddd       y# 1 sw Y   yxY w)zAMake sure that metadata routing works with non-default estimator.T)enable_metadata_routingN)sklearnconfig_contextr@   r<   r=   r>   rg  s    rJ   "test_bagging_with_metadata_routingrm    s4     
			=		$))T[[) 
>	=	=s   /AASAMME)r:   	algorithmc                 `    | j                  t        j                  t        j                         y)z^Make sure that we still can use an estimator that does not implement the
    metadata routing.N)r@   r<   r=   r>   rl  s    rJ   -test_bagging_without_support_metadata_routingrq    s     
IIdii%rL   )*   )lrf   	itertoolsr   r   r   numpyr   r   rj  sklearn.baser   sklearn.datasetsr   r   r   sklearn.dummyr	   r
   sklearn.ensembler   r   r   r   r   r   r   r   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.treer!   r"   sklearn.utilsr#   sklearn.utils._testingr$   r%   sklearn.utils.fixesr&   r'   rB   r<   permutationr>   r   permr=   r   rK   markparametrizer   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-  r0  r;  r@  rO  rS  rU  ra  rf  rm  rq  r;   rL   rJ   <module>r     ss   %     & G G 9	 	 	 2 ? Q Q G * < <   F , P > {
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&6R&4	T)0XC> >

44$&&
#H%5PN6/ 4&(R%@W* !	91E	FM	7C	DdK	-/	0%8	#%	 %(	BB
 ,!<1	
 	+;!	
	
*
* (a7K	
 	#4!#DSTU	&	&rL   