a
    �ù»jE~  ã                   @   sä  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=jBeA e=_Be=j?eA e=_?eƒ ZCe< >eCj?j@¡ZAeCjBeA eC_BeCj?eA eC_?dd„ ZDejE Fdee;e: dddddœdddddœddddœddddœgg d ¢ƒ¡d!d"„ ƒZGd#d$„ ZHejE Fd%e;e: ¡d&d'„ ƒZIG d(d)„ d)e
ƒZJd*d+„ ZKd,d-„ ZLd.d/„ ZMd0d1„ ZNd2d3„ ZOd4d5„ ZPd6d7„ ZQd8d9„ ZRd:d;„ ZSd<d=„ ZTd>d?„ ZUd@dA„ ZVG dBdC„ dCe
ƒZWdDdE„ ZXdsdGdH„ZYdIdJ„ ZZdKdL„ Z[dMdN„ Z\dOdP„ Z]dQdR„ Z^dSdT„ Z_dUdV„ Z`dWdX„ ZadYdZ„ Zbd[d\„ Zcd]d^„ Zdd_d`„ Zedadb„ Zfdcdd„ Zgdedf„ ZhejE Fdgeedhdi�ƒdfeedhdi�ƒdfeeƒ ƒdfee0ƒ ƒdfg¡djdk„ ƒZiejE Fdleedhdm�dhdn�eedhdm�dhdn�g¡dodp„ ƒZjejE Fdleedhdm�dhdn�eedhdm�dhdn�g¡dqdr„ ƒZkdS )tzE
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            	      C   s¦   t dƒ} ttjtj| d�\}}}}tddgddgddgddgd	œƒ}d tƒ td
d�tdd�t	ƒ t
ƒ g}t|t|ƒƒD ],\}}tf || ddœ|¤Ž ||¡ |¡ qtd S )Nr   ©Úrandom_stateç      à?ç      ð?é   é   TF©Úmax_samplesÚmax_featuresÚ	bootstrapÚbootstrap_featuresé   ©Z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Úparamsr6   © rF   úIE:\soccer\ml_env\Lib\site-packages\sklearn/ensemble/tests/test_bagging.pyÚtest_classification:   s<    
ÿüÿ	ú
ýüûûrH   z sparse_container, params, methodr)   r4   Tr-   r*   r,   F©r/   r0   r1   ©r.   r0   r1   )r=   Úpredict_probaÚpredict_log_probaÚdecision_functionc                    sê   G dd„ dt ƒ}tdƒ}tttjƒtj|d�\}}}}| |ƒ}	| |ƒ}
tf |ddd�dd	œ|¤Ž |	|¡}t	||ƒ|
ƒ}tf |ddd�dd	œ|¤Ž ||¡}t	||ƒ|ƒ}t
||ƒ t|	ƒ‰ d
d„ |jD ƒ}t‡ fdd„|D ƒƒsæJ ‚d S )Nc                       s    e Zd ZdZ‡ fdd„Z‡  ZS )z-test_sparse_classification.<locals>.CustomSVCú7SVC variant that records the nature of the training setc                    s   t ƒ  ||¡ t|ƒ| _| S ©N©Úsuperr<   ÚtypeÚ
data_type_©ÚselfÚXÚy©Ú	__class__rF   rG   r<   x   s    
z1test_sparse_classification.<locals>.CustomSVC.fit©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r<   Ú__classcell__rF   rF   rX   rG   Ú	CustomSVCu   s   r`   r   r'   ZlinearÚovr)ZkernelÚdecision_function_shaper+   ©r6   r(   c                 S   s   g | ]
}|j ‘qS rF   ©rS   ©Ú.0ÚirF   rF   rG   Ú
<listcomp>–   ó    z.test_sparse_classification.<locals>.<listcomp>c                    s   g | ]}|ˆ k‘qS rF   rF   ©rf   Út©Zsparse_typerF   rG   rh   ˜   ri   )r   r"   r   r   r8   r9   r:   r   r<   Úgetattrr#   rR   Úestimators_Úall)Úsparse_containerrE   Úmethodr`   r>   r?   r@   rA   rB   ÚX_train_sparseÚX_test_sparseÚsparse_classifierÚsparse_resultsZdense_classifierÚdense_resultsÚtypesrF   rl   rG   Útest_sparse_classification[   s:    ÿ
þýü
þýü
rx   c                  C   s    t dƒ} ttjd d… tjd d… | d�\}}}}tddgddgddgddgdœƒ}d tƒ tƒ tƒ t	ƒ fD ]0}|D ]&}t
f || d	œ|¤Ž ||¡ |¡ qrqjd S )
Nr   é2   r'   r)   r*   TFr-   rc   )r"   r   Údiabetesr9   r:   r   r	   r!   r   r   r   r<   r=   )r>   r?   r@   rA   rB   rC   r6   rE   rF   rF   rG   Útest_regression›   s.    ÿüÿ
ûÿþr{   rp   c                    s$  t dƒ}ttjd d… tjd d… |d�\}}}}G dd„ dtƒ}ddddd	œd
dddd	œddddœddddœg}| |ƒ}| |ƒ}	|D ]˜}
tf |ƒ ddœ|
¤Ž ||¡}| |	¡}tf |ƒ ddœ|
¤Ž ||¡ |¡}t	|ƒ‰ dd„ |j
D ƒ}t||ƒ t‡ fdd„|D ƒƒ�sJ ‚t||ƒ q†d S )Nr   ry   r'   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )z)test_sparse_regression.<locals>.CustomSVRrN   c                    s   t ƒ  ||¡ t|ƒ| _| S rO   rP   rT   rX   rF   rG   r<   Â   s    
z-test_sparse_regression.<locals>.CustomSVR.fitrZ   rF   rF   rX   rG   Ú	CustomSVR¿   s   r|   r)   r4   Tr-   r*   r,   FrI   rJ   r+   rc   c                 S   s   g | ]
}|j ‘qS rF   rd   re   rF   rF   rG   rh   é   ri   z*test_sparse_regression.<locals>.<listcomp>c                    s   g | ]}|ˆ k‘qS rF   rF   rj   rl   rF   rG   rh   ì   ri   )r"   r   rz   r9   r:   r   r   r<   r=   rR   rn   r#   ro   )rp   r>   r?   r@   rA   rB   r|   Zparameter_setsrr   rs   rE   rt   ru   rv   rw   rF   rl   rG   Útest_sparse_regression·   sP    ÿ
üü

òÿÿþ
ÿþÿ
r}   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚDummySizeEstimatorc                 C   s   |j d | _t |¡| _d S ©Nr   )ÚshapeÚtraining_size_ÚjoblibÚhashÚtraining_hash_rT   rF   rF   rG   r<   ñ   s    zDummySizeEstimator.fitc                 C   s   t  |jd ¡S r   )ÚnpÚonesr€   ©rU   rV   rF   rF   rG   r=   õ   s    zDummySizeEstimator.predictN©r[   r\   r]   r<   r=   rF   rF   rF   rG   r~   ð   s   r~   c                  C   sþ   t dƒ} ttjtj| d�\}}}}tƒ  ||¡}ttƒ dd| d� ||¡}| ||¡| ||¡ksfJ ‚ttƒ dd| d� ||¡}| ||¡| ||¡ksœJ ‚tt	ƒ dd� ||¡}g }|j
D ]$}|j|jd ksÔJ ‚| |j¡ q¼tt|ƒƒt|ƒksúJ ‚d S )Nr   r'   r*   F)r6   r.   r0   r(   T)r6   r0   )r"   r   rz   r9   r:   r!   r<   r   Úscorer~   rn   r�   r€   Úappendr„   ÚlenÚset)r>   r?   r@   rA   rB   r6   ÚensembleZtraining_hashrF   rF   rG   Útest_bootstrap_samplesù   s>    
ÿüûüûÿ
rŽ   c                  C   s²   t dƒ} ttjtj| d�\}}}}ttƒ dd| d� ||¡}|jD ]$}tjj	d t
 |¡j	d ksBJ ‚qBttƒ dd| d� ||¡}|jD ]$}tjj	d t
 |¡j	d ksˆJ ‚qˆd S )Nr   r'   r*   F)r6   r/   r1   r(   r+   T)r"   r   rz   r9   r:   r   r!   r<   Úestimators_features_r€   r…   Úunique)r>   r?   r@   rA   rB   r�   ÚfeaturesrF   rF   rG   Útest_bootstrap_features#  s0    
ÿüû
"üû
r’   c                  C   s  t dƒ} ttjtj| d�\}}}}tjddd��¾ ttƒ | d� 	||¡}t
tj| |¡dd�t t|ƒ¡ƒ t
| |¡t | |¡¡ƒ ttƒ | dd	� 	||¡}t
tj| |¡dd�t t|ƒ¡ƒ t
| |¡t | |¡¡ƒ W d   ƒ n1 sô0    Y  d S )
Nr   r'   Úignore)ÚdivideÚinvalidrc   r+   )Zaxisé   )r6   r(   r.   )r"   r   r8   r9   r:   r…   Zerrstater   r    r<   r#   ÚsumrK   r†   r‹   ÚexprL   r   ©r>   r?   r@   rA   rB   r�   rF   rF   rG   Útest_probability?  s6    
ÿÿþÿÿÿþÿÿrš   c            	   	   C   sÄ   t dƒ} ttjtj| d�\}}}}tƒ tƒ fD ]�}t|ddd| d� ||¡}| 	||¡}t
||j ƒdk snJ ‚d}tjt|d��. t|d	dd| d�}| ||¡ W d   ƒ q.1 s´0    Y  q.d S )
Nr   r'   éd   T©r6   r7   r0   Ú	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   r8   r9   r:   r    r   r   r<   r‰   ÚabsÚ
oob_score_ÚpytestÚwarnsÚUserWarning)	r>   r?   r@   rA   rB   r6   ÚclfÚ
test_scoreÚwarn_msgrF   rF   rG   Útest_oob_score_classificationb  s6    
ÿûúÿûrª   c            	      C   s¶   t dƒ} ttjtj| d�\}}}}ttƒ ddd| d� ||¡}| ||¡}t	||j
 ƒdk s`J ‚d}tjt|d��0 ttƒ d	dd| d�}| ||¡ W d   ƒ n1 s¨0    Y  d S )
Nr   r'   ry   Trœ   rž   rŸ   r    r+   )r"   r   rz   r9   r:   r   r!   r<   r‰   r¢   r£   r¤   r¥   r¦   )	r>   r?   r@   rA   rB   r§   r¨   r©   ZregrrF   rF   rG   Útest_oob_score_regression‡  s4    
ÿûúÿûr«   c                  C   sf   t dƒ} ttjtj| d�\}}}}ttƒ ddd| d� ||¡}tƒ  ||¡}t| 	|¡| 	|¡ƒ d S )Nr   r'   r+   F)r6   r7   r0   r1   r(   )
r"   r   rz   r9   r:   r   r   r<   r#   r=   )r>   r?   r@   rA   rB   Zclf1Zclf2rF   rF   rG   Útest_single_estimator«  s    
ÿûúr¬   c                  C   s2   t jt j } }tƒ }tt|ƒ | |¡dƒr.J ‚d S )NrM   )r8   r9   r:   r    Úhasattrr   r<   )rV   rW   ÚbaserF   rF   rG   Ú
test_error¿  s    r¯   c                  C   s  t tjtjdd�\} }}}ttƒ ddd� | |¡}| |¡}|jdd� | |¡}t	||ƒ ttƒ ddd� | |¡}| |¡}t	||ƒ tt
dd�ddd� | |¡}| |¡}|jdd� | |¡}	t	||	ƒ tt
dd�ddd� | |¡}| |¡}
t	||
ƒ d S )	Nr   r'   é   ©Ún_jobsr(   r+   ©r²   ra   )rb   )r   r8   r9   r:   r   r    r<   rK   Ú
set_paramsr#   r   rM   )r?   r@   rA   rB   r�   Úy1Úy2Úy3Z
decisions1Z
decisions2Z
decisions3rF   rF   rG   Útest_parallel_classificationÆ  sF    
ÿÿþ


ÿþ

ÿþ


ÿþ
r¸   c            	      C   s    t dƒ} ttjtj| d�\}}}}ttƒ ddd� ||¡}|jdd� | 	|¡}|jdd� | 	|¡}t
||ƒ ttƒ ddd� ||¡}| 	|¡}t
||ƒ d S )Nr   r'   r°   r±   r+   r³   r4   )r"   r   rz   r9   r:   r   r!   r<   r´   r=   r#   )	r>   r?   r@   rA   rB   r�   rµ   r¶   r·   rF   rF   rG   Útest_parallel_regressionï  s"    
ÿÿ


ÿ
r¹   c                  C   sD   t jt j } }d||dk< dddœ}tttƒ ƒ|dd� | |¡ d S )Nr+   r4   )r+   r4   )r7   Zestimator__CZroc_auc)Zscoring)r8   r9   r:   r   r   r   r<   )rV   rW   Ú
parametersrF   rF   rG   Útest_gridsearch	  s    
r»   c                  C   s0  t dƒ} ttjtj| d�\}}}}td ddd� ||¡}t|jt	ƒsHJ ‚tt	ƒ ddd� ||¡}t|jt	ƒspJ ‚tt
ƒ ddd� ||¡}t|jt
ƒs˜J ‚ttjtj| d�\}}}}td ddd� ||¡}t|jtƒsØJ ‚ttƒ ddd� ||¡}t|jtƒ�sJ ‚ttƒ ddd� ||¡}t|jtƒ�s,J ‚d S )Nr   r'   r°   r±   )r"   r   r8   r9   r:   r   r<   Ú
isinstanceZ
estimator_r    r   rz   r   r!   r   r™   rF   rF   rG   Útest_estimator  s6    
ÿÿþÿ
ÿÿr½   c                  C   sL   t ttdd�tƒ ƒdd�} |  tjtj¡ t| d j	d d j
tƒsHJ ‚d S )Nr+   )Úkr4   )r/   r   éÿÿÿÿ)r   r   r   r    r<   r8   r9   r:   r¼   Ústepsr(   Úint)r6   rF   rF   rG   Útest_bagging_with_pipelineA  s
    ÿrÂ   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚDummyZeroEstimatorc                 C   s   t  |¡| _| S rO   )r…   r�   Úclasses_rT   rF   rF   rG   r<   J  s    zDummyZeroEstimator.fitc                 C   s   | j tj|jd td� S )Nr   )Údtype)rÄ   r…   Zzerosr€   rÁ   r‡   rF   rF   rG   r=   N  s    zDummyZeroEstimator.predictNrˆ   rF   rF   rF   rG   rÃ   I  s   rÃ   c                  C   s~   t tƒ ƒ} tdƒ}|  tjtj¡ tj¡ t 	t
¡�6 | jtjtj|jdtjjd d�d� W d   ƒ n1 sp0    Y  d S )Nr   é
   )Úsize)Zsample_weight)r   rÃ   r"   r<   r8   r9   r:   r=   r¤   ÚraisesÚ
ValueErrorÚrandintr€   )r6   r>   rF   rF   rG   Ú1test_bagging_sample_weight_unsupported_but_passedR  s    
ýrË   é*   c                 C   s¤   t ddd�\}}d }dD ]D}|d u r4t|| dd�}n|j|d� | ||¡ t|ƒ|ksJ ‚qtd| d	d�}| ||¡ td
d„ |D ƒƒtdd„ |D ƒƒks J ‚d S )Nr2   r+   ©Z	n_samplesr(   )r–   rÆ   T)r7   r(   Ú
warm_start©r7   rÆ   Fc                 S   s   g | ]
}|j ‘qS rF   r'   ©rf   ÚtreerF   rF   rG   rh   t  ri   z#test_warm_start.<locals>.<listcomp>c                 S   s   g | ]
}|j ‘qS rF   r'   rÐ   rF   rF   rG   rh   u  ri   )r   r   r´   r<   r‹   rŒ   )r(   rV   rW   Úclf_wsr7   Z	clf_no_wsrF   rF   rG   Útest_warm_start_  s"    ÿÿÿrÓ   c                  C   sn   t ddd�\} }tddd�}| | |¡ |jdd� t t¡� | | |¡ W d   ƒ n1 s`0    Y  d S )	Nr2   r+   rÍ   r–   T)r7   rÎ   r,   rÏ   )r   r   r<   r´   r¤   rÈ   rÉ   ©rV   rW   r§   rF   rF   rG   Ú$test_warm_start_smaller_n_estimatorsy  s    rÕ   c            	      C   s¤   t ddd�\} }t| |dd�\}}}}tdddd	�}| ||¡ | |¡}|d
7 }d}tjt|d�� | ||¡ W d   ƒ n1 s†0    Y  t|| |¡ƒ d S )Nr2   r+   rÍ   é+   r'   r–   TéS   ©r7   rÎ   r(   r*   z;Warm-start fitting without increasing n_estimators does notr    )	r   r   r   r<   r=   r¤   r¥   r¦   r$   )	rV   rW   r?   r@   rA   rB   r§   Zy_predr©   rF   rF   rG   Ú"test_warm_start_equal_n_estimatorsƒ  s    
*rÙ   c            
      C   s”   t ddd�\} }t| |dd�\}}}}tdddd	�}| ||¡ |jd
d� | ||¡ | |¡}td
ddd	�}| ||¡ | |¡}	t||	ƒ d S )Nr2   r+   rÍ   rÖ   r'   r–   TiE  rØ   rÆ   rÏ   F)r   r   r   r<   r´   r=   r#   )
rV   rW   r?   r@   rA   rB   rÒ   rµ   r§   r¶   rF   rF   rG   Útest_warm_start_equivalence•  s    

rÚ   c                  C   sX   t ddd�\} }tdddd�}t t¡� | | |¡ W d   ƒ n1 sJ0    Y  d S )Nr2   r+   rÍ   r–   T)r7   rÎ   r�   )r   r   r¤   rÈ   rÉ   r<   rÔ   rF   rF   rG   Ú$test_warm_start_with_oob_score_fails¨  s    rÛ   c                  C   s|   t ddd�\} }tddd�}| | |¡ |jdddd	� | | |¡ t t¡� t|d
ƒ W d   ƒ n1 sn0    Y  d S )Nr›   r+   rÍ   r–   T)r7   r�   FrÆ   )rÎ   r�   r7   r£   )r   r   r<   r´   r¤   rÈ   ÚAttributeErrorrm   rÔ   rF   rF   rG   Ú$test_oob_score_removed_on_warm_start°  s    rÝ   c                  C   sH   t ddd�\} }ttƒ ddddd�}| | |¡j| | |¡jksDJ ‚d S )NéÈ   r+   rÍ   r)   T)r.   r/   r�   r(   )r   r   r   r<   r£   ©rV   rW   ÚbaggingrF   rF   rG   Útest_oob_score_consistency½  s    ûrá   c                  C   sä   t ddd�\} }ttƒ ddddd�}| | |¡ |j}|j}|j}t|ƒt|ƒksVJ ‚t|d ƒt| ƒd ksrJ ‚|d jj	d	ks†J ‚d}|| }|| }|| }	| | d d …|f }
|| }|	j
}|	 |
|¡ |	j
}t||ƒ d S )
NrÞ   r+   rÍ   r)   F)r.   r/   r(   r0   r   r4   rg   )r   r   r   r<   Úestimators_samples_r�   rn   r‹   rÅ   ÚkindÚcoef_r#   )rV   rW   rà   Zestimators_samplesZestimators_featuresrD   Zestimator_indexZestimator_samplesZestimator_featuresr6   r?   rA   Z
orig_coefsZ	new_coefsrF   rF   rG   Útest_estimators_samplesË  s2    ûrå   c                  C   sº   t ƒ } | j| j }}ttdd�tƒ ƒ}t|ddd�}| ||¡ |jd j	d d j
 ¡ }|jd }|jd }|jd }|| d d …|f }	|| }
| |	|
¡ t|j	d d j
|ƒ d S )Nr4   )Zn_componentsr)   r   )r6   r.   r(   r¿   r+   )r   r9   r:   r   r   r   r   r<   rn   rÀ   rä   Úcopyrâ   r�   r$   )r8   rV   rW   Zbase_pipeliner§   Zpipeline_estimator_coefr6   Zestimator_sampleZestimator_featurer?   rA   rF   rF   rG   Ú%test_estimators_samples_deterministicó  s    ÿ


rç   c                  C   sH   d} t d|  dd�\}}ttƒ | ddd�}| ||¡ |j| ksDJ ‚d S )Nr›   r4   r+   rÍ   r)   )r.   r/   r(   )r   r   r   r<   Z_max_samples)r.   rV   rW   rà   rF   rF   rG   Útest_max_samples_consistency  s    ürè   c                  C   s–   d} dgdgdggd }g d¢d }g d¢d }g d¢d }t d| d	� ||¡j}t d| d	� ||¡j}t d| d	� ||¡j}||g||gks’J ‚d S )
Nr–   r¿   r   r+   )ÚAÚBÚC)r¿   r   r+   )r   r+   r4   T)r�   r(   )r   r<   r£   )r(   rV   ZY1ZY2ZY3Úx1Zx2Zx3rF   rF   rG   Ú!test_set_oob_score_label_encoding  s$    ÿÿÿÿÿÿrí   c                 C   s"   | j ddd�} d| t | ¡ < | S )NÚfloatT)ræ   r   )Zastyper…   Úisfinite)rV   rF   rF   rG   Úreplace7  s    rð   c               	   C   sN  t  g d¢g d¢dt jdgdt jdgdt j dgg¡} t  g d¢¡t  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 t¡� | | |¡ W d   ƒ n1 sþ0    Y  t
|ƒ}t t¡� | | |¡ W d   ƒ qp1 �s>0    Y  qpd S )N©r+   r°   r–   ©r4   Né   r4   ró   )r4   r°   r°   r°   r°   )r4   r+   é	   )r°   ró   é   )r…   ÚarrayÚnanÚinfr!   r   r   rð   r<   r=   r   r€   r¤   rÈ   rÉ   )rV   Zy_valuesrW   Z	regressorÚpipelineZbagging_regressorÚy_hatrF   rF   rG   Ú*test_bagging_regressor_with_missing_inputs=  s@    

ûÿ
ûÿþ*rû   c               	   C   s4  t  g d¢g d¢dt jdgdt jdgdt j dgg¡} t  g d¢¡}tƒ }tttƒ|ƒ}| | |¡ 	| ¡ t
|ƒ}| | |¡ | 	| ¡}|j|jks˜J ‚| | ¡ | | ¡ tƒ }t|ƒ}t t¡� | | |¡ W d   ƒ n1 sæ0    Y  t
|ƒ}t t¡� | | |¡ W d   ƒ n1 �s&0    Y  d S )Nrñ   rò   r4   ró   )r°   ró   ró   ró   ró   )r…   rö   r÷   rø   r    r   r   rð   r<   r=   r   r€   rL   rK   r¤   rÈ   rÉ   )rV   rW   Ú
classifierrù   Zbagging_classifierrú   rF   rF   rG   Ú+test_bagging_classifier_with_missing_inputsf  s2    

ûÿ	


*rý   c                  C   sD   t  ddgddgg¡} t  ddg¡}ttƒ ddd�}| | |¡ d S )Nr+   r4   r°   r,   r   g333333Ó?)r/   r(   )r…   rö   r   r   r<   rß   rF   rF   rG   Útest_bagging_small_max_features†  s    rþ   c                  C   sj   t j d¡} |  dd¡}t  d¡}G dd„ dtƒ}t|ƒ ddd�}| ||¡ t|j	d j
|jd ƒ d S )Nr   é   r,   c                   @   s   e Zd ZdZdd„ ZdS )z8test_bagging_get_estimators_indices.<locals>.MyEstimatorz7An estimator which stores y indices information at fit.c                 S   s
   || _ d S rO   )Ú_sample_indicesrT   rF   rF   rG   r<   œ  s    z<test_bagging_get_estimators_indices.<locals>.MyEstimator.fitN)r[   r\   r]   r^   r<   rF   rF   rF   rG   ÚMyEstimator™  s   r  r+   )r6   r7   r(   )r…   ÚrandomZRandomStateZrandnZaranger!   r   r<   r$   rn   r   râ   )r>   rV   rW   r  r§   rF   rF   rG   Ú#test_bagging_get_estimators_indices�  s    
r  zbagging, expected_allow_nanr+   r3   c                 C   s   |   ¡ jj|ksJ ‚dS )z*Check that bagging inherits allow_nan tag.N)Z__sklearn_tags__Z
input_tagsÚ	allow_nan)rà   Zexpected_allow_nanrF   rF   rG   Útest_bagging_allow_nan_tag¥  s    r  ÚmodelrÏ   )r6   r7   c                 C   s@   t jdd��  |  tjtj¡ W d  ƒ n1 s20    Y  dS )zAMake sure that metadata routing works with non-default estimator.T)Zenable_metadata_routingN)ÚsklearnZconfig_contextr<   r8   r9   r:   ©r  rF   rF   rG   Ú"test_bagging_with_metadata_routing³  s    r	  c                 C   s   |   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<   r8   r9   r:   r  rF   rF   rG   Ú-test_bagging_without_support_metadata_routingÄ  s    r
  )rÌ   )lr^   Ú	itertoolsr   r   r‚   Únumpyr…   r¤   r  Zsklearn.baser   Zsklearn.datasetsr   r   r   Zsklearn.dummyr   r	   Zsklearn.ensembler
   r   r   r   r   r   r   r   Zsklearn.feature_selectionr   Zsklearn.linear_modelr   r   Zsklearn.model_selectionr   r   r   Zsklearn.neighborsr   r   Zsklearn.pipeliner   Zsklearn.preprocessingr   r   Zsklearn.random_projectionr   Zsklearn.svmr   r   Zsklearn.treer    r!   Zsklearn.utilsr"   Zsklearn.utils._testingr#   r$   Zsklearn.utils.fixesr%   r&   r>   r8   Zpermutationr:   rÇ   Úpermr9   rz   rH   ÚmarkZparametrizerx   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ç   rè   rí   rð   rû   rý   rþ   r  r  r	  r
  rF   rF   rF   rG   Ú<module>   sè   (
!üü

òîþ
)
8	*#%$),	

() 
üþ	

ÿ
ÿüþ
þûþ
