
    t]eT                         d Z ddlZddlZddlZddlmZ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 dd	lmZ dd
lmZ ddlmZ ddlmZ  eej                  Z e            ZdZ ej         ddgddgddgddgddgddgddgddgddgdd gg
          Z! ej         g d!          Z"ej#        $                    d"d#d$g          ej#        $                    d% e	d&'           e	d#'          g          d(                         Z%d) Z&d* Z'd8d,Z(d- Z)d. Z*d/ Z+d0 Z,d1 Z-d2 Z.ej#        /                    e ed3          k     d45          d6             Z0d7 Z1dS )9zTest the module easy ensemble.    N)	load_irismake_hastie_10_2)AdaBoostClassifier)SelectKBest)GridSearchCVtrain_test_split)assert_allcloseassert_array_equal)parse_version)make_imbalance)EasyEnsembleClassifier)make_pipeline)RandomUnderSamplerguL?gȇ,?gض?gո/N?g5 ?gR(G?g5?gz?g4?gȻ*?g9D<?gą L?g*W ge|?gF6>οgVe\?gg6?g!Q쑻gFϩ;?)
      r   r   r   r   r   r   r   r   n_estimators
      	estimator   r   c                 N   t          t          j        t          j        ddddd          \  }}t	          ||d          \  }}}}t          | |dt          	          }|                    ||                              ||           t          |j
                  | k    sJ |j
        D ]'}	t          |	j        d
                   |j        k    sJ (|                    |           |                    |           |                    |           |                    |           d S )Nr      2   r   r   r   r   sampling_strategyrandom_stater   )r   r   n_jobsr   
classifier)r   irisdatatargetr   r   RND_SEEDfitscorelenestimators_named_stepsr   predictpredict_probapredict_log_probadecision_function)
r   r   XyX_trainX_testy_trainy_testeecests
             Jlib/python3.11/site-packages/imblearn/ensemble/tests/test_easy_ensemble.pytest_easy_ensemble_classifierr9   +   sC    	 RB//	  DAq (811'M'M'M$GVWf
 !	  C GGGW##FF333s<//// L L3?<011Y5KKKKKKKKf&!!!&!!!!!    c                     t          t          j        t          j        ddddd          \  } }t	          | |d          \  }}}}t          dd d	d
                              ||          }t          |j        j	        d	         d         t                    sJ t          dt                      d	d
                              ||          }t          |j        j	        d	         d         t                    sJ d S )Nr   r   r   r   r   r   r   r   r    )r!   r   r   )r   r#   r$   r%   r   r   r'   
isinstance
estimator_stepsr   )r0   r1   r2   r3   r4   r5   ensembles          r8   test_estimatorr@   K   s   	 RB//	  DAq (811'M'M'M$GVWf%abqIIIMM H h)/3A68JKKKKK%	  	c'7  h)/3A68JKKKKKKKr:   c                  &   t          t          j        t          j        ddddd          \  } }t	          dt          t          d	          t                                
          }|                    | |          	                    |            d S )Nr   r   r   r   r   r   r   r   )k)r   r   )
r   r#   r$   r%   r   r   r   r   r'   r,   r0   r1   r   s      r8   test_bagging_with_pipelinerD   b   s    	 RB//	  DAq 'a 0 0 02D2F2FGG  I MM!Q"""""r:   *   c                 p   t          dd          \  }}d }dD ]X}|t          || d          }n|                    |           |                    ||           t	          |          |k    sJ Yt          d| d	          }|                    ||           d
 |D             d |D             k    sJ d S )Nr   r   	n_samplesr   )r   r   T)r   r   
warm_startr   r   Fc                 >    h | ]}|j         d          d         j        S r    r   r>   r   .0pipes     r8   	<setcomp>z"test_warm_start.<locals>.<setcomp>   s&    >>>tDJrN1*>>>r:   c                 >    h | ]}|j         d          d         j        S rK   rL   rM   s     r8   rP   z"test_warm_start.<locals>.<setcomp>   s9     C C C+/
2q&C C Cr:   )r   r   
set_paramsr'   r)   )r   r0   r1   clf_wsr   	clf_no_wss         r8   test_warm_startrU   p   s    bq999DAqF 
+ 
+>+))  FF <888

1a6{{l*****&lu  I MM!Q>>v>>> C C3<C C C      r:   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   rG   r   T)r   rI      r   )r   r   r'   rR   pytestraises
ValueError)r0   r1   clfs      r8   $test_warm_start_smaller_n_estimatorsr\      s    bq999DAq
 aD
A
A
AC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   rG   +   r   r   TS   r   rI   r   g      ?z2Warm-start fitting without increasing n_estimatorsmatch)	r   r   r   r'   r,   rX   warnsUserWarningr
   )	r0   r1   r2   r3   r4   r5   r[   y_predwarn_msgs	            r8   "test_warm_start_equal_n_estimatorsrg      s   bq999DAq'712'N'N'N$GVWf
 aDr
R
R
RCGGGW[[  FsNGCH	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   rG   r^   r   r   TiE  r`   r   r   F)r   r   r   r'   rR   r,   r	   )
r0   r1   r2   r3   r4   r5   rS   y1r[   y2s
             r8   test_warm_start_equivalencerk      s     bq999DAq'712'N'N'N$GVWf#tRVWWWF
JJw   
2&&&
JJw   			B
 bUQU
V
V
VCGGGW	V		BBr:   c                     t          t          j        t          j        ddddd          \  } }t	          | |d          \  }}}}t          dd	                              ||          }t          t          d          t          d                                        ||          }t          |                    |          |                    |                     d S )
Nr   r   r   r   r   r   r   r   )r   r   )r   r#   r$   r%   r   r   r'   r   r   r   r
   r,   )r0   r1   r2   r3   r4   r5   clf1clf2s           r8   .test_easy_ensemble_classifier_single_estimatorro      s    	 RB//	  DAq (811'M'M'M$GVWf!qqAAAEEgwWWD***,>A,N,N,N 	c'7 	 t||F++T\\&-A-ABBBBBr:   c                      t          t          j        t          j        ddddd          \  } }ddgd	d
gd}t	          t          t                                |d          }|                    | |           d S )Nr   r   r   r   r   r   r   r      rW   )r   estimator__n_estimators)r   r   )cv)r   r#   r$   r%   r   r   r   r'   )r0   r1   
parametersgrid_searchs       r8   )test_easy_ensemble_classifier_grid_searchrv      s    	 RB//	  DAq A$%q6 J );)=)=>>>  K
 OOAqr:   c                      t          d          \  } }t                                          | |          }t          j        t
          d          5  |j         ddd           dS # 1 swxY w Y   dS )zACheck that we raise a FutureWarning when accessing `n_features_`.T
return_X_yz`n_features_` was deprecatedra   N)r   r   r'   rX   rc   FutureWarningn_features_rC   s      r8   (test_easy_ensemble_classifier_n_featuresr|      s    %%%DAq&((,,Q22I	m+I	J	J	J                      A&&A*-A*z1.2zwarns for scikit-learn>=1.2)reasonc                      t          d          \  } }t                                          | |          }t          j        t
          d          5  |j         ddd           dS # 1 swxY w Y   dS )zECheck that we raise a FutureWarning when accessing `base_estimator_`.Trx   z `base_estimator_` was deprecatedra   N)r   r   r'   rX   rc   rz   base_estimator_rC   s      r8   ,test_easy_ensemble_classifier_base_estimatorr      s    
 %%%DAq&((,,Q22I	m+M	N	N	N " "!!" " " " " " " " " " " " " " " " " "r}   c                     t          d          \  } }d}t          j        t          |          5  t	          t                      t                                                    | |           ddd           dS # 1 swxY w Y   dS )zXCheck that we raise a ValueError when setting both `estimator` and
    `base_estimator`.Trx   zEBoth `estimator` and `base_estimator` were set. Only set `estimator`.ra   )r   base_estimatorN)r   rX   rY   rZ   r   r   r'   )r0   r1   err_msgs      r8   Ctest_easy_ensemble_classifier_set_both_estimator_and_base_estimatorr      s     %%%DAqUG	z	1	1	1  (**;M;O;O	
 	
 	

#a)))                 s   >A<<B B )rE   )2__doc__numpynprX   sklearnsklearn.datasetsr   r   sklearn.ensembler   sklearn.feature_selectionr   sklearn.model_selectionr   r   sklearn.utils._testingr	   r
   sklearn.utils.fixesr   imblearn.datasetsr   imblearn.ensembler   imblearn.pipeliner   imblearn.under_samplingr   __version__sklearn_versionr#   r&   arrayr0   Ymarkparametrizer9   r@   rD   rU   r\   rg   rk   ro   rv   r|   skipifr   r    r:   r8   <module>r      s   $ $
       8 8 8 8 8 8 8 8 / / / / / / 1 1 1 1 1 1 B B B B B B B B F F F F F F F F - - - - - - , , , , , , 4 4 4 4 4 4 + + + + + + 6 6 6 6 6 6- 344y{{ BH	J	Z 	Z 	Z 	Z 	Y	j!	j!	j!	j!  BH+++,, "b22Q'''););)L)L)LM " "	  32
"6L L L.# # #   8  4 4 4$  &C C C"  (   mmE***3P   " " "    r:   