
     hz                        d Z ddlmZ ddlZddlZddlZddlmZ ddl	m
Z
 ddl	mZ ddlmZmZ ddlmZmZ dd	lmZmZ dd
lmZmZ ddlmZmZ ddlmZmZ ddlmZm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z& ddlm'Z' ddl(m)Z)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/m0Z0 ddlm1Z1 ddl2m3Z3m4Z4  e-d          Z5 e*            Z6e57                    e6j8        j9                  Z:e6j;        e:         e6_;        e6j8        e:         e6_8         e)            Z<e57                    e<j8        j9                  Z:e<j;        e:         e<_;        e<j8        e:         e<_8        d Z=ej>        ?                    d ee3e4gdddddddddddddd dddd!gg d"                    d#             Z@d$ ZAd% ZB G d& d'e          ZCd( ZDd) ZEd* ZFd+ ZGd, ZHd- ZId. ZJd/ ZKd0 ZLd1 ZMd2 ZNd3 ZO G d4 d5e          ZPd6 ZQdMd8ZRd9 ZSd: ZTd; ZUd< ZVd= ZWd> ZXd? ZYd@ ZZdA Z[dB Z\dC Z]dD Z^dE Z_dF Z`dG Zaej>        ?                    dHeefeefg          dI             Zbej>        ?                    dJeeg          dK             ZcdL ZddS )NzE
Testing for the bagging ensemble module (sklearn.ensemble.bagging).
    )productN)BaseEstimator)assert_array_equal)assert_array_almost_equal)DummyClassifierDummyRegressor)GridSearchCVParameterGrid)BaggingClassifierBaggingRegressor)
PerceptronLogisticRegression)KNeighborsClassifierKNeighborsRegressor)DecisionTreeClassifierDecisionTreeRegressor)SVCSVR)SparseRandomProjection)make_pipeline)SelectKBest)train_test_split)load_diabetes	load_irismake_hastie_10_2)check_random_state)FunctionTransformerscale)cycle)
csc_matrix
csr_matrixc                     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paramsr2   s	            _/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/sklearn/ensemble/tests/test_bagging.pytest_classificationrD   4   s*   
Q

C'7	4;S( ( ($GVWf :F#'-		
 	
 D 	B+++J !uZ'8'899 0 0	 	
	
 	
 		
 	

 #gw

0 0    zsparse_format, params, methodr%   r0   Tr)   r&   r(   Fr+   r,   r-   r*   r,   r-   )r:   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superr9   type
data_type_selfXy	__class__s      rC   r9   z1test_sparse_classification.<locals>.CustomSVC.fitr   -    GGKK1"1ggDOKrE   __name__
__module____qualname____doc__r9   __classcell__rY   s   @rC   	CustomSVCrM   o   >        EE	 	 	 	 	 	 	 	 	rE   rb   r   r#   linearovr)kerneldecision_function_shaper'   r2   r$   c                     g | ]	}|j         
S r4   rT   .0is     rC   
<listcomp>z.test_sparse_classification.<locals>.<listcomp>   s    AAAaQ\AAArE   c                     g | ]}|k    	S r4   r4   rl   tsparse_types     rC   rn   z.test_sparse_classification.<locals>.<listcomp>   s    000Q[ 000rE   r4   )r   r   r   r   r5   r6   r7   r   r9   getattrr   rS   estimators_all)sparse_formatrB   methodrb   r;   r<   r=   r>   r?   X_train_sparseX_test_sparsesparse_classifiersparse_resultsdense_classifierdense_resultstypesrr   s                   @rC   test_sparse_classificationr   U   s   4    C    Q

C'7di$+C( ( ($GVWf #]7++N!M&))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1rE   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)   rh   r4   )r   r   diabetesr6   r7   r
   r   r   r   r   r   r9   r:   )r;   r<   r=   r>   r?   r@   r2   rB   s           rC   test_regressionr      s   
Q

C'7crcHOCRC0s( ( ($GVWf : #J#'-		
 	
 D 	 
 
	  	 	FMysMMfMMQQ gfoooo	
 
rE   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}t          t          fD ]} ||          } ||          }	|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>.CustomSVRrN   c                 t    t                                          ||           t          |          | _        | S rP   rQ   rU   s      rC   r9   z-test_sparse_regression.<locals>.CustomSVR.fit   rZ   rE   r[   ra   s   @rC   	CustomSVRr      rc   rE   r   r%   r0   Tr)   r&   r(   FrF   rG   r'   rh   c                     g | ]	}|j         
S r4   rj   rk   s     rC   rn   z*test_sparse_regression.<locals>.<listcomp>   s    IIIaQ\IIIrE   c                     g | ]}|k    	S r4   r4   rp   s     rC   rn   z*test_sparse_regression.<locals>.<listcomp>   s    888Q[(888rE   r4   )r   r   r   r6   r7   r   r    r!   r   r9   r:   rS   rt   r   ru   )r;   r<   r=   r>   r?   r   parameter_setsrv   rx   ry   rB   rz   r{   r}   r~   rr   s                  @rC   test_sparse_regressionr      s&   
Q

C'7crcHOCRC0s( ( ($GVWf    C    "&		
 	
 "&		
 	
 dKK$eLLN" %j1 E E&w//%f--$ 	E 	EF !1 !#)++A! !9?! !c.'**  /66}EEN !Q99;;QQQ&QQWg&&  ~..KII+<+HIIIE%nmDDD8888%88899999%nmDDDD)	EE ErE   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_rV   rW   rX   s      rC   r9   zDummySizeEstimator.fit   s&    gaj$k!nnrE   c                 @    t          j        |j        d                   S r   )nponesr   rV   rW   s     rC   r:   zDummySizeEstimator.predict   s    wqwqz"""rE   Nr\   r]   r^   r9   r:   r4   rE   rC   r   r      s2        - - -# # # # #rE   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)r2   r*   r,   r$   T)r2   r,   )r   r   r   r6   r7   r   r9   r   scorer   rt   r   r   appendr   lenset)r;   r<   r=   r>   r?   r2   ensembletraining_hashs           rC   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8rE   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)r2   r+   r-   r$   r'   T)r   r   r   r6   r7   r   r   r9   estimators_features_r   r   unique)r;   r<   r=   r>   r?   r   featuress          rC   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rE   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invalidrh   r'   )axis   )r2   r$   r*   )r   r   r5   r6   r7   r   errstater   r   r9   r   sumrH   r   r   exprI   r   r;   r<   r=   r>   r?   r   s         rC   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r2   r3   r,   	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   r5   r6   r7   r   r   r   r9   r   abs
oob_score_pytestwarnsUserWarning)	r;   r<   r=   r>   r?   r2   clf
test_scorewarn_msgs	            rC   test_oob_score_classificationr   ]  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   r6   r7   r   r   r9   r   r   r   r   r   r   )	r;   r<   r=   r>   r?   r   r   r   regrs	            rC   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)r2   r3   r,   r-   r$   )
r   r   r   r6   r7   r   r   r9   r   r:   )r;   r<   r=   r>   r?   clf1clf2s          rC   test_single_estimatorr     s    
Q

C'7xS( ( ($GVWf %''    
c'7 	   $$Wg66Ddll622DLL4H4HIIIIIrE   c                      t           j        t           j        }} t                      }t	          t          |                              | |          d          rJ d S )NrJ   )r5   r6   r7   r   hasattrr   r9   )rW   rX   bases      rC   
test_errorr     sP    9dkqA!##D(..221a88:MNNNNNNNrE   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   re   )rg   )r   r5   r6   r7   r   r   r9   rH   
set_paramsr   r   rJ   )r<   r=   r>   r?   r   y1y2y3
decisions1
decisions2
decisions3s              rC   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5rE   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   r0   )r   r   r   r6   r7   r   r   r9   r   r:   r   )	r;   r<   r=   r>   r?   r   r   r   r   s	            rC   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"%%%%%rE   c                      t           j        t           j        }} d||dk    <   ddd}t          t	          t                                |d                              | |           d S )Nr'   r0   )r'   r0   )r3   estimator__Croc_auc)scoring)r5   r6   r7   r	   r   r   r9   )rW   rX   
parameterss      rC   test_gridsearchr     sf     9dkqAAa1fI #)&AAJ"355)):yIIIMMaQRSSSSSrE   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   r5   r6   r7   r   r9   
isinstance
estimator_r   r   r   r   r   r   r   s         rC   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///////rE   c                  2   t          t          t          d          t                                d          } |                     t
          j        t
          j                   t          | d         j	        d         d         j
        t                    sJ d S )Nr'   )kr0   )r+   r   )r   r   r   r   r9   r5   r6   r7   r   stepsr$   int)r2   s    rC   test_bagging_with_pipeliner   <  s    !kA&&&(>(@(@AAPQ  I MM$)T[)))il(,Q/<cBBBBBBBrE   c                       e Zd Zd Zd ZdS )DummyZeroEstimatorc                 8    t          j        |          | _        | S rP   )r   r   classes_r   s      rC   r9   zDummyZeroEstimator.fitE  s    	!rE   c                 d    | j         t          j        |j        d         t                             S )Nr   )dtype)r   r   zerosr   r   r   s     rC   r:   zDummyZeroEstimator.predictI  s$    }RXagaj<<<==rE   Nr   r4   rE   rC   r   r   D  s2          > > > > >rE   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   r9   r5   r6   r7   r:   r   raises
ValueErrorrandintr   )r2   r;   s     rC   1test_bagging_sample_weight_unsupported_but_passedr   M  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 )Nr.   r'   	n_samplesr$   )r   r   T)r3   r$   
warm_startr3   r   Fc                     g | ]	}|j         
S r4   r#   rl   trees     rC   rn   z#test_warm_start.<locals>.<listcomp>o  s    555d!555rE   c                     g | ]	}|j         
S r4   r#   r  s     rC   rn   z#test_warm_start.<locals>.<listcomp>p  s    111t	111rE   )r   r   r   r9   r   r   )r$   rW   rX   clf_wsr3   	clf_no_wss         rC   test_warm_startr
  Z  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; ;      rE   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 )	Nr.   r'   r   r   T)r3   r  r(   r  )r   r   r9   r   r   r   r   rW   rX   r   s      rC   $test_warm_start_smaller_n_estimatorsr  t  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 )Nr.   r'   r   +   r#   r   TS   r3   r  r$   r&   z;Warm-start fitting without increasing n_estimators does notr   )	r   r   r   r9   r:   r   r   r   r   )	rW   rX   r<   r=   r>   r?   r   y_predr   s	            rC   "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 )Nr.   r'   r   r  r#   r   TiE  r  r   r  F)r   r   r   r9   r   r:   r   )
rW   rX   r<   r=   r>   r?   r  r   r   r   s
             rC   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"%%%%%rE   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 )Nr.   r'   r   r   T)r3   r  r   )r   r   r   r   r   r9   r  s      rC   $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)r3   r   Fr   )r  r   r3   r   )r   r   r9   r   r   r   AttributeErrorrs   r  s      rC   $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)r*   r+   r   r$   )r   r   r   r9   r   rW   rX   baggings      rC   test_oob_score_consistencyr    s~     c:::DAq  G ;;q!'7;;q!+<+<+GGGGGGGrE   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)r*   r+   r$   r,   r   r0   rm   )r   r   r   r9   estimators_samples_r   rt   r   r   kindcoef_r   )rW   rX   r  estimators_samplesestimators_featuresrA   estimator_indexestimator_samplesestimator_featuresr2   r<   r>   
orig_coefs	new_coefss                 rC   test_estimators_samplesr+    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4rE   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 )Nr0   )n_componentsr%   r   )r2   r*   r$   r   r'   )r   r6   r7   r   r   r   r   r9   rt   r   r#  copyr!  r   r   )r5   rW   rX   base_pipeliner   pipeline_estimator_coefr2   estimator_sampleestimator_featurer<   r>   s              rC   %test_estimators_samples_deterministicr3    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MrE   c                      d} t          d| z  d          \  }}t          t                      | dd          }|                    ||           |j        | k    sJ d S )Nr   r0   r'   r   r%   )r*   r+   r$   )r   r   r   r9   _max_samples)r*   rW   rX   r  s       rC   test_max_samples_consistencyr6  	  sy     Ka+oAFFFDAq	  G KK1;......rE   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'   r0   T)r   r$   )r   r9   r   )r$   rW   Y1Y2Y3x1x2x3s           rC   !test_set_oob_score_label_encodingrA    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rE   c                 d    |                      dd          } d| t          j        |            <   | S )NfloatT)r.  r   )astyper   isfinite)rW   s    rC   replacerF  2  s0    	t$$AAr{1~~oHrE   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   r0   N   r0   rJ  )r0   r   r   r   r   )r0   r'   	   )r   rJ     )r   arraynaninfNINFr   r   r   rF  r9   r:   r   r   r   r   r   )rW   y_valuesrX   	regressorpipelinebagging_regressory_hats          rC   *test_bagging_regressor_with_missing_inputsrV  8  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$   E??F	F	2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 )NrH  rI  r0   rJ  )r   rJ  rJ  rJ  rJ  )r   rM  rN  rO  rP  r   r   r   rF  r9   r:   r   r   rI   rH   r   r   r   )rW   rX   
classifierrS  bagging_classifierrU  s         rC   +test_bagging_classifier_with_missing_inputsrZ  a  s@   
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6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'   r0   r   r(   r   g333333?)r+   r$   )r   rM  r   r   r9   r  s      rC   test_bagging_small_max_featuresr\    si     	1a&1a&!""A
!QA 2 4 43UVWWWGKK1rE   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 rP   )_sample_indicesr   s      rC   r9   z<test_bagging_get_estimators_indices.<locals>.MyEstimator.fit  s    #$D   rE   N)r\   r]   r^   r_   r9   r4   rE   rC   MyEstimatorr`    s)        EE	% 	% 	% 	% 	%rE   rc  r'   )r2   r3   r$   )r   randomRandomStaterandnaranger   r   r9   r   rt   rb  r!  )r;   rW   rX   rc  r   s        rC   #test_bagging_get_estimators_indicesrh    s    
 )


"
"C		"aA
	"A% % % % %+ % % % [[]]QR
S
S
SCGGAqMMMsq)93;RST;UVVVVVrE   zBagging, Estimatorc                 (   t          j        ddgddgg          }t          j        ddg          } |  |            d          }d}t          j        t          |	          5  |                    ||           d d d            d S # 1 swxY w Y   d S )
Nr'   r0   r   r(   r   r   )base_estimatorr3   V`base_estimator` was renamed to `estimator` in version 1.2 and will be removed in 1.4.r   )r   rM  r   r   FutureWarningr9   )Bagging	EstimatorrW   rX   modelr   s         rC   'test_base_estimator_argument_deprecatedrp    s     	1a&1a&!""A
!QAG99;;R@@@E	"  
m8	4	4	4  		!Q                 s   #BBBrm  c                     t          j        ddgddgg          }t          j        ddg          } |             }|                    ||           d}t          j        t
          |          5  |j         d d d            d S # 1 swxY w Y   d S )Nr'   r0   r   r(   r   zoAttribute `base_estimator_` was deprecated in version 1.2 and will be removed in 1.4. Use `estimator_` instead.r   )r   rM  r9   r   r   rl  base_estimator_)rm  rW   rX   ro  r   s        rC   'test_base_estimator_property_deprecatedrs    s    
 	1a&1a&!""A
!QAGIIE	IIaOOO	<  
m8	4	4	4                   s   .BB
Bc                  p   t                      } | j        | j        }}t          t	                                }t          |d          sJ d}t          j        t          |          5  |	                    ||          
                    |          }ddd           n# 1 swxY w Y   |j        dk    sJ dS )zSCheck that `BaggingClassifier` delegate to classifier with
    `decision_function`.)rj  rJ   rk  r   N)   r   )r   r6   r7   r   r   r   r   r   rl  r9   rJ   r   )r5   rW   rX   r   r   
y_decisions         rC   4test_deprecated_base_estimator_has_decision_functionrw    s     ;;D9dkqA
355
1
1
1C3+,,,,,	"  
m8	4	4	4 8 8WWQ]]44Q77
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8x''''''s   (*BB"%B")r   )er_   	itertoolsr   numpyr   r   r   sklearn.baser   sklearn.utils._testingr   r   sklearn.dummyr   r   sklearn.model_selectionr	   r
   sklearn.ensembler   r   sklearn.linear_modelr   r   sklearn.neighborsr   r   sklearn.treer   r   sklearn.svmr   r   sklearn.random_projectionr   sklearn.pipeliner   sklearn.feature_selectionr   r   sklearn.datasetsr   r   r   sklearn.utilsr   sklearn.preprocessingr   r   r   scipy.sparser    r!   r;   r5   permutationr7   r   permr6   r   rD   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+  r3  r6  rA  rF  rV  rZ  r\  rh  rp  rs  rw  r4   rE   rC   <module>r     s                & & & & & & 5 5 5 5 5 5 < < < < < < 9 9 9 9 9 9 9 9 ? ? ? ? ? ? ? ? @ @ @ @ @ @ @ @ ? ? ? ? ? ? ? ? G G G G G G G G F F F F F F F F                 < < < < < < * * * * * * 1 1 1 1 1 1 4 4 4 4 4 4 G G G G G G G G G G , , , , , , < < < < < < < <       / / / / / / / / y{{
t{'((IdO	k$ =??
x+,,d#/$'0 0 0B #G	Z   # !!&*	   # !!&*	  U$OOd%PP	
  	ONN%  .&2 &2/ .&2R  87E 7E 7Et# # # # # # # #'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, 	23	01 
 
 
 )*  	 ( ( ( ( (rE   