
    0Phtz                        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<>                    e=j?        j@                  ZAe=jB        eA         e=_B        e=j?        eA         e=_?         e            ZCe<>                    eCj?        j@                  ZAeCjB        eA         eC_B        eCj?        eA         eC_?        d ZDejE        F                    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jE        F                    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 ZXdOd6ZYd7 ZZd8 Z[d9 Z\d: Z]d; Z^d< Z_d= Z`d> Zad? Zbd@ ZcdA ZddB ZedC ZfdD ZgdE ZhejE        F                    dF e edGH                    df e edGH                    df e e                      df e e0                      dfg          dI             ZiejE        F                    dJ e edGK          dGL           e edGK          dGL          g          dM             ZjejE        F                    dJ e edGK          dGL           e edGK          dGL          g          dN             ZkdS )PzE
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 ]<\  }}t          d|| dd|                    ||                              |           =d S )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	            c/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/ensemble/tests/test_bagging.pytest_classificationrK   :   s*   
Q

C'7	4;S( ( ($GVWf :F#'-		
 	
 D 	B+++J !uZ'8'899 0 0	 	
	
 	
 		
 	

 #gw

0 0    z sparse_container, params, methodr+   r7   Tr/   r,   r.   Fr1   r2   r3   r0   r2   r3   )rA   predict_probapredict_log_probadecision_functionc                     G d dt                     }t          d          }t          t          t          j                  t          j        |          \  }}}} | |          }	 | |          }
t          d |dd          dd	|                    |	|          } t          ||          |
          }t          d |dd          dd	|                    ||          } t          ||          |          }t          ||           t          |	          d
 |j        D             }t          fd|D                       sJ d S )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                 t    t                                          ||           t          |          | _        | S Nsuperr@   type
data_type_selfXy	__class__s      rJ   r@   z1test_sparse_classification.<locals>.CustomSVC.fitx   -    GGKK1"1ggDOKrL   __name__
__module____qualname____doc__r@   __classcell__r`   s   @rJ   	CustomSVCrT   u   >        EE	 	 	 	 	 	 	 	 	rL   ri   r   r)   linearovr)kerneldecision_function_shaper-   r9   r*   c                     g | ]	}|j         
S r;   r[   .0is     rJ   
<listcomp>z.test_sparse_classification.<locals>.<listcomp>   s    AAAaQ\AAArL   c                     g | ]}|k    	S r;   r;   rs   tsparse_types     rJ   ru   z.test_sparse_classification.<locals>.<listcomp>   s    000Q[ 000rL   r;   )r   r#   r   r   r<   r=   r>   r   r@   getattrr$   rZ   estimators_all)sparse_containerrI   methodri   rB   rC   rD   rE   rF   X_train_sparseX_test_sparsesparse_classifiersparse_resultsdense_classifierdense_resultstypesry   s                   @rJ   test_sparse_classificationr   [   s   4    C    Q

C'7di$+C( ( ($GVWf &%g..N$$V,,M) )8UKKK    
c.'""	 
 8W.77FFN ) )8UKKK    
c'7	 
 6G,f55f==Mnm<<<~&&KAA#4#@AAAE0000%0001111111rL   c                     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 ]=}|D ]8}t          d
|| d	|                    ||                              |           9>d S )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crcHOCRC0s( ( ($GVWf : #J#'-		
 	
 D 	 
 
	  	 	FMysMMfMMQQ gfoooo	
 
rL   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|
                    ||          }|                    |	          }t          d |            dd|
                    ||                              |          }t          |          d |j
        D             }t          ||           t          fd|D                       sJ t          ||           d S )Nr   r   r)   c                   "     e Zd ZdZ fdZ xZS ))test_sparse_regression.<locals>.CustomSVRrU   c                 t    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   c                     g | ]	}|j         
S r;   rq   rr   s     rJ   ru   z*test_sparse_regression.<locals>.<listcomp>   s    EEE!EEErL   c                     g | ]}|k    	S r;   r;   rw   s     rJ   ru   z*test_sparse_regression.<locals>.<listcomp>   s    444A$444rL   r;   )r#   r   r   r=   r>   r    r   r@   rA   rZ   r{   r$   r|   )r}   rB   rC   rD   rE   rF   r   parameter_setsr   r   rI   r   r   r   r   ry   s                  @rJ   test_sparse_regressionr      s    Q

C'7crcHOCRC0s( ( ($GVWf    C    "&		
 	
 "&		
 	
 dKK$eLLN" &%g..N$$V,,M  A A, 
ikk
 
5;
 

#ng
&
& 	 +22=AA Myy{{MMfMMS'""WV__ 	 >**EE'8'DEEE!.-@@@4444e44455555!.-@@@@'A ArL   c                       e Zd Zd Zd ZdS )DummySizeEstimatorc                 \    |j         d         | _        t          j        |          | _        d S Nr   )shapetraining_size_joblibhashtraining_hash_r]   r^   r_   s      rJ   r@   zDummySizeEstimator.fit   s&    gaj$k!nnrL   c                 @    t          j        |j        d                   S r   )nponesr   r]   r^   s     rJ   rA   zDummySizeEstimator.predict   s    wqwqz"""rL   Nrc   rd   re   r@   rA   r;   rL   rJ   r   r      s2        - - -# # # # #rL   r   c                     t          d          } t          t          j        t          j        |           \  }}}}t                                          ||          }t          t                      dd|                               ||          }|                    ||          |                    ||          k    sJ t          t                      dd|                               ||          }|                    ||          |                    ||          k    sJ t          t                      d                              ||          }g }|j
        D ]4}|j        |j        d         k    sJ |                    |j                   5t          t!          |                    t          |          k    sJ d S )Nr   r)   r,   F)r9   r0   r2   r*   T)r9   r2   )r#   r   r   r=   r>   r"   r@   r   scorer   r{   r   r   appendr   lenset)rB   rC   rD   rE   rF   r9   ensembletraining_hashs           rJ   test_bootstrap_samplesr      s   
Q

C'7xS( ( ($GVWf &''++GW==I  '))	  
 
c'7  ??7G,,w0P0PPPPP  '))	  
 
c'7  ??7G,,x~~gw/O/OOOOO
  *<*>*>$OOOSS H M) 7 7	'7=+;;;;;Y56666s=!!""c-&8&8888888rL   c                  V   t          d          } t          t          j        t          j        |           \  }}}}t          t                      dd|                               ||          }|j        D ]<}t          j        j	        d         t          j        |          j	        d         k    sJ =t          t                      dd|                               ||          }|j        D ]<}t          j        j	        d         t          j        |          j	        d         k    sJ =d S )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   #  sE   
Q

C'7xS( ( ($GVWf  ')) 	  
 
c'7  1 F F}"1%8)<)<)B1)EEEEEE'))	  
 
c'7  1 E E}"1%	((;(;(A!(DDDDDDE ErL   c            	         t          d          } t          t          j        t          j        |           \  }}}}t          j        dd          5  t          t                      |           	                    ||          }t          t          j        |                    |          d          t          j        t          |                               t          |                    |          t          j        |                    |                               t          t#                      | d	          	                    ||          }t          t          j        |                    |          d          t          j        t          |                               t          |                    |          t          j        |                    |                               d d d            d S # 1 swxY w Y   d S )
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   ?  s"   
Q

C'7	4;S( ( ($GVWf 
Hh	7	7	7 
 
$,..S
 
 

#gw

 	 	"F8))&11:::BGCKK<P<P	
 	
 	
 	"""6**BF83M3Mf3U3U,V,V	
 	
 	

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

#gw

 	 	"F8))&11:::BGCKK<P<P	
 	
 	
 	"""6**BF83M3Mf3U3U,V,V	
 	
 	
/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   F G>>HHc            	      ,   t          d          } t          t          j        t          j        |           \  }}}}t                      t                      fD ]}t          |ddd|                               ||          }|	                    ||          }t          ||j        z
            dk     sJ d}t          j        t          |          5  t          |d	dd|           }|                    ||           d d d            n# 1 swxY w Y   d S )
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   b  s    Q

C'7	4;S( ( ($GVWf -..6 & &	
 
 
 #gw

 	 YYvv..
:.//#5555J 	 \+X666 	& 	&##   C GGGW%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&%& &s   +DD	D	c                      t          d          } t          t          j        t          j        |           \  }}}}t          t                      ddd|                               ||          }|                    ||          }t          ||j
        z
            dk     sJ d}t          j        t          |          5  t          t                      d	dd|           }|                    ||           d d d            d S # 1 swxY w Y   d S )
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     sr    Q

C'7xS( ( ($GVWf '))   
c'7  66**JzCN*++c1111	F  
k	2	2	2 # #+--
 
 
 	'"""# # # # # # # # # # # # # # # # # #s   ?7DD
Dc                     t          d          } t          t          j        t          j        |           \  }}}}t          t                      ddd|                               ||          }t                                          ||          }t          |	                    |          |	                    |                     d S )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66Ddll622DLL4H4HIIIIIrL   c                      t           j        t           j        }} t                      }t	          t          |                              | |          d          rJ d S )NrQ   )r<   r=   r>   r!   hasattrr   r@   )r^   r_   bases      rJ   
test_errorr     sP    9dkqA!##D(..221a88:MNNNNNNNrL   c                     t          t          j        t          j        d          \  } }}}t	          t                      dd                              | |          }|                    |          }|                    d           |                    |          }t          ||           t	          t                      dd                              | |          }|                    |          }t          ||           t	          t          d          dd                              | |          }|                    |          }|                    d           |                    |          }	t          ||	           t	          t          d          dd                              | |          }|                    |          }
t          ||
           d S )	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     s   '7	4;Q( ( ($GVWf !    	c'7 
 
			'	'Bq!!!				'	'Bb"%%%     	c'7  
			'	'Bb"%%% !E***11  	c'7  ++F33Jq!!!++F33Jj*555 E***11  	c'7  ++F33Jj*55555rL   c                  X   t          d          } t          t          j        t          j        |           \  }}}}t          t                      dd                              ||          }|                    d           |	                    |          }|                    d           |	                    |          }t          ||           t          t                      dd                              ||          }|	                    |          }t          ||           d S )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 7PQRRRVV H q!!!			&	!	!Bq!!!			&	!	!Bb"%%% 5 7 7PQRRRVV H 
		&	!	!Bb"%%%%%rL   c                      t           j        t           j        }} d||dk    <   ddd}t          t	          t                                |d                              | |           d S )Nr-   r7   )r-   r7   )r:   estimator__Croc_auc)scoring)r<   r=   r>   r   r   r   r@   )r^   r_   
parameterss      rJ   test_gridsearchr   	  sf     9dkqAAa1fI #)&AAJ"355)):yIIIMMaQRSSSSSrL   c                  H   t          d          } t          t          j        t          j        |           \  }}}}t          d dd                              ||          }t          |j        t                    sJ t          t                      dd                              ||          }t          |j        t                    sJ t          t                      dd                              ||          }t          |j        t                    sJ t          t          j        t          j        |           \  }}}}t          d dd                              ||          }t          |j        t                    sJ t          t                      dd                              ||          }t          |j        t                    sJ t          t                      dd                              ||          }t          |j        t                    sJ d S )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VVHh)+ABBBBB     	c'7  h)+ABBBBB aaHHHLL H h):66666 (8xS( ( ($GVWf  QQ???CCGWUUHh)+@AAAAA 5 7 7PQRRRVV H h)+@AAAAAaa@@@DDWgVVHh)3///////rL   c                  2   t          t          t          d          t                                d          } |                     t
          j        t
          j                   t          | d         j	        d         d         j
        t                    sJ d S )Nr-   )kr7   )r1   r   )r   r   r   r!   r@   r<   r=   r>   r   stepsr*   int)r9   s    rJ   test_bagging_with_pipeliner   A  s    !kA&&&(>(@(@AAPQ  I MM$)T[)))il(,Q/<cBBBBBBBrL   c                       e Zd Zd Zd ZdS )DummyZeroEstimatorc                 8    t          j        |          | _        | S rW   )r   r   classes_r   s      rJ   r@   zDummyZeroEstimator.fitJ  s    	!rL   c                 d    | j         t          j        |j        d         t                             S )Nr   )dtype)r   r   zerosr   r   r   s     rJ   rA   zDummyZeroEstimator.predictN  s$    }RXagaj<<<==rL   Nr   r;   rL   rJ   r   r   I  s2          > > > > >rL   r   c            
         t          t                                } t          d          }|                     t          j        t          j                                      t          j                   t          j	        t                    5  |                     t          j        t          j        |                    dt          j        j        d                              d d d            d S # 1 swxY w Y   d S )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  R  s    !"4"6"677I
Q

CMM$)T[))11$)<<<	z	"	" 
 
IK++b	0B+DD 	 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   AC//C36C3*   c                    t          dd          \  }}d }dD ]X}|t          || d          }n|                    |           |                    ||           t	          |          |k    sJ Yt          d| d	          }|                    ||           t          d
 |D                       t          d |D                       k    sJ d S )Nr4   r-   	n_samplesr*   )r   r   T)r:   r*   
warm_startr:   r   Fc                     g | ]	}|j         
S r;   r)   rs   trees     rJ   ru   z#test_warm_start.<locals>.<listcomp>t  s    555d!555rL   c                     g | ]	}|j         
S r;   r)   r  s     rJ   ru   z#test_warm_start.<locals>.<listcomp>u  s    111t	111rL   )r   r   r   r@   r   r   )r*   r^   r_   clf_wsr:   	clf_no_wss         rJ   test_warm_startr  _  s    bq999DAqF + +>&)QU  FF <888

1a6{{l*****!lu  I MM!Q55f55566#11y111; ;      rL   c                  8   t          dd          \  } }t          dd          }|                    | |           |                    d           t	          j        t                    5  |                    | |           d d d            d S # 1 swxY w Y   d S )	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  y  s    bq999DAq
t
<
<
<CGGAqMMMNNN"""	z	"	"  1                 s   +BBBc                     t          dd          \  } }t          | |d          \  }}}}t          ddd	          }|                    ||           |                    |          }|d
z  }d}t          j        t          |          5  |                    ||           d d d            n# 1 swxY w Y   t          ||                    |                     d S )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999DAq'712'N'N'N$GVWf
t"
M
M
MCGGGW[[  FsNGLH	k	2	2	2 " "!!!" " " " " " " " " " " " " " "vs{{62233333s   B..B25B2c                     t          dd          \  } }t          | |d          \  }}}}t          ddd	          }|                    ||           |                    d
           |                    ||           |                    |          }t          d
dd	          }|                    ||           |                    |          }	t          ||	           d S )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999DAq'712'N'N'N$GVWfA$TRRRF
JJw   
2&&&
JJw   			B
D
Q
Q
QCGGGW	V		Bb"%%%%%rL   c                      t          dd          \  } }t          ddd          }t          j        t                    5  |                    | |           d d d            d S # 1 swxY w Y   d S )Nr4   r-   r  r   T)r:   r	  r   )r   r   r   r  r  r@   r  s      rJ   $test_warm_start_with_oob_score_failsr    s    bq999DAq
tt
L
L
LC	z	"	"  1                 s    A$$A(+A(c                  \   t          dd          \  } }t          dd          }|                    | |           |                    ddd	           |                    | |           t	          j        t                    5  t          |d
           d d d            d S # 1 swxY w Y   d S )Nr   r-   r  r   T)r:   r   Fr   )r	  r   r:   r   )r   r   r@   r   r   r  AttributeErrorrz   r  s      rJ   $test_oob_score_removed_on_warm_startr!    s    c:::DAq
d
;
;
;CGGAqMMMNNde"NEEEGGAqMMM	~	&	& # #\"""# # # # # # # # # # # # # # # # # #s   B!!B%(B%c                      t          dd          \  } }t          t                      dddd          }|                    | |          j        |                    | |          j        k    sJ d S )N   r-   r  r+   T)r0   r1   r   r*   )r   r   r   r@   r   r^   r_   baggings      rJ   test_oob_score_consistencyr&    s~     c:::DAq  G ;;q!'7;;q!+<+<+GGGGGGGrL   c                  ^   t          dd          \  } }t          t                      dddd          }|                    | |           |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
        }t          ||           d S )
Nr#  r-   r  r+   F)r0   r1   r*   r2   r   r7   rt   )r   r   r   r@   estimators_samples_r   r{   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_samplesr2    s`    c:::DAq  G KK1 !4!6$J !""c*oo5555!!$%%Q14444a &+s2222 O*?;,_=?+I"#QQQ(:%:;G!"GJMM'7###Ij)44444rL   c                  F   t                      } | j        | j        }}t          t	          d          t                                }t          |dd          }|                    ||           |j        d         j	        d         d         j
                                        }|j        d         }|j        d         }|j        d         }||         d d |f         }	||         }
|                    |	|
           t          |j	        d         d         j
        |           d S )Nr7   )n_componentsr+   r   )r9   r0   r*   r   r-   )r   r=   r>   r   r   r   r   r@   r{   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9dkqA!A...0B0D0D M mST
U
U
UCGGAqMMM!oa06r:1=CHHJJ"I.q103!"AAA'8$89G !GMM'7###yr*1-35LMMMMMrL   c                      d} t          d| z  d          \  }}t          t                      | dd          }|                    ||           |j        | k    sJ d S )Nr   r7   r-   r  r+   )r0   r1   r*   )r   r   r   r@   _max_samples)r0   r^   r_   r%  s       rJ   test_max_samples_consistencyr=    sy     Ka+oAFFFDAq	  G KK1;......rL   c                  ^   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        }t          d| 	                              ||          j        }t          d| 	                              ||          j        }||g||gk    sJ d S )
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_encodingrH    s     L
sQC1A	1	B	aB	QBD|DDD	Q	  	D|DDD	Q	  	D|DDD	Q	 
 8BxrL   c                 d    |                      dd          } d| t          j        |            <   | S )NfloatT)r5  r   )astyper   isfinite)r^   s    rJ   replacerM  7  s0    	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                    |          }|                    | |          	                    |            t          |          }|                    | |          	                    |           }|j        |j        k    sJ t	                      }t          |          }t          j        t                    5  |                    | |           d d d            n# 1 swxY w Y   t          |          }t          j        t                    5  |                    | |           d d d            n# 1 swxY w Y   bd S )Nr-   r   r   r7   N   r7   rQ  )r7   r   r   r   r   )r7   r-   	   )r   rQ     )r   arraynaninfr"   r   r   rM  r@   rA   r   r   r   r  r  )r^   y_valuesr_   	regressorpipelinebagging_regressory_hats          rJ   *test_bagging_regressor_with_missing_inputsr\  =  s]   
IILLNNO	
	 	A 	!!
											
 	
H  ( ()++	 !4W!=!=yIIQ""1%%%,X66!%%a++33A66w%+%%%% *++	 ++]:&& 	 	LLA	 	 	 	 	 	 	 	 	 	 	 	 	 	 	,X66]:&& 	( 	(!!!Q'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(( (s$   F  F	F	3GG	G	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	                      }t          t          t                    |          }|                    | |          	                    |            t          |          }|                    | |           |	                    |           }|j        |j        k    sJ |                    |            |                    |            t	                      }t          |          }t          j        t                     5  |                    | |           d d d            n# 1 swxY w Y   t          |          }t          j        t                     5  |                    | |           d d d            d S # 1 swxY w Y   d S )NrO  rP  r7   rQ  )r   rQ  rQ  rQ  rQ  )r   rT  rU  rV  r!   r   r   rM  r@   rA   r   r   rP   rO   r   r  r  )r^   r_   
classifierrY  bagging_classifierr[  s         rJ   +test_bagging_classifier_with_missing_inputsr`  f  sB   
IILLNNO	
	 	A 	!!A'))J099:FFHLLAq!!!*8441a   &&q))E7ek!!!!((+++$$Q''' ())JZ((H	z	"	"  Q              *844	z	"	" % %q!$$$% % % % % % % % % % % % % % % % % %s$   !FFF7GG"Gc                      t          j        ddgddgg          } t          j        ddg          }t          t                      dd          }|                    | |           d S )Nr-   r7   r   r.   r   g333333?)r1   r*   )r   rT  r   r   r@   r$  s      rJ   test_bagging_small_max_featuresrb    si     	1a&1a&!""A
!QA 2 4 43UVWWWGKK1rL   c                  t   t           j                            d          } |                     dd          }t          j        d          } G d dt
                    }t           |            dd          }|                    ||           t          |j	        d         j
        |j        d                    d S )Nr      r.   c                       e Zd ZdZd ZdS )8test_bagging_get_estimators_indices.<locals>.MyEstimatorz7An estimator which stores y indices information at fit.c                     || _         d S 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   MyEstimatorrf    s)        EE	% 	% 	% 	% 	%rL   ri  r-   )r9   r:   r*   )r   randomRandomStaterandnaranger"   r   r@   r%   r{   rh  r(  )rB   r^   r_   ri  r   s        rJ   #test_bagging_get_estimators_indicesrn    s    
 )


"
"C		"aA
	"A% % % % %+ % % % [[]]QR
S
S
SCGGAqMMMsq)93;RST;UVVVVVrL   zbagging, expected_allow_nanr-   r5   c                 N    |                                  j        j        |k    sJ dS )z*Check that bagging inherits allow_nan tag.N)__sklearn_tags__
input_tags	allow_nan)r%  expected_allow_nans     rJ   test_bagging_allow_nan_tagrt    s.     ##%%0:>PPPPPPPrL   modelr
  )r9   r:   c                     t          j        d          5  |                     t          j        t          j                   ddd           dS # 1 swxY w Y   dS )zAMake sure that metadata routing works with non-default estimator.T)enable_metadata_routingN)sklearnconfig_contextr@   r<   r=   r>   ru  s    rJ   "test_bagging_with_metadata_routingr{    s     
		=	=	= * *		$)T[)))* * * * * * * * * * * * * * * * * *s   +AAAc                 Z    |                      t          j        t          j                   dS )z^Make sure that we still can use an estimator that does not implement the
    metadata routing.N)r@   r<   r=   r>   rz  s    rJ   -test_bagging_without_support_metadata_routingr}    s"     
IIdi%%%%%rL   )r  )lrf   	itertoolsr   r   r   numpyr   r   rx  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&  r2  r:  r=  rH  rM  r\  r`  rb  rn  rt  r{  r}  r;   rL   rJ   <module>r     s    % $ $ $ $ $ $ $        & & & & & & G G G G G G G G G G 9 9 9 9 9 9 9 9	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 2 1 1 1 1 1 ? ? ? ? ? ? ? ? Q Q Q Q Q Q Q Q Q Q G G G G G G G G * * * * * * < < < < < < < < < < < < < <                 F F F F F F F F , , , , , , P P P P P P P P > > > > > > > > y{{
t{'((IdO	k$ =??
x+,,d#/$'0 0 0B &G'  # !!&*	   # !!&*	  U$OOd%PP	
  	ONN%  .&2 &2/ .&2R  8 +^n-LMM5A 5A NM5Ap# # # # # # # #'9 '9 '9TE E E8 
  
  
F"& "& "&J!# !# !#HJ J J(O O O&6 &6 &6R& & &4	T 	T 	T)0 )0 )0XC C C> > > > > > > >

 

 

   4  4 4 4$& & &&  
# 
# 
#H H H%5 %5 %5PN N N6/ / /     4  &( &( &(R% % %@  W W W* !		991EEE	F	FM		77CCC	D	DdK		--//	0	0%8		##%%	 	 %(	 Q Q Q
 ,,!<<<1	
 	
 	
 	++;;;!	
 	
 	
	
 
* *
 
* ((a888	
 	
 	
 	#4#4!#D#D#DSTUUU	 	& &	 	& & &rL   