
    >[g,                        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,Z6 e5       D  cg c]  } | jn                  jp                  e6vr|  c} Z9d- Z:ejv                  jy                  d.e9e:/      d0        Z=yc c} w )1z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y)DelegatorData r   )random_statec                 <    || _         || _        || _        || _        y N)name	constructfit_argsskip_methods)selfr%   r&   r(   r'   s        \/var/www/html/bid-api/venv/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   r1   s    r*   <lambda>r3   2   s    (UCL>*Br,   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Fr,   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               } | 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>.wrapperZ   s>      FOO3$^c6G6G%GHH$$VS11r,   )property)rM   rN   s   ` r*   hidesz,test_metaestimator_delegation.<locals>.hidesY   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$   )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 | _        y)Nr<   T)nparangeshapecoef_classes_r)   Xyargskwargss        r*   fitz7test_metaestimator_delegation.<locals>.SubEstimator.fitg   s$    1771:.DJDMr,   c                     t        |        y r$   r   )r)   s    r*   
_check_fitz>test_metaestimator_delegation.<locals>.SubEstimator._check_fitl   s
    D!r,   c                 &    | j                          |S r$   ra   r)   r[   r]   r^   s       r*   r@   zEtest_metaestimator_delegation.<locals>.SubEstimator.inverse_transformo       OOHr,   c                 &    | j                          |S r$   rc   rd   s       r*   r?   z=test_metaestimator_delegation.<locals>.SubEstimator.transformt   re   r,   c                 f    | j                          t        j                  |j                  d         S Nr   ra   rU   onesrW   rd   s       r*   rC   z;test_metaestimator_delegation.<locals>.SubEstimator.predicty   #    OO771771:&&r,   c                 f    | j                          t        j                  |j                  d         S rh   ri   rd   s       r*   rA   zAtest_metaestimator_delegation.<locals>.SubEstimator.predict_proba~   rk   r,   c                 f    | j                          t        j                  |j                  d         S rh   ri   rd   s       r*   rB   zEtest_metaestimator_delegation.<locals>.SubEstimator.predict_log_proba   rk   r,   c                 f    | j                          t        j                  |j                  d         S rh   ri   rd   s       r*   decision_functionzEtest_metaestimator_delegation.<locals>.SubEstimator.decision_function   rk   r,   c                 $    | j                          y)N      ?rc   rZ   s        r*   r:   z9test_metaestimator_delegation.<locals>.SubEstimator.score   s    OOr,   )r<   Nr$   )r-   r.   r/   r+   r_   ra   r@   r?   rC   rA   rB   ro   r:   )rP   s   r*   SubEstimatorrR   b   s    	/	
	" 
	 
	 
	 
	 
	' 
	' 
	' 
	' 
	' 
	' 
	' 
	' 
	 
	r,   rr   _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
startswithsortDELEGATING_METAESTIMATORSr&   r(   hasattrr%   pytestraisesr	   getattrr'   r_   )rr   kmethodsdelegator_datadelegate	delegatorrM   rP   s          @r*   test_metaestimator_delegationr   W   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                    h d|z  rt        |       r#t        t               t                     }dddgi}n"t        t               t	                     }dddgi}|j                  ddh      rd|v rdd	ini } t        |       ||fi |S  t        |       |      S d
|v rOdt        t               t                     fdt        t               t        d            fg} t        |       |      S 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} t        |       |      S y)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   3kA'%o&7AI(3*5J%o&79K9MNI1C:>J##01
 -5,CHa=L'4'	:NNN'4'	22[( }_%6GHo/%1PQ
 $tN#$455{"''8%c:JKL'8%a.IJI !/"35G#5NO '8:Lq:QRSI $tN#I.. #r,   c               #     K   t        dt        t                            t        t                     D ]  \  } }t	        t        |      j                        }t        d|j                  |       |j                  h d      sOt        t              5  t        |      D ]  }t        |       t        ||        	 ddd        y# 1 sw Y   xY ww)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   )rs   	Estimatorsigr   s       r*   0_generate_meta_estimator_instances_with_pipeliner      s      
.#n./0~/09)I&112dI&&,
 h"6y"An%1.#FF #B   1  s   BC*C<CC	C)AdaBoostClassifierAdaBoostRegressorr   BaggingRegressorClassifierChainFrozenEstimatorIterativeImputerOneVsOneClassifierRANSACRegressorr   r   RegressorChainr   SequentialFeatureSelectorc                 .    | j                   j                  S r$   )	__class__r-   )r   s    r*   _get_meta_estimator_idr   0  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_)rU   randomRandomStater   choicearrayobjectr   normalrandintr   tolistr   r_   ry   )r   rng	n_samplesr[   r\   s        r*   -test_meta_estimators_delegate_data_validationr   4  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,   )>__doc__rJ   
contextlibr   inspectr   numpyrU   rz   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    rx   r   r   r   )DATA_VALIDATION_META_ESTIMATORS_TO_IGNOREr   r-   DATA_VALIDATION_META_ESTIMATORSr   markparametrizer   r2   s   0r*   <module>r      sp   %      4 0 . - ; 0 : D 4 > : ( N = 5) )& *BCFY
 	
 Y %K9L+MN%P 
  /H=# Lpf,/^G>- )& @A#A
}}%NN A# ( 06L  44#s   ?!E