
    0Ph,                        d Z ddlZddlm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-m.Z. ddl/m0Z0  G d d          Z1 e1dd            e1dd dg           e1dd dg           e1ded d!g           e1d"eg d#           e1d$eg d%           e1d&d' g d(          gZ2d) Z3d* Z4d+ Z5g d,Z6d-  e5            D             Z7d. Z8ej9        :                    d/e7e80          d1             Z;dS )2zCommon tests for metaestimators    N)suppress)	signature)BaseEstimatoris_regressor)make_classification)BaggingClassifier)NotFittedError)TfidfVectorizer)RFERFECV)LogisticRegressionRidge)GridSearchCVRandomizedSearchCV)Pipelinemake_pipeline)MaxAbsScalerStandardScalerSelfTrainingClassifier)all_estimators)_construct_instances)SkipTestset_random_state)_enforce_estimator_tags_X_enforce_estimator_tags_ycheck_is_fittedc                   .    e Zd Zd ed          fdZdS )DelegatorData r   )random_statec                 >    || _         || _        || _        || _        d S N)name	constructfit_argsskip_methods)selfr%   r&   r(   r'   s        a/var/www/html/test/jupyter/venv/lib/python3.11/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44
) 
) 
) 
) 
) 
)r,   r    r   c                 &    t          d| fg          S )Nest)r   r1   s    r*   <lambda>r3   2   s    (UCL>*B*B r,   r   c                 ,    t          | ddgid          S )Nparam      )
param_gridcv)r   r2   s    r*   r3   r3   5   s    L'A3AFFF r,   score)r(   r   c                 .    t          | ddgidd          S )Nr5   r6   r7      )param_distributionsr9   n_iter)r   r2   s    r*   r3   r3   :   s%    &gs^!
 
 
 r,   r   	transforminverse_transformr   )r?   r@   r:   r   )r?   r@   r:   predict_probapredict_log_probapredictr   c                      t          |           S r$   r   r2   s    r*   r3   r3   Q   s    *3// r,   )r?   r@   rA   c                     d  G fddt                     } d | j                                        D             }|                                 t          D ]} |             }|                    |          }|D ]}||j        v rt          ||          sJ t          ||          sJ |j        d|d            |dk    rbt          j
        t                    5   t          ||          |j        d         |j        d	                    d d d            n# 1 swxY w Y   t          j
        t                    5   t          ||          |j        d                    d d d            n# 1 swxY w Y    |j        |j          |D ]g}||j        v r|dk    r1 t          ||          |j        d         |j        d	                    C t          ||          |j        d                    h|D ]d}||j        v r | |
          }|                    |          }t          ||          rJ t          ||          rJ |j        d|d            e	d S )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>.wrapperZ   s<     FO33$^c6G%GHHH$VS111r,   )property)rM   rN   s   ` r*   hidesz,test_metaestimator_delegation.<locals>.hidesY   s-    		2 	2 	2 	2 
	2
 r,   c                       e Zd ZddZddZd Z d             Z d             Z d             Z d	             Z	 d
             Z
 d             Z d             ZdS )3test_metaestimator_delegation.<locals>.SubEstimatorr<   Nc                 "    || _         || _        d S r$   )r5   rH   )r)   r5   rH   s      r*   r+   z<test_metaestimator_delegation.<locals>.SubEstimator.__init__c   s    DJ!.Dr,   c                 \    t          j        |j        d                   | _        g | _        dS )Nr<   T)nparangeshapecoef_classes_r)   Xyargskwargss        r*   fitz7test_metaestimator_delegation.<locals>.SubEstimator.fitg   s%    171:..DJDM4r,   c                 $    t          |            d S r$   r   )r)   s    r*   
_check_fitz>test_metaestimator_delegation.<locals>.SubEstimator._check_fitl   s    D!!!!!r,   c                 .    |                                   |S r$   ra   r)   r[   r]   r^   s       r*   r@   zEtest_metaestimator_delegation.<locals>.SubEstimator.inverse_transformo       OOHr,   c                 .    |                                   |S r$   rc   rd   s       r*   r?   z=test_metaestimator_delegation.<locals>.SubEstimator.transformt   re   r,   c                 h    |                                   t          j        |j        d                   S Nr   ra   rU   onesrW   rd   s       r*   rC   z;test_metaestimator_delegation.<locals>.SubEstimator.predicty   (    OO7171:&&&r,   c                 h    |                                   t          j        |j        d                   S rh   ri   rd   s       r*   rA   zAtest_metaestimator_delegation.<locals>.SubEstimator.predict_proba~   rk   r,   c                 h    |                                   t          j        |j        d                   S rh   ri   rd   s       r*   rB   zEtest_metaestimator_delegation.<locals>.SubEstimator.predict_log_proba   rk   r,   c                 h    |                                   t          j        |j        d                   S rh   ri   rd   s       r*   decision_functionzEtest_metaestimator_delegation.<locals>.SubEstimator.decision_function   rk   r,   c                 .    |                                   dS )N      ?rc   rZ   s        r*   r:   z9test_metaestimator_delegation.<locals>.SubEstimator.score   s    OO3r,   )r<   Nr$   )r-   r.   r/   r+   r_   ra   r@   r?   rC   rA   rB   ro   r:   )rP   s   r*   SubEstimatorrR   b   s	       	/ 	/ 	/ 	/	 	 	 	
	" 	" 	" 
	 	 
	 
	 	 
	 
	' 	' 
	' 
	' 	' 
	' 
	' 	' 
	' 
	' 	' 
	' 
	 	 
	 	 	r,   rr   c                 f    g | ].}|                     d           |                     d          ,|/S )_r_   )
startswith).0ks     r*   
<listcomp>z1test_metaestimator_delegation.<locals>.<listcomp>   sP       ||C   *+e)<)<	  r,   z does not have method z when its delegate doesr:   r   r<   )rH   z has method z when its delegate does not)r   __dict__keyssortDELEGATING_METAESTIMATORSr&   r(   hasattrr%   pytestraisesr	   getattrr'   r_   )rr   methodsdelegator_datadelegate	delegatorrM   rP   s         @r*   test_metaestimator_delegationr   W   s     . . . . . . .} . . .` &++--  G
 LLNNN3 . .<>>",,X66	 	K 	KF4448V,,,,,6    ###     ]>22  .GIv..&/2N4KA4N                
 ]>22 K K.GIv..~/Fq/IJJJK K K K K K K K K K K K K K K 		~.// 		G 		GF444  *	6**"+A.0G0J    +	6**>+B1+EFFFF 	 	F444#|&999H&00::Ix000006    ###   	G. .s$   1DD #D %E22E69E6c                 (   h d|z  rt          |           r/t          t                      t                                }dddgi}n.t          t                      t	                                }dddgi}|                    ddh          r!d|v rdd	ini } t          |           ||fi |S  t          |           |          S d
|v rndt          t                      t                                fdt          t                      t          d                    fg} t          |           |          S d|v rt          |           rYdt          t                      t          d                    fdt          t                      t          d                    fg}nXdt          t                      t	          d                    fdt          t                      t	          d                    fg} t          |           |          S dS )zLGiven a single meta-estimator instance, generate an instance with a pipeline>   	estimator	regressorbase_estimatorridge__alphag?rq   logisticregression__Cr8   r=   r>   r7   transformer_listtrans1trans2F)	with_mean
estimatorsest1)alphaest2r<   )CN)	r   r   r
   r   r   intersectiontyper   r   )meta_estimatorinit_paramsr   r8   extra_paramsr   s         r*   _get_instance_with_pipeliner      s=   333kA 3'' 	?%o&7&7AAI(3*5JJ%o&7&79K9M9MNNI1C:>J##01
 
 	3 -5,C,CHa==L'4''	:NNNNN'4''	222[(( }_%6%6GGHo//%1P1P1PQQ
 $tN##$4555{""'' 	'8'8%c:J:J:JKKL'8'8%a...IIJII !/"3"35G#5N5N5NOO '8'8:Lq:Q:Q:QRRSI $tN##I... #"r,   c               #     K   t          dt          t                                           t          t                                D ]\  } }t	          t          |          j                  }t          d|j        |           |                    h d          sTt          t                    5  t          |          D ]#}t          |           t          ||          V  $	 ddd           n# 1 swxY w Y   dS )zGenerate instances of meta-estimators fed with a pipeline

    Are considered meta-estimators all estimators accepting one of "estimator",
    "base_estimator" or "estimators".
    zestimators: 
>   r   r   r   r   r   N)printlenr   sortedsetr   
parametersr-   r   r   r   r   r   )rt   	Estimatorsigr   s       r*   0_generate_meta_estimator_instances_with_pipeliner      si      
.#n..//000~//00 G G9)I&&122dI&,,,  
 
 		 h 	G 	G"6y"A"A G Gn%%%1.#FFFFFFG	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	GG Gs   /4C00C4	7C4	)AdaBoostClassifierAdaBoostRegressorr   BaggingRegressorClassifierChainFrozenEstimatorIterativeImputerOneVsOneClassifierRANSACRegressorr   r   RegressorChainr   SequentialFeatureSelectorc                 8    g | ]}|j         j        t          v|S r!   )	__class__r-   )DATA_VALIDATION_META_ESTIMATORS_TO_IGNORE)rv   r1   s     r*   rx   rx   )  s3     # # #
}%NNN NNNr,   c                     | j         j        S r$   )r   r-   )r   s    r*   _get_meta_estimator_idr   0  s    ''r,   r   )idsc                    t           j                            d          }t          |            d}|                    t          j        g dt                    |          }t          |           r|                    |          }n|	                    d|          }t          | |                                          }t          | |                                          }|                     ||           t          | d          rJ d S )Nr      )aabbcc)dtype)size   n_features_in_)rU   randomRandomStater   choicearrayobjectr   normalrandintr   tolistr   r_   r}   )r   rng	n_samplesr[   r\   s        r*   -test_meta_estimators_delegate_data_validationr   4  s     )


"
"CYI

28...f===I
NNAI +JJIJ&&KK	K** 	")Q//6688A!)Q//6688A
 MM!Q y"23333333r,   )<__doc__rJ   
contextlibr   inspectr   numpyrU   r~   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._test_common.instance_generatorr   sklearn.utils._testingr   r   sklearn.utils.estimator_checksr   r   sklearn.utils.validationr   r    r|   r   r   r   r   DATA_VALIDATION_META_ESTIMATORSr   markparametrizer   r!   r,   r*   <module>r      s   % %                      4 4 4 4 4 4 4 4 0 0 0 0 0 0 . . . . . . - - - - - - ; ; ; ; ; ; 0 0 0 0 0 0 0 0 : : : : : : : : D D D D D D D D 4 4 4 4 4 4 4 4 > > > > > > > > : : : : : : ( ( ( ( ( ( N N N N N N = = = = = = = =        5 4 4 4 4 4) ) ) ) ) ) ) )& M*BBCCMFFY  
 M	
 	
 Y   M%K9L+MNNNM%P%P%P   M
 
 
   M //HHH  =# Lp p pf,/ ,/ ,/^G G G>- - - )"# #??AA# # # ( ( ( 06L   4 4 4 4 4r,   