a
    h6                     @   s  d dl Z d dlZd dl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
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mZmZm Z m!Z! d dl"m#Z# d dl$m%Z%m&Z& e' F e(de) ej*+e
j,gZ-e.dd ede-dD Z/W d   n1 sF0    Y  g dZ0g dZ1dd Z2dd Z3dd Z4dd Z5e	j67de	j68de d d! Z9d"d# Z:e!d$d% Z;e!d&d' Z<dS )(    N)	signature)walk_packages)metrics)make_classification)StackingClassifierStackingRegressor)enable_halving_search_cvenable_iterative_imputerLogisticRegression)FunctionTransformer)all_estimators)_construct_instances)_get_func_nameassert_docstring_consistencycheck_docstring_parametersignore_warningsskip_if_no_numpydoc)_is_deprecated)_enforce_estimator_tags_X_enforce_estimator_tags_yignorec                 C   s,   g | ]$}d |d v sd|d v s|d qS )z._   z.tests. ).0Zpckgr   r   c/var/www/html/assistant/venv/lib/python3.9/site-packages/sklearn/tests/test_docstring_parameters.py
<listcomp>0   s   r   zsklearn.)prefixpath)z%sklearn.utils.deprecation.load_mlcompzsklearn.pipeline.make_pipelinezsklearn.pipeline.make_unionz%sklearn.utils.extmath.safe_sparse_dotzsklearn.utils._joblibZHalfBinomialLoss)fitZscoreZfit_predictZfit_transformZpartial_fitZpredictc               
      sn  t jddd ddlm}  g }tD ]   dr4q" dkr>q"tjdd	 t	 }W d    n1 sj0    Y  t
|t
j}d
d |D }|D ]\}}g }|tv s|drqt
|rqtjdd	}| |}W d    n1 s0    Y  t|rtd| |d f t|jr&q|t|j|7 }|jD ]l}	t||	}
t|
rXq<d }|	tv rt|
}d|jv r|jd jd u rdg}t|
|d}||7 }q<||7 }qt
|t
j} fdd|D }|D ]j\}}|drq|dkr
 dr
qt|tfddtD st|s|t|7 }qq"d |}t|dkrjt!d| d S )Nnumpydocz+numpydoc is required to test the docstrings)reasonr   	docscrapez	.conftestzsklearn.utils.fixesT)recordc                 S   s    g | ]}|d  j dr|qS )r   sklearn)
__module__
startswith)r   clsr   r   r   r   d       z-test_docstring_parameters.<locals>.<listcomp>_z"Error for __init__ of %s in %s:
%sy)r   c                    s   g | ]}|d  j  kr|qS )r   )r&   )r   fnnamer   r   r      r)   configurationsetupc                 3   s   | ]}| v V  qd S )Nr   )r   d)name_r   r   	<genexpr>   r)   z,test_docstring_parameters.<locals>.<genexpr>
zDocstring Error:
)"pytestimportorskipr    r#   PUBLIC_MODULESendswithwarningscatch_warnings	importlibimport_moduleinspect
getmembersisclass_DOCSTRING_IGNORESr'   
isabstractClassDoclenRuntimeErrorr   __new__r   __init__methodsgetattr_METHODS_IGNORE_NONE_Yr   
parametersdefault
isfunctionr   anyjoinAssertionError)r#   Z	incorrectmoduleclassescnamer(   Zthis_incorrectwZcdocmethod_namemethodZparam_ignoresigresultZ	functionsfnamefuncmsgr   )r.   r2   r   test_docstring_parametersM   sp    

(
(






r[   c                 C   s   | t  dddgiS )NCg?r   r
   )ZSearchCVr   r   r   _construct_searchcv_instance   s    r]   c                 C   s\   | j dkr | ddddgfgdS | j dkr<| dt fgd	S | j d
krX| dt fgdS d S )NColumnTransformerZtransformerpassthroughr   r   )ZtransformersPipelineZclf)ZstepsFeatureUnion)Ztransformer_list)__name__r   r   )	Estimatorr   r   r   $_construct_compose_pipeline_instance   s    


rd   c                 C   s8   t jg dg dg dg dg dgt jd}| |dS )N)r   r   r   )re      )r   r   r   )r   r   r   )r   rf   r   )Zdtype)
dictionary)nparrayZfloat64)rc   rg   r   r   r   _construct_sparse_coder   s
     rj   z-ignore::sklearn.exceptions.ConvergenceWarningzname, Estimatorc              	   C   s$  t d ddlm} ||}|d }|jdv r<t|}nd|jdv rPt|}nP|jdkrdt|}n<|jdkrt	d	d
dd\}}|t
 ||}ntt|}|jdkr|jdd nn|jdkr|jdd nV|jdks|jdr|jdd n2|jdv r|jdd n|jdkr&|jdd d| v rX|jdd |jdkrX|jdd d| v rr|jdd i }|jdr|jdv rg d }n |jd!krddd"d#dd$g}d }n*t	d	d#dddd%\}}t||}t||}| jjr|| nV| jjr(|tj||f  n2| jjrN||tjd&f | n||| |D ]r}	|	j|v rrq^d'|	j  }
d(|
v rq^t!t"d)" t#||	jsJ W d    n1 s0    Y  q^t$|}d*d+ |D }t%|&|}t%|&|}|r t'd,|j d-| d S ).Nr    r   r"   Z
Attributes)ZHalvingRandomSearchCVZRandomizedSearchCVZHalvingGridSearchCVZGridSearchCV)r^   r`   ra   ZSparseCoderZFrozenEstimator      )	n_samples
n_featuresrandom_stateZSelectKBestrf   )kZDummyClassifierZ
stratified)ZstrategyZCCAZPLSr   )Zn_components)ZGaussianRandomProjectionZSparseRandomProjectionZTSNE)Z
perplexitymax_iter)rq      ro   )ro   Z
Vectorizer)ZCountVectorizerZHashingVectorizerZTfidfVectorizer)zThis is the first document.z%This document is the second document.zAnd this is the third one.zIs this the first document?ZDictVectorizer)foobar   )rs   Zbaz)rm   rn   Zn_redundantZ	n_classesro   . zonly categoryc                 S   s   g | ]
}|j qS r   r-   )r   attrr   r   r   r   %  r)   z1test_fit_docstring_attributes.<locals>.<listcomp>zUndocumented attributes for z: )(r5   r6   r    r#   rB   rb   r]   rd   rj   r   r   r   nextr   Z
set_paramsr'   
get_paramsr8   r   r   Z__sklearn_tags__Ztarget_tagsZone_d_labelsZtwo_d_labelsrh   Zc_Z
input_tagsZthree_d_arrayZnewaxisr.   rN   desclowerr   FutureWarninghasattr_get_all_fitted_attributesset
differencerO   )r.   rc   r#   doc
attributesZestXr+   Zskipped_attributesry   r|   fit_attrZfit_attr_namesZundocumented_attrsr   r   r   test_fit_docstring_attributes   s    















6r   c                 C   s   t | j }t z tjdtd t| jD ]P}t	| j|}t
|tsLq0zt	| | W n ttfyt   Y q0Y n0 || q0W d   n1 s0    Y  dd |D S )zBGet all the fitted attributes of an estimator including propertieserrorrw   Nc                 S   s$   g | ]}| d r|d s|qS )r*   )r8   r'   )r   rp   r   r   r   r   D  r)   z._get_all_fitted_attributes.<locals>.<listcomp>)list__dict__keysr9   r:   filterwarningsr~   dir	__class__rH   
isinstancepropertyAttributeErrorappend)Z	estimatorr   r.   objr   r   r   r   .  s    


*r   c                  C   sL   t jt jt jt jt jg} t| dddgd d}t| dgd| d dS )	z>Check docstrings parameters of related metrics are consistent.TZaverageZzero_division)include_paramsZexclude_paramsa  This parameter is required for multiclass/multilabel targets\.
        If ``None``, the metrics for each class are returned\. Otherwise, this
        determines the type of averaging performed on the data:
        ``'binary'``:
            Only report results for the class specified by ``pos_label``\.
            This is applicable only if targets \(``y_\{true,pred\}``\) are binary\.
        ``'micro'``:
            Calculate metrics globally by counting the total true positives,
            false negatives and false positives\.
        ``'macro'``:
            Calculate metrics for each label, and find their unweighted
            mean\.  This does not take label imbalance into account\.
        ``'weighted'``:
            Calculate metrics for each label, and find their average weighted
            by support \(the number of true instances for each label\)\. This
            alters 'macro' to account for label imbalance; it can result in an
            F-score that is not between precision and recall\.[\s\w]*\.*
        ``'samples'``:
            Calculate metrics for each instance, and find their average \(only
            meaningful for multilabel classification where this differs from
            :func:`accuracy_score`\)\.rv   )r   Zdescr_regex_patternN)	r   Zprecision_recall_fscore_supportZf1_scoreZfbeta_scoreZprecision_scoreZrecall_scorer   rN   split)Zmetrics_to_checkZdescription_regexr   r   r   3test_precision_recall_f_score_docstring_consistencyG  s$    r   c                   C   s   t ttgg dddgd dS )z?Check docstrings parameters stacking estimators are consistent.)ZcvZn_jobsr_   verboseTZfinal_estimator_)r   Zinclude_attrsZexclude_attrsN)r   r   r   r   r   r   r   8test_stacking_classifier_regressor_docstring_consistencyx  s    r   )=r;   r=   osr9   r   pkgutilr   numpyrh   r5   r%   r   Zsklearn.datasetsr   Zsklearn.ensembler   r   Zsklearn.experimentalr   r	   Zsklearn.linear_modelr   Zsklearn.preprocessingr   Zsklearn.utilsr   Z-sklearn.utils._test_common.instance_generatorr   Zsklearn.utils._testingr   r   r   r   r   Zsklearn.utils.deprecationr   Zsklearn.utils.estimator_checksr   r   r:   simplefilterr~   r   dirname__file__Zsklearn_pathr   r7   r@   rI   r[   r]   rd   rj   markr   Zparametrizer   r   r   r   r   r   r   r   <module>   sR   

$


O
	
y
0