
    {Kg;(                     ~   d Z ddlZddlm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 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" ddl#m$Z$ ddl%m&Z& ddl'm(Z(m)Z) ddl*m+Z+  G d d      Z, e,dd        e,dd dg       e,dd dg       e,deddg       e,d eddg       e,d!eg d"       e,d#d$ g d%      gZ-d& Z.d' Z/g d(Z0 e/       D  cg c]  } | jb                  jd                  e0vr|  c} Z3d) Z4ejj                  jm                  d*e3e4+      d,        Z7yc c} w )-zCommon tests for metaestimators    N)	signature)BaseEstimatoris_regressor)make_classification)BaggingClassifier)NotFittedError)TfidfVectorizer)RFERFECV)LogisticRegressionRidge)GridSearchCVRandomizedSearchCV)Pipelinemake_pipeline)MaxAbsScalerStandardScalerSelfTrainingClassifier)all_estimators)set_random_state)_enforce_estimator_tags_X_enforce_estimator_tags_ycheck_is_fittedc                   &    e Zd Zd ed      fdZy)DelegatorData r   )random_statec                 <    || _         || _        || _        || _        y N)name	constructfit_argsskip_methods)selfr"   r#   r%   r$   s        e/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/sklearn/tests/test_metaestimators.py__init__zDelegatorData.__init__   s!     	" (    N)__name__
__module____qualname__r   r(   r   r)   r'   r   r      s    
 $!4
)r)   r   r   c                     t        d| fg      S )Nest)r   r.   s    r'   <lambda>r0   ,   s    (UCL>*Br)   r   c                 $    t        | ddgid      S )Nparam      )
param_gridcv)r   r/   s    r'   r0   r0   /   s    L'A3AFr)   score)r%   r   c                 &    t        | ddgidd      S )Nr2   r3   r4      )param_distributionsr6   n_iter)r   r/   s    r'   r0   r0   4   s    &gs^!
r)   r
   	transforminverse_transformr   r   )r<   r=   r7   predict_probapredict_log_probapredictr   c                     t        |       S r!   r   r/   s    r'   r0   r0   I   s
    *3/r)   )r<   r=   r>   c                     d  G fddt               } | j                  j                         D cg c]&  }|j                  d      s|j                  d      s|( }}|j	                          t
        D ]  } |        }|j                  |      }|D ]  }||j                  v rt        ||      sJ t        ||      sJ |j                  d|d       |dk(  rPt        j                  t              5   t        ||      |j                  d	   |j                  d
          d d d        t        j                  t              5   t        ||      |j                  d	          d d d          |j                  |j                    |D ]c  }||j                  v r|dk(  r. t        ||      |j                  d	   |j                  d
          E t        ||      |j                  d	          e |D ]\  }||j                  v r | |      }|j                  |      }t        ||      rJ t        ||      sGJ |j                  d|d         y c c}w # 1 sw Y   xY w# 1 sw Y   xY w)Nc                 $     t          fd       }|S )Nc                     | j                   j                  k(  rt        d| j                   z        t        j                  |       S )Nz%r is hidden)hidden_methodr*   AttributeError	functoolspartial)objmethods    r'   wrapperz=test_metaestimator_delegation.<locals>.hides.<locals>.wrapperR   s>      FOO3$^c6G6G%GHH$$VS11r)   )property)rJ   rK   s   ` r'   hidesz,test_metaestimator_delegation.<locals>.hidesQ   s    		2 
	2
 r)   c                       e Zd ZddZddZd ZW  d        ZW  d        ZW  d        ZW  d        Z	W  d	        Z
W  d
        ZW  d        Zy)3test_metaestimator_delegation.<locals>.SubEstimatorNc                      || _         || _        y r!   )r2   rE   )r&   r2   rE   s      r'   r(   z<test_metaestimator_delegation.<locals>.SubEstimator.__init__[   s    DJ!.Dr)   c                 `    t        j                  |j                  d         | _        g | _        y)Nr9   T)nparangeshapecoef_classes_r&   Xyargskwargss        r'   fitz7test_metaestimator_delegation.<locals>.SubEstimator.fit_   s$    1771:.DJDMr)   c                     t        |        y r!   r   )r&   s    r'   
_check_fitz>test_metaestimator_delegation.<locals>.SubEstimator._check_fitd   s
    D!r)   c                 &    | j                          |S r!   r^   r&   rX   rZ   r[   s       r'   r=   zEtest_metaestimator_delegation.<locals>.SubEstimator.inverse_transformg       OOHr)   c                 &    | j                          |S r!   r`   ra   s       r'   r<   z=test_metaestimator_delegation.<locals>.SubEstimator.transforml   rb   r)   c                 f    | j                          t        j                  |j                  d         S Nr   r^   rR   onesrT   ra   s       r'   r@   z;test_metaestimator_delegation.<locals>.SubEstimator.predictq   #    OO771771:&&r)   c                 f    | j                          t        j                  |j                  d         S re   rf   ra   s       r'   r>   zAtest_metaestimator_delegation.<locals>.SubEstimator.predict_probav   rh   r)   c                 f    | j                          t        j                  |j                  d         S re   rf   ra   s       r'   r?   zEtest_metaestimator_delegation.<locals>.SubEstimator.predict_log_proba{   rh   r)   c                 f    | j                          t        j                  |j                  d         S re   rf   ra   s       r'   decision_functionzEtest_metaestimator_delegation.<locals>.SubEstimator.decision_function   rh   r)   c                 $    | j                          y)N      ?r`   rW   s        r'   r7   z9test_metaestimator_delegation.<locals>.SubEstimator.score   s    OOr)   )r9   Nr!   )r*   r+   r,   r(   r\   r^   r=   r<   r@   r>   r?   rl   r7   )rM   s   r'   SubEstimatorrO   Z   s    	/	
	" 
	 
	 
	 
	 
	' 
	' 
	' 
	' 
	' 
	' 
	' 
	' 
	 
	r)   ro   _r\   z does not have method z when its delegate doesr7   r   r9   )rE   z has method z when its delegate does not)r   __dict__keys
startswithsortDELEGATING_METAESTIMATORSr#   r%   hasattrr"   pytestraisesr   getattrr$   r\   )ro   kmethodsdelegator_datadelegate	delegatorrJ   rM   s          @r'   test_metaestimator_delegationr   O   ss   .} .d &&++--A||C e)< 	
-  
 LLN33>",,X6	F4448V,,,6  ##   ]]>2.GIv.&//2N4K4KA4N 32
 ]]>2.GIv.~/F/Fq/IJ 32# ( 		~../F444 *	6*"++A.0G0G0J +	6*>+B+B1+EF  F444#&9H&00:Ix0006  ##  G 4, 32
 32s   +I4.I I&I#&I0c            	   #   `  K   t        t                     D ]  \  } }t        t        |      j                        }d|v sd|v sd|v rzt        |      r#t        t               t                     }dddgi}n"t        t               t                     }dddgi}d|v sd	|v rd
|v rd
dini } |||fi |  ||       d|v rIdt        t               t                     fdt        t               t        d            fg} ||       d|v rt        |      rAdt        t               t        d            fdt        t               t        d            fg}n@dt        t               t        d            fdt        t               t        d            fg} ||        yw)zGenerate instances of meta-estimators fed with a pipeline

    Are considered meta-estimators all estimators accepting one of "estimator",
    "base_estimator" or "estimators".
    	estimatorbase_estimator	regressorridge__alphag?rn   logisticregression__Cr5   r:   r;   r4   transformer_listtrans1trans2F)	with_mean
estimatorsest1)alphaest2r9   )CN)sortedr   setr   
parametersr   r   r	   r   r   r   r   )rp   	Estimatorsigr   r5   extra_paramsr   s          r'   0_generate_meta_estimator_instances_with_pipeliner      s     ~/09)I&112#!1S!8K3<NI&)/*;UWE	,sCj9
)/*;=O=QR	5SzB
s"&;s&B08C!}R	:FFF	**3& =):LNKL!/"3^e5TU  ,--S I&]?+<e#>NOP]?+<e!nMN	 %o&79Kc9RS ]?+<>PST>UVW	 I&& _ 1s   F,F.)AdaBoostClassifierAdaBoostRegressorr   BaggingRegressorClassifierChainIterativeImputerOneVsOneClassifierRANSACRegressorr
   r   RegressorChainr   SequentialFeatureSelectorc                 .    | j                   j                  S r!   )	__class__r*   )r   s    r'   _get_meta_estimator_idr     s    '''r)   r   )idsc                    t         j                  j                  d      }t        |        d}|j	                  t        j
                  g dt              |      }t        |       r|j                  |      }n|j                  d|      }t        | |      j                         }t        | |      j                         }| j                  ||       t        | d      rJ y )Nr      )aabbcc)dtype)size   n_features_in_)rR   randomRandomStater   choicearrayobjectr   normalrandintr   tolistr   r\   rv   )r   rng	n_samplesrX   rY   s        r'   -test_meta_estimators_delegate_data_validationr     s     ))


"CYI

288.f=I
NAIJJIJ&KK	K* 	")Q/668A!)Q/668A
 MM!Q y"23333r)   )8__doc__rG   inspectr   numpyrR   rw   sklearn.baser   r   sklearn.datasetsr   sklearn.ensembler   sklearn.exceptionsr   sklearn.feature_extraction.textr	   sklearn.feature_selectionr
   r   sklearn.linear_modelr   r   sklearn.model_selectionr   r   sklearn.pipeliner   r   sklearn.preprocessingr   r   sklearn.semi_supervisedr   sklearn.utilsr   sklearn.utils._testingr   sklearn.utils.estimator_checksr   r   sklearn.utils.validationr   r   ru   r   r   )DATA_VALIDATION_META_ESTIMATORS_TO_IGNOREr   r*   DATA_VALIDATION_META_ESTIMATORSr   markparametrizer   r/   s   0r'   <module>r      sd   %     4 0 . - ; 0 : D 4 > : ( 3 5) ) *BCFY
 	
 Y %K9L+MN'5=P/QR
  /H9! Hpf5v- )$ @A#A
}}%NN A# ( 06L  44#s   .!D: