U
    ½mœd¶z  ã                   @   sX  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ƒZ5e*ƒ Z6e5 7e6j8j9¡Z:e6j;e: e6_;e6j8e: e6_8e)ƒ Z<e5 7e<j8j9¡Z:e<j;e: e<_;e<j8e: e<_8d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d#d$d%d&gƒ¡d'd(„ ƒZ@d)d*„ ZAd+d,„ ZBG d-d.„ d.eƒZCd/d0„ ZDd1d2„ ZEd3d4„ ZFd5d6„ ZGd7d8„ ZHd9d:„ ZId;d<„ ZJd=d>„ ZKd?d@„ ZLdAdB„ ZMdCdD„ ZNdEdF„ ZOG dGdH„ dHeƒZPdIdJ„ ZQdtdLdM„ZRdNdO„ ZSdPdQ„ ZTdRdS„ ZUdTdU„ ZVdVdW„ ZWdXdY„ ZXdZd[„ ZYd\d]„ ZZd^d_„ Z[d`da„ Z\dbdc„ Z]ddde„ Z^dfdg„ Z_dhdi„ Z`djdk„ Zaej> ?dleefeefg¡dmdn„ ƒZbej> ?doeeg¡dpdq„ ƒZcdrds„ ZddS )uzE
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            	      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Úparamsr/   © r?   ú\/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/sklearn/ensemble/tests/test_bagging.pyÚtest_classification4   sB      ÿüÿ	ú
ýü ûûrA   zsparse_format, params, methodr#   r-   Tr'   r$   r&   F©r)   r*   r+   ©r(   r*   r+   r6   Ú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æt‚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©Úsuperr5   ÚtypeÚ
data_type_©ÚselfÚXÚy©Ú	__class__r?   r@   r5   r   s    
z1test_sparse_classification.<locals>.CustomSVC.fit©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r5   Ú__classcell__r?   r?   rQ   r@   Ú	CustomSVCo   s   rY   r   r!   ZlinearÚovr)ZkernelÚdecision_function_shaper%   ©r/   r"   c                 S   s   g | ]
}|j ‘qS r?   ©rL   ©Ú.0Úir?   r?   r@   Ú
<listcomp>�   s     z.test_sparse_classification.<locals>.<listcomp>c                    s   g | ]}|ˆ k‘qS r?   r?   ©r_   Út©Zsparse_typer?   r@   ra   ’   s     )r   r   r   r   r1   r2   r3   r
   r5   Úgetattrr   rK   Úestimators_ÚallÚAssertionError)Úsparse_formatr>   ÚmethodrY   r7   r8   r9   r:   r;   ÚX_train_sparseÚX_test_sparseÚsparse_classifierÚsparse_resultsZdense_classifierÚdense_resultsÚtypesr?   rd   r@   Útest_sparse_classificationU   sB      ÿ
þý ü
þý ü
rq   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'   r\   )r   r   Údiabetesr2   r3   r	   r   r   r   r   r   r5   r6   )r7   r8   r9   r:   r;   r<   r/   r>   r?   r?   r@   Útest_regression•   s4      ÿüÿ
û ÿþrt   c                     s2  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}ttfD ]²}||ƒ}||ƒ}	|D ]˜}
tf |ƒ ddœ|
—Ž 	||¡}| 
|	¡}tf |ƒ ddœ|
—Ž 	||¡ 
|¡}t|ƒ‰ dd„ |jD ƒ}t||ƒ t‡ fdd„|D ƒƒ�s t‚t||ƒ q’qzd S )Nr   rr   r!   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )z)test_sparse_regression.<locals>.CustomSVRrG   c                    s   t ƒ  ||¡ t|ƒ| _| S rH   rI   rM   rQ   r?   r@   r5   »   s    
z-test_sparse_regression.<locals>.CustomSVR.fitrS   r?   r?   rQ   r@   Ú	CustomSVR¸   s   ru   r#   r-   Tr'   r$   r&   FrB   rC   r%   r\   c                 S   s   g | ]
}|j ‘qS r?   r]   r^   r?   r?   r@   ra   ä   s     z*test_sparse_regression.<locals>.<listcomp>c                    s   g | ]}|ˆ k‘qS r?   r?   rb   rd   r?   r@   ra   ç   s     )r   r   rs   r2   r3   r   r   r    r   r5   r6   rK   rf   r   rg   rh   )r7   r8   r9   r:   r;   ru   Zparameter_setsri   rk   rl   r>   rm   rn   ro   rp   r?   rd   r@   Útest_sparse_regression±   s\      ÿ
üü

ò ÿÿ þ
 ÿþÿ
rv   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_rM   r?   r?   r@   r5   ì   s    zDummySizeEstimator.fitc                 C   s   t  |jd ¡S rx   )ÚnpÚonesry   ©rN   rO   r?   r?   r@   r6   ð   s    zDummySizeEstimator.predictN©rT   rU   rV   r5   r6   r?   r?   r?   r@   rw   ë   s   rw   c                  C   sþ   t dƒ} ttjtj| d�\}}}}tƒ  ||¡}ttƒ dd| d� ||¡}| ||¡| ||¡ksft	‚ttƒ dd| d� ||¡}| ||¡| ||¡ksœt	‚tt
ƒ dd� ||¡}g }|jD ]$}|j|jd ksÔt	‚| |j¡ q¼tt|ƒƒt|ƒksút	‚d S )Nr   r!   r$   F)r/   r(   r*   r"   T)r/   r*   )r   r   rs   r2   r3   r   r5   r   Úscorerh   rw   rf   rz   ry   Úappendr}   ÚlenÚset)r7   r8   r9   r:   r;   r/   ÚensembleZtraining_hashr?   r?   r@   Útest_bootstrap_samplesô   sH      ÿü ûü û ÿ
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sBt‚qBttƒ dd| d� ||¡}|jD ]$}tjj	d t
 |¡j	d ksˆt‚qˆd S )Nr   r!   r$   F)r/   r)   r+   r"   r%   T)r   r   rs   r2   r3   r   r   r5   Úestimators_features_ry   r~   Úuniquerh   )r7   r8   r9   r:   r;   r†   Úfeaturesr?   r?   r@   Útest_bootstrap_features  s8      ÿü û
"ü û
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 5 Q R X d S )
Nr   r!   Úignore)ÚdivideÚinvalidr\   r%   )Zaxisé   )r/   r"   r(   )r   r   r1   r2   r3   r~   Zerrstater
   r   r5   r   ÚsumrD   r   r„   ÚexprE   r   ©r7   r8   r9   r:   r;   r†   r?   r?   r@   Útest_probability:  sL      ÿ ÿ þ ÿ ÿ  ÿ þ ÿ ÿ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 snt‚d}tjt|d��$ t|d	dd| d�}| ||¡ W 5 Q R X q.d S )
Nr   r!   éd   T©r/   r0   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   r1   r2   r3   r   r   r
   r5   r‚   ÚabsÚ
oob_score_rh   ÚpytestÚwarnsÚUserWarning)	r7   r8   r9   r:   r;   r/   ÚclfÚ
test_scoreÚwarn_msgr?   r?   r@   Útest_oob_score_classification]  s<      ÿû úÿûr£   c            	   	   C   s¢   t dƒ} ttjtj| d�\}}}}ttƒ ddd| d� ||¡}| ||¡}t	||j
 ƒdk s`t‚d}tjt|d��& ttƒ d	dd| d�}| ||¡ W 5 Q R X d S )
Nr   r!   rr   Tr•   r—   r˜   r™   r%   )r   r   rs   r2   r3   r   r   r5   r‚   r›   rœ   rh   r�   rž   rŸ   )	r7   r8   r9   r:   r;   r    r¡   r¢   Zregrr?   r?   r@   Útest_oob_score_regression‚  s:      ÿû úÿû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)r/   r0   r*   r+   r"   )
r   r   rs   r2   r3   r   r   r5   r   r6   )r7   r8   r9   r:   r;   Zclf1Zclf2r?   r?   r@   Útest_single_estimator¦  s$      ÿû úr¥   c                  C   s2   t jt j } }tƒ }tt|ƒ | |¡dƒr.t‚d S )NrF   )r1   r2   r3   r   Úhasattrr
   r5   rh   )rO   rP   Úbaser?   r?   r@   Ú
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«   rZ   )r[   )r   r1   r2   r3   r
   r   r5   rD   Ú
set_paramsr   r   rF   )r8   r9   r:   r;   r†   Úy1Úy2Úy3Z
decisions1Z
decisions2Z
decisions3r?   r?   r@   Útest_parallel_classificationÁ  sb      ÿ  ÿ þ


  ÿ þ

  ÿ þ


  ÿ þ
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¬   r-   )r   r   rs   r2   r3   r   r   r5   r­   r6   r   )	r7   r8   r9   r:   r;   r†   r®   r¯   r°   r?   r?   r@   Ú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%   r-   )r%   r-   )r0   Zestimator__CZroc_auc)Zscoring)r1   r2   r3   r   r
   r   r5   )rO   rP   Ú
parametersr?   r?   r@   Útest_gridsearch  s    
r´   c                  C   s0  t dƒ} ttjtj| d�\}}}}td ddd� ||¡}t|jt	ƒsHt
‚tt	ƒ ddd� ||¡}t|jt	ƒspt
‚ttƒ ddd� ||¡}t|jtƒs˜t
‚ttjtj| d�\}}}}td ddd� ||¡}t|jtƒsØt
‚ttƒ ddd� ||¡}t|jtƒ�st
‚ttƒ ddd� ||¡}t|jtƒ�s,t
‚d S )Nr   r!   r©   rª   )r   r   r1   r2   r3   r
   r5   Ú
isinstanceZ
estimator_r   rh   r   rs   r   r   r   r’   r?   r?   r@   Útest_estimator  sH      ÿ  ÿ þ ÿ  ÿ ÿr¶   c                  C   sL   t ttdd�tƒ ƒdd�} |  tjtj¡ t| d j	d d j
tƒsHt‚d S )Nr%   )Úkr-   )r)   r   éÿÿÿÿ)r
   r   r   r   r5   r1   r2   r3   rµ   Ústepsr"   Úintrh   )r/   r?   r?   r@   Útest_bagging_with_pipeline<  s     ÿr»   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚDummyZeroEstimatorc                 C   s   t  |¡| _| S rH   )r~   r‰   Úclasses_rM   r?   r?   r@   r5   E  s    zDummyZeroEstimator.fitc                 C   s   | j tj|jd td� S )Nr   )Údtype)r½   r~   Zzerosry   rº   r€   r?   r?   r@   r6   I  s    zDummyZeroEstimator.predictNr�   r?   r?   r?   r@   r¼   D  s   r¼   c               	   C   sj   t tƒ ƒ} tdƒ}|  tjtj¡ tj¡ t 	t
¡�, | jtjtj|jdtjjd d�d� W 5 Q R X d S )Nr   é
   )Úsize)Zsample_weight)r
   r¼   r   r5   r1   r2   r3   r6   r�   ÚraisesÚ
ValueErrorÚrandintry   )r/   r7   r?   r?   r@   Ú1test_bagging_sample_weight_unsupported_but_passedM  s    
ýrÄ   é*   c                 C   s¤   t ddd�\}}d }dD ]D}|d kr4t|| dd�}n|j|d� | ||¡ t|ƒ|kst‚qtd| d	d�}| ||¡ td
d„ |D ƒƒtdd„ |D ƒƒks t‚d S )Nr,   r%   ©Z	n_samplesr"   )r�   r¿   T)r0   r"   Ú
warm_start©r0   r¿   Fc                 S   s   g | ]
}|j ‘qS r?   r!   ©r_   Útreer?   r?   r@   ra   o  s     z#test_warm_start.<locals>.<listcomp>c                 S   s   g | ]
}|j ‘qS r?   r!   rÉ   r?   r?   r@   ra   p  s     )r   r
   r­   r5   r„   rh   r…   )r"   rO   rP   Úclf_wsr0   Z	clf_no_wsr?   r?   r@   Útest_warm_startZ  s*      ÿ  ÿÿrÌ   c               	   C   sZ   t ddd�\} }tddd�}| | |¡ |jdd� t t¡� | | |¡ W 5 Q R X d S )	Nr,   r%   rÆ   r�   T)r0   rÇ   r&   rÈ   )r   r
   r5   r­   r�   rÁ   rÂ   ©rO   rP   r    r?   r?   r@   Ú$test_warm_start_smaller_n_estimatorst  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 5 Q R X t|| |¡ƒ d S )Nr,   r%   rÆ   é+   r!   r�   TéS   ©r0   rÇ   r"   r$   z;Warm-start fitting without increasing n_estimators does notr™   )	r   r   r
   r5   r6   r�   rž   rŸ   r   )	rO   rP   r8   r9   r:   r;   r    Zy_predr¢   r?   r?   r@   Ú"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 )Nr,   r%   rÆ   rÏ   r!   r�   TiE  rÑ   r¿   rÈ   F)r   r   r
   r5   r­   r6   r   )
rO   rP   r8   r9   r:   r;   rË   r®   r    r¯   r?   r?   r@   Útest_warm_start_equivalence�  s    

rÓ   c               	   C   sD   t ddd�\} }tdddd�}t t¡� | | |¡ W 5 Q R X d S )Nr,   r%   rÆ   r�   T)r0   rÇ   r–   )r   r
   r�   rÁ   rÂ   r5   rÍ   r?   r?   r@   Ú$test_warm_start_with_oob_score_fails£  s    rÔ   c               	   C   sh   t ddd�\} }tddd�}| | |¡ |jdddd	� | | |¡ t t¡� t|d
ƒ W 5 Q R X d S )Nr”   r%   rÆ   r�   T)r0   r–   Fr¿   )rÇ   r–   r0   rœ   )r   r
   r5   r­   r�   rÁ   ÚAttributeErrorre   rÍ   r?   r?   r@   Ú$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sDt‚d S )NéÈ   r%   rÆ   r#   T)r(   r)   r–   r"   )r   r
   r   r5   rœ   rh   ©rO   rP   Úbaggingr?   r?   r@   Ú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sVt‚t|d ƒt| ƒd ksrt‚|d j	j
d	ks†t‚d}|| }|| }|| }	| | d d …|f }
|| }|	j}|	 |
|¡ |	j}t||ƒ d S )
Nr×   r%   rÆ   r#   F)r(   r)   r"   r*   r   r-   r`   )r   r
   r   r5   Úestimators_samples_rˆ   rf   r„   rh   r¾   ÚkindÚcoef_r   )rO   rP   rÙ   Zestimators_samplesZestimators_featuresr=   Zestimator_indexZestimator_samplesZestimator_featuresr/   r8   r:   Z
orig_coefsZ	new_coefsr?   r?   r@   Ú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 )Nr-   )Zn_componentsr#   r   )r/   r(   r"   r¸   r%   )r   r2   r3   r   r   r   r
   r5   rf   r¹   rÝ   ÚcopyrÛ   rˆ   r   )r1   rO   rP   Zbase_pipeliner    Zpipeline_estimator_coefr/   Zestimator_sampleZestimator_featurer8   r:   r?   r?   r@   Ú%test_estimators_samples_deterministicî  s      ÿ


rà   c                  C   sH   d} t d|  dd�\}}ttƒ | ddd�}| ||¡ |j| ksDt‚d S )Nr”   r-   r%   rÆ   r#   )r(   r)   r"   )r   r
   r   r5   Z_max_samplesrh   )r(   rO   rP   rÙ   r?   r?   r@   Útest_max_samples_consistency	  s    ürá   c                  C   sœ   d} dgdgdggd }dddgd }dddgd }dddgd }t d	| d
� ||¡j}t d	| d
� ||¡j}t d	| d
� ||¡j}||g||gks˜t‚d S )Nr�   r¸   r   r%   ÚAÚBÚCr-   T)r–   r"   )r
   r5   rœ   rh   )r"   rO   ZY1ZY2ZY3Úx1Zx2Zx3r?   r?   r@   Ú!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)rO   r?   r?   r@   Úreplace2  s    ré   c               
   C   s6  t  dddgdd dgdt jdgdt jdgdt jdgg¡} t  dddddg¡t  dddgdddgdddgdddgdddgg¡g}|D ]®}tƒ }tttƒ|ƒ}| 	| |¡ 
| ¡ t|ƒ}| 	| |¡ 
| ¡}|j|jksÖt‚tƒ }t|ƒ}t t¡� | 	| |¡ W 5 Q R X t|ƒ}t t¡� | 	| |¡ W 5 Q R X q‚d S )Nr%   r©   r�   r-   é   é	   é   )r~   ÚarrayÚnanÚinfÚNINFr   r   r   ré   r5   r6   r   ry   rh   r�   rÁ   rÂ   )rO   Zy_valuesrP   Z	regressorÚpipelineZbagging_regressorÚy_hatr?   r?   r@   Ú*test_bagging_regressor_with_missing_inputs8  s@    


ûÿ
ûÿþró   c               	   C   s  t  dddgdd dgdt jdgdt jdgdt jdgg¡} t  dddddg¡}tƒ }tttƒ|ƒ}| 	| |¡ 
| ¡ t|ƒ}| 	| |¡ | 
| ¡}|j|jks t‚| | ¡ | | ¡ tƒ }t|ƒ}t t¡� | 	| |¡ W 5 Q R X t|ƒ}t t¡� | 	| |¡ W 5 Q R X d S )Nr%   r©   r�   r-   rê   )r~   rí   rî   rï   rð   r   r   r   ré   r5   r6   r
   ry   rh   rE   rD   r�   rÁ   rÂ   )rO   rP   Ú
classifierrñ   Zbagging_classifierrò   r?   r?   r@   Ú+test_bagging_classifier_with_missing_inputsa  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%   r-   r©   r&   r   g333333Ó?)r)   r"   )r~   rí   r
   r   r5   rØ   r?   r?   r@   Ú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 rH   )Ú_sample_indicesrM   r?   r?   r@   r5   —  s    z<test_bagging_get_estimators_indices.<locals>.MyEstimator.fitN)rT   rU   rV   rW   r5   r?   r?   r?   r@   ÚMyEstimator”  s   rù   r%   )r/   r0   r"   )r~   ÚrandomZRandomStateZrandnZaranger   r   r5   r   rf   rø   rÛ   )r7   rO   rP   rù   r    r?   r?   r@   Ú#test_bagging_get_estimators_indices‹  s    
rû   zBagging, Estimatorc              	   C   s`   t  ddgddgg¡}t  ddg¡}| |ƒ dd�}d}tjt|d	�� | ||¡ W 5 Q R X d S )
Nr%   r-   r©   r&   r   r¿   )Úbase_estimatorr0   úV`base_estimator` was renamed to `estimator` in version 1.2 and will be removed in 1.4.r™   )r~   rí   r�   rž   ÚFutureWarningr5   )ÚBaggingZ	EstimatorrO   rP   Úmodelr¢   r?   r?   r@   Ú'test_base_estimator_argument_deprecated¡  s    ÿr  rÿ   c              	   C   s^   t  ddgddgg¡}t  ddg¡}| ƒ }| ||¡ d}tjt|d�� |j W 5 Q R X d S )Nr%   r-   r©   r&   r   zoAttribute `base_estimator_` was deprecated in version 1.2 and will be removed in 1.4. Use `estimator_` instead.r™   )r~   rí   r5   r�   rž   rþ   Zbase_estimator_)rÿ   rO   rP   r   r¢   r?   r?   r@   Ú'test_base_estimator_property_deprecated¶  s    ÿr  c               	   C   sp   t ƒ } | j| j }}ttƒ d�}t|dƒs.t‚d}tjt	|d�� | 
||¡ |¡}W 5 Q R X |jdkslt‚dS )zSCheck that `BaggingClassifier` delegate to classifier with
    `decision_function`.)rü   rF   rý   r™   )é–   r©   N)r   r2   r3   r
   r   r¦   rh   r�   rž   rþ   r5   rF   ry   )r1   rO   rP   r    r¢   Z
y_decisionr?   r?   r@   Ú4test_deprecated_base_estimator_has_decision_functionÉ  s    ÿr  )rÅ   )erW   Ú	itertoolsr   Únumpyr~   r{   r�   Zsklearn.baser   Zsklearn.utils._testingr   r   Zsklearn.dummyr   r   Zsklearn.model_selectionr   r	   Zsklearn.ensembler
   r   Zsklearn.linear_modelr   r   Zsklearn.neighborsr   r   Zsklearn.treer   r   Zsklearn.svmr   r   Zsklearn.random_projectionr   Zsklearn.pipeliner   Zsklearn.feature_selectionr   r   Zsklearn.datasetsr   r   r   Zsklearn.utilsr   Zsklearn.preprocessingr   r   r   Zscipy.sparser   r    r7   r1   Zpermutationr3   rÀ   Úpermr2   rs   rA   ÚmarkZparametrizerq   rt   rv   rw   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?   r@   Ú<module>   sÈ   !üü

ò
îþ
):	*#%$),	

() 
þþ
þ
