a
    �ù»j68  ã                   @   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	j6 7d¡e	j6 8d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   úME:\soccer\ml_env\Lib\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¡r¶q”t
 |¡rÂq”tjdd	��}|  |¡}W d   ƒ n1 sî0    Y  t|ƒ�rtd|ˆ |d f ƒ‚t|jƒ�r&q”|t|j|ƒ7 }|jD ]l}	t||	ƒ}
t|
ƒ�rX�q<d }|	tv �r’t|
ƒ}d|jv �r’|jd jd u �r’dg}t|
|d�}||7 }�q<||7 }q”t
 |t
j¡}‡ fdd„|D ƒ}|D ]j\}}| d¡�rð�qØ|dk�r
ˆ  d¡�r
�qØt|ƒ‰t‡fdd„tD ƒƒ�sØt|ƒ�sØ|t|ƒ7 }�qØq"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r”t	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 �ršg d ¢}n |jd!k�rºd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ƒ�s®J ‚W d   ƒ n1 �sÄ0    Y  �q^t$|ƒ}d*d+„ |D ƒ}t%|ƒ &|¡}t%|ƒ &|¡}|�r t'd,|j› d-|› �ƒ‚d S ).Nr    r   r"   Ú
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)rr   éú   rp   )rp   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é   )rt   Zbaz)rn   ro   Zn_redundantZ	n_classesrp   .ú 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_attributesrz   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 s–0    Y  dd„ |D ƒS )zBGet all the fitted attributes of an estimator including propertiesÚerrorrx   Nc                 S   s$   g | ]}|  d ¡r| d ¡s|‘qS )r*   )r8   r'   )r   rq   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`\)\.rw   )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