o
    tBh@(                     @   s  d Z ddlZddlm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 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 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+ G dd dZ,e,ddd e,ddd dgde,ddd dgde,d ed!d"gde,d#ed!d"gde,d$e!g d%de,d&d'd g d(dgZ-d)d* Z.d+d, Z/g d-Z0d.d/ e/ D Z1d0d1 Z2ej3j4d2e1e2d3d4d5 Z5dS )6zCommon tests for metaestimators    N)	signature)BaseEstimator)is_regressor)make_classification)all_estimators)_enforce_estimator_tags_x)_enforce_estimator_tags_ycheck_is_fitted)set_random_state)Pipelinemake_pipeline)GridSearchCVRandomizedSearchCV)TfidfVectorizer)RFERFECV)BaggingClassifier)NotFittedErrorSelfTrainingClassifier)RidgeLogisticRegression)StandardScalerMaxAbsScalerc                   @   s   e Zd Zde fddZdS )DelegatorData c                 C   s   || _ || _|| _|| _d S N)name	constructfit_argsskip_methods)selfr   r   r!   r    r   r   x/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/sklearn/tests/test_metaestimators.py__init__   s   
zDelegatorData.__init__N)__name__
__module____qualname__r   r$   r   r   r   r#   r      s    r   r   c                 C   s   t d| fgS )Nest)r   r(   r   r   r#   <lambda>&   s    r*   r   c                 C   s   t | ddgiddS )Nparam      )
param_gridcv)r   r)   r   r   r#   r*   )   s    score)r!   r   c                 C   s   t | ddgidddS )Nr+   r,   r-      )param_distributionsr/   n_iter)r   r)   r   r   r#   r*   .   s    r   	transforminverse_transformr   r   )r4   r5   r0   predict_probapredict_log_probapredictr   c                 C   s   t | S r   r   r)   r   r   r#   r*   C   s    )r4   r5   r6   c               
      s  dd  G  fdddt } dd | j D }|  tD ]}|  }||}|D ]d}||jv r2q*t||s9J t||sGJ d|j|f |dkrot	
t t|||jd	 |jd
  W d    n1 siw   Y  q*t	
t t|||jd	  W d    n1 sw   Y  q*|j|j  |D ]%}||jv rq|dkrt|||jd	 |jd
  qt|||jd	  q|D ]'}||jv rq| |d}||}t||rJ t||rJ d|j|f qqd S )Nc                    s   t  fdd}|S )Nc                    s&   | j  jkrtd| j  t | S )Nz%r is hidden)hidden_methodr%   AttributeError	functoolspartial)objmethodr   r#   wrapperL   s   z=test_metaestimator_delegation.<locals>.hides.<locals>.wrapper)property)r?   r@   r   r>   r#   hidesK   s   z,test_metaestimator_delegation.<locals>.hidesc                       s|   e Zd ZdddZdddZdd Z d	d
 Z dd Z dd Z dd Z	 dd Z
 dd Z dd ZdS )z3test_metaestimator_delegation.<locals>.SubEstimatorr1   Nc                 S   s   || _ || _d S r   )r+   r9   )r"   r+   r9   r   r   r#   r$   U   s   
z<test_metaestimator_delegation.<locals>.SubEstimator.__init__c                 _   s   t |jd | _g | _dS )Nr1   T)nparangeshapecoef_classes_r"   Xyargskwargsr   r   r#   fitY   s   z7test_metaestimator_delegation.<locals>.SubEstimator.fitc                 S   s   t |  d S r   r	   )r"   r   r   r#   
_check_fit^   s   z>test_metaestimator_delegation.<locals>.SubEstimator._check_fitc                 _      |    |S r   rN   r"   rI   rK   rL   r   r   r#   r5   a      zEtest_metaestimator_delegation.<locals>.SubEstimator.inverse_transformc                 _   rO   r   rP   rQ   r   r   r#   r4   f   rR   z=test_metaestimator_delegation.<locals>.SubEstimator.transformc                 _      |    t|jd S Nr   rN   rC   onesrE   rQ   r   r   r#   r8   k      z;test_metaestimator_delegation.<locals>.SubEstimator.predictc                 _   rS   rT   rU   rQ   r   r   r#   r6   p   rW   zAtest_metaestimator_delegation.<locals>.SubEstimator.predict_probac                 _   rS   rT   rU   rQ   r   r   r#   r7   u   rW   zEtest_metaestimator_delegation.<locals>.SubEstimator.predict_log_probac                 _   rS   rT   rU   rQ   r   r   r#   decision_functionz   rW   zEtest_metaestimator_delegation.<locals>.SubEstimator.decision_functionc                 _   s   |    dS )N      ?rP   rH   r   r   r#   r0      rR   z9test_metaestimator_delegation.<locals>.SubEstimator.score)r1   Nr   )r%   r&   r'   r$   rM   rN   r5   r4   r8   r6   r7   rX   r0   r   rB   r   r#   SubEstimatorT   s$    







r[   c                 S   s$   g | ]}| d s| ds|qS )_rM   )
startswith).0kr   r   r#   
<listcomp>   s    z1test_metaestimator_delegation.<locals>.<listcomp>z1%s does not have method %r when its delegate doesr0   r   r1   )r9   z+%s has method %r when its delegate does not)r   __dict__keyssortDELEGATING_METAESTIMATORSr   r!   hasattrr   pytestraisesr   getattrr    rM   )r[   methodsdelegator_datadelegate	delegatorr?   r   rZ   r#   test_metaestimator_delegationI   sr   	0





rm   c                  c   sv   t t D ]\} }tt|j}d|v sd|v sd|v r_t|r/tt t }dddgi}ntt t	 }dddgi}d|v sDd	|v rYd
|v rLd
dini }|||fi |V  q||V  qd|v r}dtt t
 fdtt tddfg}||V  qd|v rt|rdtt tddfdtt tddfg}ndtt t	ddfdtt t	ddfg}||V  qq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".
    	estimatorbase_estimator	regressorridge__alphag?rY   logisticregression__Cr.   r2   r3   r-   transformer_listtrans1trans2F)	with_mean
estimatorsest1)alphaest2r1   )CN)sortedr   setr   
parametersr   r   r   r   r   r   r   )r\   	Estimatorsigrn   r.   extra_paramsrs   r   r   r#   0_generate_meta_estimator_instances_with_pipeline   sB   r   )AdaBoostClassifierAdaBoostRegressorr   BaggingRegressorClassifierChainIterativeImputerOneVsOneClassifierRANSACRegressorr   r   RegressorChainr   SequentialFeatureSelectorc                 C   s   g | ]
}|j jtvr|qS r   )	__class__r%   )DATA_VALIDATION_META_ESTIMATORS_TO_IGNORE)r^   r(   r   r   r#   r`     s
    r`   c                 C   s   | j jS r   )r   r%   )rn   r   r   r#   _get_meta_estimator_id  s   r   rn   )idsc                 C   s   t jd}t|  d}|jt jg dtd|d}t| r%|j|d}n|j	d|d}t
| | }t| | }| || t| drGJ d S )Nr      )aabbcc)dtype)size   n_features_in_)rC   randomRandomStater   choicearrayobjectr   normalrandintr   tolistr   rM   re   )rn   rng	n_samplesrI   rJ   r   r   r#   -test_meta_estimators_delegate_data_validation  s   r   )6__doc__r;   inspectr   numpyrC   rf   sklearn.baser   r   sklearn.datasetsr   sklearn.utilsr   sklearn.utils.estimator_checksr   r   sklearn.utils.validationr
   sklearn.utils._testingr   sklearn.pipeliner   r   sklearn.model_selectionr   r   sklearn.feature_extraction.textr   sklearn.feature_selectionr   r   sklearn.ensembler   sklearn.exceptionsr   sklearn.semi_supervisedr   sklearn.linear_modelr   r   sklearn.preprocessingr   r   r   rd   rm   r   r   DATA_VALIDATION_META_ESTIMATORSr   markparametrizer   r   r   r   r#   <module>   st    $s;