o
    tBh(                    @   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mZ d dl	m
Z
 d dlZd dlmZ d dlm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 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& d	dl#m'Z' d	dl#m(Z( d	dl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ d	dl0m1Z1m2Z2m3Z3 d	dl4m5Z5 d	d l6m7Z7 d	d!l6m8Z8 d	d"l9m:Z: d	d#l;m<Z< d	d$l;m=Z= d	d%l;m>Z> d	d&l?m@Z@ d	d'l?mAZA d	d(lBmCZC d	d)lDmEZEmFZFmGZG d	d*lHmIZI d	d+lJmKZK dd,lmLZL dd-lMmNZNmOZO dd.lPmQZQmRZR d	d/lSmTZT d	d0lSmUZU d	d1lVmWZWmXZXmYZYmZZZ da[g d2Z\d3d4 Z]d5d6 Z^ee_d7d8d9 Z`d:d; Zad<d= Zbd>d? Zcd@dA ZddBdC ZedDdE ZfdFdG ZgdHdI ZhdJdK ZidLdM ZjdNdO Zkd	dRdSZldTdU ZmdVdW ZnG dXdY dYZodZd[ ZpeFfd\d]Zqd^d_ Zrd`da Zsee_d7dbdc Ztee_d7ddde Zuee_d7dfdg Zvee_d7dhdi Zwee_d7d
dkdlZxdmdn Zyee_ezfd7dodp Z{dqdr Z|edsdt Z}dudv Z~ee_d7dwdx Zee_d7dydz Zd{d| Zee_d7d}d~ Zee_d7dd Zedd Zedd Zedd Zee_d7dddZee_d7dd Zee_d7dd Zdd Zedd Zedd Zedd Zdd Zee_d7dd Zee_d7dd Zedd Zedd Zee_d7dd Zee_d7dd Zee_d7dd Zee_d7dddZee_d7dd Zee_d7dd Zdd Ze	dddZdd ZdddZee_d7dd Zee_d7dd Zee_d7dd Zee_d7dd Zee_d7dddZedd Zee_d7dd ZeddĄ ZddƄ ZddȄ Zee_d7ddʄ Zee_d7dPejfdd̄Zedd΄ Zee_d7ddЄ Zee_d7dd҄ Zee_d7ddԄ Zee_d7ddք Zee_d7dd؄ Zee_d7ddڄ Zee_d7dd܄ Zee_d7ddބ Zee_d7dd Zdd Zdd Zdd Zee_d7dd Zee_d7dd Zee_d7dd Zee_d7dd Zee_d7dd Zee_d7dd Zdd Zdd Zdd Zdd Zdd Zdd Zee_d7dd  ZÐdd ZĐdd ZŐdd ZƐdd ZdS (      N)deepcopy)partialwraps)	signature)sparse)rankdata   )IS_PYPY   )config_context	_get_args)assert_raise_message)assert_array_equal)assert_array_almost_equal)assert_allclose)assert_allclose_dense_sparse)assert_array_less)set_random_state)SkipTest)ignore_warningscreate_memmap_backed_data)raises)is_scalar_nan)LinearRegression)LogisticRegressionRANSACRegressor)Ridge)SGDRegressor)cloneClusterMixinis_classifieris_regressoris_outlier_detectorRegressorMixin)accuracy_scoreadjusted_rand_scoref1_score)BaseRandomProjection)SelectKBest)SelectFromModel)make_pipeline)DataConversionWarning)NotFittedError)SkipTestWarning)train_test_split)ShuffleSplit)_safe_split)
rbf_kernellinear_kernelpairwise_distances)threadpool_info)check_is_fitted)shuffle)_DEFAULT_TAGS
_safe_tags)has_fit_parameter_num_samples)StandardScaler)scale)	load_iris
make_blobsmake_multilabel_classificationmake_regression)PLSCanonicalPLSRegressionCCAPLSSVDc                 c   s    | j j}t| }tV  tV  tV  t| dr8tV  tV  t	V  |d s8t
V  tV  ttddV  ttddV  tV  ttddV  |d sOtV  tV  tV  |tvrVtV  |d	 sa|d satV  |d rhtV  tV  t| d
rstV  tV  tV  tV  d S )Nsample_weightpairwiseones)kindzerosTreadonly_memmapno_validation	allow_nansparsify)	__class____name__r;   check_no_attributes_set_in_initcheck_estimators_dtypescheck_fit_score_takes_yr<   "check_sample_weights_pandas_series!check_sample_weights_not_an_arraycheck_sample_weights_listcheck_sample_weights_shape$check_sample_weights_not_overwrittenr   check_sample_weights_invariance!check_estimators_fit_returns_selfcheck_complex_datacheck_dtype_object$check_estimators_empty_data_messagesCROSS_DECOMPOSITIONcheck_pipeline_consistencycheck_estimators_nan_infcheck_nonsquare_error!check_estimators_overwrite_paramshasattrcheck_sparsify_coefficientscheck_estimator_sparse_datacheck_estimators_pickle%check_estimator_get_tags_default_keys)	estimatornametags rn   u/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/sklearn/utils/estimator_checks.py_yield_checksO   sB   


rp   c                 c   s    t | }tV  tV  tV  tV  |d rtV  tV  ttddV  ttdddV  tV  |d r=t	V  t
V  tV  tV  |d sKtV  |d sKtV  |d	 rRtV  d
|   v r]tV  tV  tV  d S )NmultioutputTrM   float32rN   X_dtype
multilabelrO   multioutput_onlyrequires_fitclass_weight)r;   "check_classifier_data_not_an_arraycheck_classifiers_one_labelcheck_classifiers_classes'check_estimators_partial_fit_n_featurescheck_classifier_multioutputcheck_classifiers_trainr   #check_classifiers_regression_target6check_classifiers_multilabel_representation_invariance2check_classifiers_multilabel_output_format_predict8check_classifiers_multilabel_output_format_predict_proba<check_classifiers_multilabel_output_format_decision_functioncheck_supervised_y_no_nancheck_supervised_y_2dcheck_estimators_unfitted
get_paramskeyscheck_class_weight_classifiers'check_non_transformer_estimators_n_iter check_decision_proba_consistency)
classifierrm   rn   rn   ro   _yield_classifier_checks   s6   
r   categoryc           
   	   C   s   t |}tjd}|jdd}tjtjfD ]N}td|}t||}|j	}|
dr?d|v s?|ds?t|r<d}nd	}nd }d
|  d}	tt||	d ||| W d    n1 s_w   Y  qd S )Nix  )
      sizer   sklearn.test__testingzJInput (y|Y) contains infinity or a value too large for dtype\('float64'\).zInput (y|Y) contains NaN.
Estimator z< should have raised error on fitting array y with inf value.matcherr_msg)r!   nprandomRandomStatestandard_normalnaninffull_enforce_estimator_tags_y
__module__
startswithendswithisinfr   
ValueErrorfit)
rl   estimator_origrk   rngXvalueymodule_namer   r   rn   rn   ro   r      s*   



r   c                 c   s    t | }tV  ttddV  ttdddV  tV  tV  |d r$tV  tV  |d s2|d s2tV  tV  | j	j
}|dkr@tV  |d	 rGtV  tV  d S )
NTrM   rr   rs   rq   rO   rv   rF   rw   )r;   check_regressors_trainr   !check_regressor_data_not_an_arrayr|   check_regressor_multioutput%check_regressors_no_decision_functionr   r   rR   rS   check_regressors_intr   r   )	regressorrm   rl   rn   rn   ro   _yield_regressor_checks   s&   
r   c                 c   sr    t | }|d stV  tV  |d rtV  ttddV  t | dds&tV  g d}| jj}||vr7tV  d S d S )NrO   preserves_dtypeTrM   	statelesskey)Isomap	KernelPCALocallyLinearEmbeddingRandomizedLassoLogisticRegressionCVBisectingKMeans)	r;   #check_transformer_data_not_an_arraycheck_transformer_general!check_transformer_preserve_dtypesr   check_transformers_unfittedrR   rS   check_transformer_n_iter)transformerrm   external_solverrl   rn   rn   ro   _yield_transformer_checks   s   	
r   c                 c   sJ    t V  | jj}|dvrtV  ttddV  tV  t| ds#tV  d S d S )N)WardAgglomerationFeatureAgglomerationTrM   	transform)&check_clusterer_compute_labels_predictrR   rS   check_clusteringr   r|   rf   r   )	clustererrl   rn   rn   ro   _yield_clustering_checks   s   

r   c                 c   sR    t | dr	tV  t | dr$tV  ttddV  tV  t| ddr$tV  tV  d S )Nfit_predictpredictTrM   rw   r   )rf   check_outliers_fit_predictcheck_outliers_trainr   ry   r;   r   r   )rk   rn   rn   ro   _yield_outliers_checks  s   


r   c                 c   s   | j j}t| }d|d vrtd||d t d S |d r,td|t d S t| D ]}|V  q0t| rDt	| D ]}|V  q>t
| rRt| D ]}|V  qLt| drat| D ]}|V  q[t| trpt| D ]}|V  qjt| r~t| D ]}|V  qxtV  |d stV  tV  tV  tV  tV  tV  tV  tV  tV  tV  |d stV  tV  t V  |d	 rt!V  |d
 rt"V  d S d S )N2darrayX_typesz8Can't test estimator {} which requires input  of type {}
_skip_testz2Explicit SKIP via _skip_test tag for estimator {}.r   non_deterministicrO   
requires_yrequires_positive_X)#rR   rS   r;   warningswarnformatr0   rp   r#   r   r$   r   rf   r   
isinstancer"   r   r%   r   &check_parameters_default_constructible%check_methods_sample_order_invariancecheck_methods_subset_invariancecheck_fit2d_1samplecheck_fit2d_1featurecheck_get_params_invariancecheck_set_paramscheck_dict_unchangedcheck_dont_overwrite_parameterscheck_fit_idempotentcheck_fit_check_is_fittedcheck_n_features_incheck_fit1dcheck_fit2d_predict1dcheck_requires_y_nonecheck_fit_non_negative)rk   rl   rm   checkrn   rn   ro   _yield_all_checks  sn   


r   c                 C   s   t | r(t| ts| jS | js| jjS ddd | j D }d| jj|S t	| drMt
dd tdd	t| W  d
   S 1 sFw   Y  d
S d
S )a  Create pytest ids for checks.

    When `obj` is an estimator, this returns the pprint version of the
    estimator (with `print_changed_only=True`). When `obj` is a function, the
    name of the function is returned with its keyword arguments.

    `_get_check_estimator_ids` is designed to be used as the `id` in
    `pytest.mark.parametrize` where `check_estimator(..., generate_only=True)`
    is yielding estimators and checks.

    Parameters
    ----------
    obj : estimator or function
        Items generated by `check_estimator`.

    Returns
    -------
    id : str or None

    See Also
    --------
    check_estimator
    ,c                 S   s   g | ]
\}}d  ||qS )z{}={})r   ).0kvrn   rn   ro   
<listcomp>v      z,_get_check_estimator_ids.<locals>.<listcomp>z{}({})r   T)print_changed_onlyz\s N)callabler   r   rS   keywordsfuncjoinitemsr   rf   r   resubstr)objkwstringrn   rn   ro   _get_check_estimator_idsW  s   

$r  c                 C   s  t | dg }t|r|dgdgfv rAt| tr| t }|S t| tr*| t }|S t| tr8| tdd}|S | t	dd}|S |dgfv rrt| tr_| d	td
dfdtddfgd}|S | d	t	d
dfdt	ddfgd}|S d| j
 d| }t|t t||  }|S )z)Construct Estimator instance if possible._required_parametersrk   base_estimatorr   random_stater   )C
estimatorsest1皙?alphaest2)r  zCan't instantiate estimator z parameters )getattrlen
issubclassr   r   r&   r   r,   r    r   rS   r   r   r0   r   )	Estimatorrequired_parametersrk   msgrn   rn   ro   _construct_instance}  sD   






r  c                 C   s4   t | |\}}|s| |fS |j| ||jj|ddS )N)reason)marks)_should_be_skipped_or_markedparammarkxfail)rk   r   pytestshould_be_markedr  rn   rn   ro   _maybe_mark_xfail  s   r  c                    sJ   t |\}|s|S t|tr|jjn|j t| fdd}|S )Nc                     s   t d  djj d )Nz	Skipping z for z: )r   rR   rS   )argskwargs
check_namerk   r  rn   ro   wrapped  s   z_maybe_skip.<locals>.wrapped)r  r   r   r   rS   r   )rk   r   should_be_skippedr"  rn   r   ro   _maybe_skip  s   r$  c                 C   s@   t |tr	|jjn|j}t| ddpi }||v rd|| fS dS )N_xfail_checksr   T)Fz*placeholder reason that will never be used)r   r   r   rS   r;   )rk   r   r!  xfail_checksrn   rn   ro   r    s
   r  c                    sH   ddl tdd  D rd}t| fdd}jjd| td	S )
a  Pytest specific decorator for parametrizing estimator checks.

    The `id` of each check is set to be a pprint version of the estimator
    and the name of the check with its keyword arguments.
    This allows to use `pytest -k` to specify which tests to run::

        pytest test_check_estimators.py -k check_estimators_fit_returns_self

    Parameters
    ----------
    estimators : list of estimators instances
        Estimators to generated checks for.

        .. versionchanged:: 0.24
           Passing a class was deprecated in version 0.23, and support for
           classes was removed in 0.24. Pass an instance instead.

        .. versionadded:: 0.24

    Returns
    -------
    decorator : `pytest.mark.parametrize`

    See Also
    --------
    check_estimator : Check if estimator adheres to scikit-learn conventions.

    Examples
    --------
    >>> from sklearn.utils.estimator_checks import parametrize_with_checks
    >>> from sklearn.linear_model import LogisticRegression
    >>> from sklearn.tree import DecisionTreeRegressor

    >>> @parametrize_with_checks([LogisticRegression(),
    ...                           DecisionTreeRegressor()])
    ... def test_sklearn_compatible_estimator(estimator, check):
    ...     check(estimator)

    r   Nc                 s       | ]}t |tV  qd S N)r   type)r   estrn   rn   ro   	<genexpr>      z*parametrize_with_checks.<locals>.<genexpr>uPassing a class was deprecated in version 0.23 and isn't supported anymore from 0.24.Please pass an instance instead.c                  3   s@     D ]} t | j}t| D ]}t||}t| |V  qqd S r(  )r)  rS   r   r   r  )rk   rl   r   r  r  rn   ro   checks_generator  s   

z1parametrize_with_checks.<locals>.checks_generatorzestimator, check)ids)r  any	TypeErrorr  parametrizer  )r  r  r/  rn   r.  ro   parametrize_with_checks  s   (r4  F
deprecatedc                    s    du r|dkrd}t ||dkrd}t|t | t tr'd}t|t j fdd}|r8| S | D ]$\ }z|  W q; ty_ } ztt	|t
 W Y d}~q;d}~ww dS )a  Check if estimator adheres to scikit-learn conventions.

    This function will run an extensive test-suite for input validation,
    shapes, etc, making sure that the estimator complies with `scikit-learn`
    conventions as detailed in :ref:`rolling_your_own_estimator`.
    Additional tests for classifiers, regressors, clustering or transformers
    will be run if the Estimator class inherits from the corresponding mixin
    from sklearn.base.

    Setting `generate_only=True` returns a generator that yields (estimator,
    check) tuples where the check can be called independently from each
    other, i.e. `check(estimator)`. This allows all checks to be run
    independently and report the checks that are failing.

    scikit-learn provides a pytest specific decorator,
    :func:`~sklearn.utils.parametrize_with_checks`, making it easier to test
    multiple estimators.

    Parameters
    ----------
    estimator : estimator object
        Estimator instance to check.

        .. versionadded:: 1.1
           Passing a class was deprecated in version 0.23, and support for
           classes was removed in 0.24.

    generate_only : bool, default=False
        When `False`, checks are evaluated when `check_estimator` is called.
        When `True`, `check_estimator` returns a generator that yields
        (estimator, check) tuples. The check is run by calling
        `check(estimator)`.

        .. versionadded:: 0.22

    Estimator : estimator object
        Estimator instance to check.

        .. deprecated:: 1.1
            ``Estimator`` was deprecated in favor of ``estimator`` in version 1.1
            and will be removed in version 1.3.

    Returns
    -------
    checks_generator : generator
        Generator that yields (estimator, check) tuples. Returned when
        `generate_only=True`.

    See Also
    --------
    parametrize_with_checks : Pytest specific decorator for parametrizing estimator
        checks.
    Nr5  zBEither estimator or Estimator should be passed to check_estimator.ze'Estimator' was deprecated in favor of 'estimator' in version 1.1 and will be removed in version 1.3.r-  c                  3   s.    t  D ]} t | }  t| fV  qd S r(  )r   r$  r   )r   rk   rl   rn   ro   r/  e  s
   
z)check_estimator.<locals>.checks_generator)r   r   r   FutureWarningr   r)  r2  rS   r   r   r0   )rk   generate_onlyr  r  r/  r   	exceptionrn   r6  ro   check_estimator  s0   7

r:  c                  C   s8   t d u rtddddddd\} }t | } | |fa t S )N   r   r         @   *   )	n_samples
n_featuresn_informativebiasnoiser  )REGRESSION_DATASETrC   r>   fit_transform)r   r   rn   rn   ro   _regression_datasetv  s   
rF  c                 C   sr  |   }| jj}d|v r|dkr| jdd d|v r^| jd ur)| jtd| jd |dv r3| jdd |d	kr=| jd
d | jjdkrJ| jddd |dv rT| jdd |dkr^| jdd d|v rh| jdd d|v rv| jtd| jd d|v r| jdd d|v r| jdd d|v r| jdd |dkr| jdd |d krd!| _|d"kr| jdd# t| d$rt| j	d| _	t| d%rd!| _
|d&kr| jd'd( |d)krd| _t| tr| jdd* t| tr| jd!d+ |d,v r| jdd- |d.kr| jd/d0 d1d2g}||vrt| d3r| jd4d5 t| d6r| jd4d7 |d8kr*| jd9d: |tv r7| jd!d* d S d S );Nn_iterTSNEr   rG  max_iterrJ  )	LinearSVR	LinearSVCr=  NMFi  MiniBatchNMFT)rJ  fresh_restarts)MLPClassifierMLPRegressord   MiniBatchDictionaryLearningn_resampling)rU  n_estimators)rV  
max_trialsr   )rW  n_initr
   )rX  
batch_size)rY  	MeanShift      ?)	bandwidthTruncatedSVDr   LassoLarsIC)noise_variance
n_clustersn_best	SelectFdr      ?r  TheilSenRegressor)n_components)r   )HistGradientBoostingClassifierHistGradientBoostingRegressor)min_samples_leafDummyClassifier
stratified)strategyRidgeCVRidgeClassifierCVcv   rn  n_splits)rq  OneHotEncoderignore)handle_unknown)r   rR   rS   
set_paramsrJ  minrV  re  rf   r`  ra  max_subpopulationr   r*   r+   ra   )rk   paramsrl   loo_cvrn   rn   ro   _set_checking_parameters  sv   






rz  c                   @   s*   e Zd ZdZdd Zd	ddZdd ZdS )
_NotAnArrayzvAn object that is convertible to an array.

    Parameters
    ----------
    data : array-like
        The data.
    c                 C   s   t || _d S r(  )r   asarraydata)selfr}  rn   rn   ro   __init__  s   z_NotAnArray.__init__Nc                 C   s   | j S r(  )r}  )r~  dtypern   rn   ro   	__array__  s   z_NotAnArray.__array__c                 C   s   |j dkrdS td|j )Nmay_share_memoryTz%Don't want to call array_function {}!)rS   r2  r   )r~  r   typesr  r  rn   rn   ro   __array_function__  s   
z_NotAnArray.__array_function__r(  )rS   r   __qualname____doc__r  r  r  rn   rn   rn   ro   r{    s
    
r{  c                 C   s   t | dd}t|dkS )zReturns True if estimator accepts pairwise metric.

    Parameters
    ----------
    estimator : object
        Estimator object to test.

    Returns
    -------
    out : bool
        True if _pairwise is set to True and False otherwise.
    metricNprecomputed)r  bool)rk   r  rn   rn   ro   _is_pairwise_metric  s   r  c                 C   s2   t |r
t| ddS t|}|d r|| | S | S )N	euclidean)r  rI   )r  r6   r;   )r   rk   kernelrm   rn   rn   ro   _pairwise_estimator_convert_X  s   
r  c                 c   s    | j dksJ d|  fV  dD ]
}|| |fV  q| d}|jd|_|jd|_d|fV  dD ]}| |}|jd|_|jd|_|d |fV  q6dS )	a;  Generate sparse matrices with {32,64}bit indices of diverse format.

    Parameters
    ----------
    X_csr: CSR Matrix
        Input matrix in CSR format.

    Returns
    -------
    out: iter(Matrices)
        In format['dok', 'lil', 'dia', 'bsr', 'csr', 'csc', 'coo',
        'coo_64', 'csc_64', 'csr_64']
    csr)doklildiabsrcsccoor  int64coo_64)r  r  _64N)r   copyasformatrowastypecolindicesindptr)X_csrsparse_formatX_coor   rn   rn   ro   _generate_sparse_matrix!  s   


r  c              
   C   s  t jd}|jdd}d||dk < t||}t|}d|jdd t}t	t
d t|}W d    n1 s;w   Y  t||}t|}t|D ]\}}t	t
d t|}| dv re|jd	d
 W d    n1 sow   Y  d|v rd|  d| d}	nd|  d}	tttfddgd|	dm t	t
d ||| W d    n1 sw   Y  t|dr||}
|d r|
j|jd dfksJ n|
j|jd fksJ t|dr||}|d r|jd df}n|jd df}|j|ksJ W d    n	1 sw   Y  qMd S )Nr   )(   ro  r   g?   r  r   )Scalerr>   F)	with_mean64r   z doesn't seem to support z_ matrix, and is not failing gracefully, e.g. by using check_array(X, accept_large_sparse=False)z doesn't seem to fail gracefully on sparse data: error message should state explicitly that sparse input is not supported if this is not the case.r   SparseTr   may_passr   r   rv   r   predict_probabinary_onlyr
   )r   r   r   uniformr  r   
csr_matrixr  intr   r7  r!   r   r;   r  ru  r   r2  r   r   rf   r   shaper  )rl   r   r   r   r  r   rk   rm   matrix_formatr   predprobsexpected_probs_shapern   rn   ro   rh   B  s^   








rh   c                 C   s   t |}zjdd l}tddgddgddgddgddgddgddgddgddgddgddgddgg}|t||}|g d}|dgd }t|dd	rT||}z|j|||d
 W W d S  t	yn   t	d
| w  tyy   tdw )Nr   r   r
   ro  r  r   r   r   r   r
   r
   r
   r
   r   r   r
   r
      rv   r   rH   zPEstimator {0} raises error if 'sample_weight' parameter is of type pandas.SerieszUpandas is not installed: not testing for input of type pandas.Series to class weight.)r!   pandasr   array	DataFramer  Seriesr;   r   r   r   ImportErrorr   )rl   r   rk   pdr   r   weightsrn   rn   ro   rW   x  sH   
rW   c                 C   s   t |}tddgddgddgddgddgddgddgddgddgddgddgddgg}tt||}tg d}tdgd }t|ddrPt|jd	d}|j|||d
 d S )Nr   r
   ro  r  r  r  rv   r   r  )	r!   r   r  r{  r  r;   r}  reshaper   )rl   r   rk   r   r   r  rn   rn   ro   rX     s,   rX   c                 C   sd   t |}tjd}d}t|j|dfd|}t|d }t||}dg| }|j|||d d S )Nr      ro  r   r  )	r!   r   r   r   r  r  aranger   r   )rl   r   rk   rndr?  r   r   rH   rn   rn   ro   rY     s   

rY   c                 C   s6  t |}tddgddgddgddgddgddgddgddgddgddgddgddgddgddgddgddgg}tg d}t||}|j||tt|d tt |j||tdt| d W d    n1 spw   Y  tt |j||tt|dfd W d    d S 1 sw   Y  d S )Nr   ro  r
   r  r   r   r   r   r
   r
   r
   r
   r   r   r   r   r
   r
   r
   r
   r  )	r!   r   r  r   r   rJ   r  r   r   )rl   r   rk   r   r   rn   rn   ro   rZ     s:   

 
 "rZ   rJ   c                 C   s  t |}t |}t|dd t|dd tjddgddgddgddgddgddgddgddgddgddgddgddgddgddgddgddggtjd}tjg dtd}|d	krl|}|}tjt|d
}	d|  d}
n<|dkrt||d g}t	|d| g}tjt|d d
}	d|	t|d < t
|||	dd\}}}	d|  d}
ntt||}t||}|j||d d |j|||	d dD ]}t||rt|||}t|||}t|||
d qd S )Nr   r  r   ro  r
   r  r  r  rJ   )r  zFor z; sample_weight=None is not equivalent to sample_weight=onesrL   z?, a zero sample_weight is not equivalent to removing the sample)r   rH   )r   r  decision_functionr   r   )r!   r   r   r  float64r  rJ   r  vstackhstackr9   r   r   r   rf   r  r   )rl   r   rK   
estimator1
estimator2X1y1X2y2sw2r   methodX_pred1X_pred2rn   rn   ro   r\     sf   




r\   c                 C   s   t |}t|dd tjddgddgddgddgddgddgddgddgddgddgddgddgddgddgddgddggtjd}tjg dtd}t||}t|jd }d	|d< |	 }|j
|||d
 |  d}t|||d d S )Nr   r  r   ro  r
   r  r  r  g      $@r  z8 overwrote the original `sample_weight` given during fitr  )r!   r   r   r  r  r  r   rJ   r  r  r   r   )rl   r   rk   r   r   sample_weight_originalsample_weight_fitr   rn   rn   ro   r[   :  s<   

r[   c                 C   s:  t jd}t|jdd|}|t}t|}|d d df d t}t	|}t
||}||| t|dr>|| t|drH|| ttddd	 |||t W d    n1 scw   Y  d
|d vrddi|d< d}tt|d ||| W d    d S 1 sw   Y  d S ||| d S )Nr   )r  r   r   r  r   r   zUnknown label typeTr   r  stringr   foobarr   r   z"argument must be a string.* numberr   )r   r   r   r  r  r  objectr;   r  r!   r   r   rf   r   r   r   	Exceptionr2  )rl   r   r   r   rm   r   rk   r  rn   rn   ro   r_   b  s,   





"r_   c                 C   s   t jd}|jddd|jdd  }|dd}|jdddd	d }t|}t|dd
 tt	dd |
|| W d    d S 1 sFw   Y  d S )Nr>  r   r   y              ?r  r   r   r
   lowhighr   r  zComplex data not supportedr  )r   r   r   r  r  randintr!   r   r   r   r   )rl   r   r   r   r   rk   rn   rn   ro   r^     s   "r^   c                 C   s   | dv rd S t jd}| dv rd|jdd }nd|jdd }t||}|d d df t}t|}t||}t	|drBd	|_
t	|d
rJd	|_t	|drRd	|_t|d	 ||| dD ]}t	||r}|j }t||| |j|ks}J d| q_d S )N)SpectralCoclusteringr   r   ro  r=  ro  r   r
   re  r   r`  ra  r   r   r  r  z$Estimator changes __dict__ during %s)r   r   r   r  r  r  r  r!   r   rf   re  r`  ra  r   r   __dict__r  r  )rl   r   r  r   r   rk   r  dict_beforern   rn   ro   r     s6   







r   c                 C   s   |  dp	| d S )N_)r   r   )attrrn   rn   ro   _is_public_parameter  s   r  c           	         s  t |jdrd S t|}tjd}d|jdd }t||}|d d df t	}t
||}t |dr7d|_t |dr?d|_t|d |j ||| |j d	d
   D }fdd
|D }|roJ dd|  fdd
|D }|rJ dd| d S )Ndeprecated_originalr   ro  r  r   re  r   r`  c                 S   s   g | ]}t |r|qS rn   )r  r   r   rn   rn   ro   r     
    z3check_dont_overwrite_parameters.<locals>.<listcomp>c                    s   g | ]
}|   vr|qS rn   )r   r  )dict_before_fitrn   ro   r     s    zEstimator adds public attribute(s) during the fit method. Estimators are only allowed to add private attributes either started with _ or ended with _ but %s added, c                    s    g | ]}|  | ur|qS rn   rn   r  dict_after_fitr  rn   ro   r     s
    zEstimator changes public attribute(s) during the fit method. Estimators are only allowed to change attributes started or ended with _, but %s changed)rf   r  r!   r   r   r   r  r  r  r  r   re  r`  r   r  r  r   r   r   )	rl   r   rk   r  r   r   public_keys_after_fitattrs_added_by_fitattrs_changed_by_fitrn   r  ro   r     sF   







r   c                 C   s   t jd}d|jdd }t||}|d d df t}t|}t||}t	|dr/d|_
t	|dr7d|_t|d ||| dD ]}t	||rWttd	t|||d  qDd S )
Nr   ro  r  r   re  r   r`  r  zReshape your data)r   r   r   r  r  r  r  r!   r   rf   re  r`  r   r   r   r   r  )rl   r   r  r   r   rk   r  rn   rn   ro   r     s&   





r   c                    s~    |}|j d  fdd|D }t|tkr&|d }ttdd |}t|r5|j}dd |D }t	|t	|fS )Nr   c                    s   g | ]
} | d qS )r   )r  )r   batchr   r@  rn   ro   r     r   z%_apply_on_subsets.<locals>.<listcomp>r   c                 S   s   | d S )Nr   rn   )xrn   rn   ro   <lambda>  s    z#_apply_on_subsets.<locals>.<lambda>c                 S      g | ]}|j qS rn   )A)r   r  rn   rn   ro   r         )
r  r)  tuplelistmapr   issparser  r   ravel)r   r   result_fullresult_by_batchrn   r  ro   _apply_on_subsets  s   

r  c           
      C   s   t jd}d|jdd }t||}|d d df t}t|}t||}t	|dr/d|_
t	|dr7d|_t|d ||| dD ] }d	j|| d
}t	||rdtt|||\}}	t||	d|d qDd S )Nr   ro  r  r   re  r   r`  r   r   r  score_samplesr  z={method} of {name} is not invariant when applied to a subset.r  rl   Hz>atolr   )r   r   r   r  r  r  r  r!   r   rf   re  r`  r   r   r   r  r  r   )
rl   r   r  r   r   rk   r  r  r  r  rn   rn   ro   r   $  s.   






r   c           	      C   s  t jd}d|jdd }t||}|d d df t j}t|ddr+d||dk< t|}t	||}t
|d	r<d|_t
|d
rDd|_t|d ||| t j|jd }dD ]$}dj|| d}t
||r~tt|||| t|||| d|d qZd S )Nr   ro  r  r   r  r   r   r
   re  r`  r  zY{method} of {name} is not invariant when applied to a datasetwith different sample order.r  &.>r  )r   r   r   r  r  r  r  r;   r!   r   rf   re  r`  r   r   permutationr  r   r   r  )	rl   r   r  r   r   rk   idxr  r  rn   rn   ro   r   J  s8   





r   c                 C   s   t jd}d|jdd }t||}|d d df t}t|}t||}t	|dr/d|_
t	|dr7d|_t|d | dkrF|jdd	 g d
}tt|dd ||| W d    d S 1 scw   Y  d S )Nr   ro  )r   r   r   re  r   r`  OPTICS)min_samples)z1 samplezn_samples = 1zn_samples=1z
one samplez1 classz	one classTr  )r   r   r   r  r  r  r  r!   r   rf   re  r`  r   ru  r   r   r   rl   r   r  r   r   rk   msgsrn   rn   ro   r   v  s"   




	"r   c                 C   s   t jd}d|jdd }t||}|d d df t}t|}t||}t	|dr/d|_
t	|dr7d|_| dkr>d|_| d	krEd
|_t||}t|d g d}tt|dd ||| W d    d S 1 slw   Y  d S )Nr   ro  )r   r   r   re  r   r`  RandomizedLogisticRegressionr   rc  )z1 feature\(s\)zn_features = 1zn_features=1Tr  )r   r   r   r  r  r  r  r!   r   rf   re  r`  sample_fractionresidual_thresholdr   r   r   r   r  rn   rn   ro   r     s(   





"r   c                 C   s   t jd}d|jdd }|t}t|}t||}t|dr$d|_	t|dr,d|_
t|d tt ||| W d    d S 1 sGw   Y  d S )Nr   ro  r=  r   re  r   r`  )r   r   r   r  r  r  r!   r   rf   re  r`  r   r   r   r   )rl   r   r  r   r   rk   rn   rn   ro   r     s   





"r   c                 C   sj   t dg dg dgdddd\}}t |}|| 8 }t||}|r,t||g\}}t| ||| d S Nr  r   r   r   r   r   r   r   r
   r
  r?  centersr  r@  cluster_std)rA   r>   rE  rv  r  r   _check_transformer)rl   r   rN   r   r   rn   rn   ro   r     s   

r   c                 C   s   t dg dg dgdddd\}}t |}|| d 8 }t||}t|}tt|}t| ||| t| ||	 |	  d S r  )
rA   r>   rE  rv  r  r{  r   r|  r  tolist)rl   r   r   r   this_Xthis_yrn   rn   ro   r     s   

r   c                 C   sZ   t  \}}t|}tttfd|  dd || W d    d S 1 s&w   Y  d S )NzThe unfitted transformer z\ does not raise an error when transform is called. Perhaps use check_is_fitted in transform.r  )rF  r!   r   AttributeErrorr   r   )rl   r   r   r   rn   rn   ro   r     s   
	"r   c                 C   sr  t |j\}}t|}t| | tv r8t jt |t |f }|d d ddf  d9  < t|tr7t|}n|}|	|| t|}|j
||d}	t|	tr_|	D ]}
|
jd |ks]J qRn	|	jd |kshJ t|dr/| tv r|||}|j
||d}n||}|j
||d}t|ddr| d }t|t|	trt|trt|	||D ]\}
}}t|
|d	d
| d t|
|d	d| d qn$t|	|d
| d	d t|	|d	d| d t||ksJ t||ksJ t|dr1t|dds3|jdkr5|jd dkr7ttd|  dd ||d d d df  W d    d S 1 s(w   Y  d S d S d S d S d S d S )Nr
   r   r   r   r   r   r    is non deterministic{Gz?z9fit_transform and transform outcomes not consistent in %sr  z7consecutive fit_transform outcomes not consistent in %s)r   r	  r  r   zThe transformer zr does not raise an error when the number of features in transform is different from the number of features in fit.r  r  )r   r|  r  r!   r   ra   c_r   r{  r   rE  r  rf   r   r;   r   zipr   r=   ndimr   r   )rl   transformer_origr   r   r?  r@  r   y_transformer_cloneX_predx_predr  X_pred3r  x_pred2x_pred3rn   rn   ro   r    s   




$.r  c                 C   s   t |ddr| d }t|tdg dg dgddd	d
\}}|| 8 }t||td}t|}t||}t| t	|}|
|| |
|| ddg}|D ] }t||d }	|	d urot||}
|	||}|
||}t|| qOd S )Nr   r   r   r  r  r  r   r
   r
  r  r  scorerE  )r;   r   rA   rv  r  r4   r!   r   r   r-   r   r  r   )rl   r   r  r   r   rk   pipelinefuncs	func_namer   func_pipelineresultresult_pipern   rn   ro   rb   b  s8   





rb   c                 C   s   t jd}d}|j|dfd}t||}t |d }t|}t||}t| g d}|D ];}t	||d }	|	d urj|	|| dd t
|	j D }
|
d dkrX|
d	d  }
|
d	 d
v sjJ d|t|j|
f q/d S )Nr   r  ro  r   )r   r.  partial_fitr   rE  c                 S   r  rn   )rl   r   prn   rn   ro   r     r  z+check_fit_score_takes_y.<locals>.<listcomp>r~  r   )r   YzJExpected y or Y as second argument for method %s of %s. Got arguments: %r.)r   r   r   r  r  r  r!   r   r   r  r   
parametersvaluesr)  rS   )rl   r   r  r?  r   r   rk   r0  r1  r   r  rn   rn   ro   rV     s.   


rV   c                 C   s   t jd}d|jddt j }t||}|t j}|t j}|t j	}|d d df }t
||}g d}||||fD ]"}	t|}
t|
d |
|	| |D ]}t|
|rat|
||	 qSq@d S )Nr   ro  )r=  r   r   r  r   )r   r   r   r  r  rr   r  r  r  int32r   r!   r   r   rf   r  )rl   r   r  
X_train_32
X_train_64X_train_int_64X_train_int_32r   methodsX_trainrk   r  rn   rn   ro   rU     s&   



rU   c                 C   s   t dg dg dgddd\}}t |}|| 8 }t||}t|ddD ]/}||}t|}t| |||}t	|t
rE|d }|j|ksVJ d	|j d
|j q'd S )Nr  r  r  r   r
  )r?  r  r  r  r   r   zEstimator transform dtype: z - original/expected dtype: )rA   r>   rE  rv  r  r;   r  r!   r   r   r  r  rS   )rl   r%  r   r   r  X_castr   X_transrn   rn   ro   r     s,   




r   c                 C   s   t |}t|d tddd}d|  d}tt|d ||g  W d    n1 s/w   Y  tddd}t|t	g d}d	}tt|d
 ||| W d    d S 1 saw   Y  d S )Nr   r   ro  The estimator zc does not raise a ValueError when an empty data is used to train. Perhaps use check_array in train.r  r  )r   r   r   r   r   r   r   r   r   r   r   r   zG0 feature\(s\) \(shape=\(\d*, 0\)\) while a minimum of \d* is required.r  )
r!   r   r   emptyr  r   r   r   r   r  )rl   r   eX_zero_samplesr   X_zero_featuresr   r  rn   rn   ro   r`     s   

"r`   c              
   C   s  t jd}t|jdd|}|jdd}t j|d< |jdd}t j|d< t d}d|d d< t||}d|  d}d|  d	}d|  d
}	||fD ]}
t	t
d| t|}t|d ttddg|d ||
| W d    n1 svw   Y  ||| t|drttddg|d ||
 W d    n1 sw   Y  t|drttddg|	d ||
 W d    n1 sw   Y  W d    n1 sw   Y  qKd S )Nr   r   ro  r   r  r   r   r   z& doesn't check for NaN and inf in fit.z* doesn't check for NaN and inf in predict.z, doesn't check for NaN and inf in transform.r   r   r   NaNr   r   r   )r   r   r   r  r  r   r   rJ   r   r   r7  r!   r   r   r   r   rf   r   r   )rl   r   r  X_train_finiteX_train_nanX_train_infr   error_string_fiterror_string_predicterror_string_transformrA  rk   rn   rn   ro   rc     sV   







rc   c                 C   s^   t ddd\}}t|}ttd|  dd ||| W d   dS 1 s(w   Y  dS )z8Test that error is thrown when non-square data provided.r=  r   )r?  r@  zThe pairwise estimator z+ does not raise an error on non-square datar  N)rA   r!   r   r   r   rl   r   r   r   rk   rn   rn   ro   rd   !  s   
"rd   c                 C   s@  g d}t dg dg dgdddd\}}|| 8 }t||td	}t|}|d
 rAtjd}|j|j	ddd}tj
|d|< t|}t||}t| ||| t|}	|j}
|
drpd|
v sp|
dspd|	v spJ t|	}t }|D ]}t||rt|||||< qz|D ]}t|||}t|| | qdS )z'Test that we can pickle all estimators.r  r  r  r  r   r
   r
  r  r-  rP   r>  r   F)replacer  r   r   r   s   versionN)rA   rv  r  r4   r;   r   r   r   choicer   r   r  r!   r   r   r   pickledumpsr   r   r   loadsdictrf   r  r   )rl   r   check_methodsr   r   rm   r   maskrk   pickled_estimatorr   unpickled_estimatorr3  r  unpickled_resultrn   rn   ro   ri   1  sD   
	




ri   c                 C   s   t |dsd S t|}tddd\}}|| 8 }t||}zt|r1t|}|j|||d n||| W n
 t	yB   Y d S w t
td|  dd ||d d d d	f | W d    d S 1 sgw   Y  d S )
Nr5  2   r   r?  r  classesrD  zZ does not raise an error when the number of features changes between calls to partial_fit.r  r  )rf   r!   rA   rv  r   r#   r   uniquer5  NotImplementedErrorr   r   )rl   r   rk   r   r   r`  rn   rn   ro   r|   f  s*   



"r|   c                 C   s  d\}}}t |}t|}td|||d\}}||| ||}|j||fks4J d||f|j|jjdks<J t	|drq|
|}	t|	tjsNJ |	j||fks`J d||f|	j|	dkt}
|j|
 }t|| t	|d	r||}t|tr|d
 st|D ]-}|| j|dfksJ d|df|| jttj|| ddt|d d |f  qn |d
 s|j||fksJ d||f|jt| t| t	|dr	t	|d	rt|D ]%}||d d |f }|
|}tt|t|d d |f  qd S d S d S )N)r>  r   ro  r>  )r  r?  n_labels	n_classesSThe shape of the prediction for multioutput data is incorrect. Expected {}, got {}.ir  zaThe shape of the decision function output for multioutput data is incorrect. Expected {}, got {}.r   r  
poor_scorer
   zTThe shape of the probability for multioutput data is incorrect. Expected {}, got {}.r   axis)r;   r!   rB   r   r   r  r   r  rK   rf   r  r   r   ndarrayr  r  classes_r   r  r  rangeargmaxroundr   )rl   rk   r?  rc  rd  rm   r   r   y_preddecisiondec_preddec_expy_probrf  y_proba
y_decisionrn   rn   ro   r}     sl   









$


 r}   c                 C   s   t |}d }}t|s|d }tdd||d\}}t||}||| ||}|jtdks:J d|j|j	|j	ksDJ dd S )	Nr   r   r>  r   )r  	n_targetsr?  r@  r  zbMultioutput predictions by a regressor are expected to be floating-point precision. Got {} insteadre  )
r!   r  rC   r  r   r   r  r   r   r  )rl   rk   r?  r@  r   r   ro  rn   rn   ro   r     s"   


r   c                 C   s  t |}tddd\}}t||dd\}}t |}tjd}t||j	dddd	g}|r:t
|||g\}}}|j\}}	t|d
rJ|jdd t| | dkr^|jdd |jdd || ||  |j}
|
j|fksuJ t|
|dks~J t|ddrd S t| tjdd ||}W d    n1 sw   Y  t|
| |
jtdtdfv sJ |jtdtdfv sJ ||}t|}t|t|d |d d  |d dv sJ t|d
rt|d
}|d |d ksJ d S d S )Nr]  r   r^     r  ro  )r   r
   r  r`  )r`  AffinityPropagationi)
preferencerS  rK  g?r   r   Trecordr;  r  r   r  )r   r  )r!   rA   r9   r>   rE  r   r   r   concatenater  r   r  rf   ru  r   r   r  labels_r(   r;   r   catch_warningsr   r   r  ra  r  r  )rl   clusterer_origrN   r   r   r   r   X_noiser?  r@  r  pred2labelslabels_sortedr`  rn   rn   ro   r     sP   







r   c                 C   sh   t ddd\}}t|}t| t|dr2|||}|jdd |||}t|| dS dS )z2Check that predict is invariant of compute_labels.r=  r   r^  compute_labelsF)r  N)rA   r!   r   rf   r   r   ru  r   )rl   r  r   r   r   r  r  rn   rn   ro   r     s   
r   c           
   	   C   s   d}d}t jd}|jdd}|jdd}t d}ttdA t|}tt	dd	|d
}	|
|| W d    n1 s>w   Y  |	jrO	 W d    d S t||||d W d    d S 1 sdw   Y  d S )Nz6Classifier can't train when only one class is present.z8Classifier can't predict when only one class is present.r   rI  r   r   r   classTr  r  )r   r   r   r  rJ   r   r7  r!   r   r   r   raised_and_matchedr   r   )
rl   classifier_origrN  rO  r  rA  X_testr   r   cmrn   rn   ro   rz   %  s&   
"rz   c                    s&   t dd t D   fdd| D S )Nc                 s   s4    | ]}|d  dkr| dd dkrdV  qdS )internal_apiopenblasarchitectureprescottTN)getlower)r   inforn   rn   ro   r+  ?  s    z-_create_memmap_backed_data.<locals>.<genexpr>c                    s   g | ]}t | d qS ))alignedr   )r   r  has_prescott_openblasrn   ro   r   F  s    
z._create_memmap_backed_data.<locals>.<listcomp>)r1  r7   )numpy_arraysrn   r  ro   _create_memmap_backed_data<  s   
r  r  c              	   C   s  t ddd\}}||}t||dd\}}t |}||dk }||dk }| dv r8|| 8 }|| 8 }|rFt||||g\}}}}||fg}t|}	|	d sZ|||f |D ]\}
}t	
|}t|}|
j\}}t|}t|
|}
t||}t| |	d	 sttd
|  dd ||
|d d  W d    n1 sw   Y  ||
| ||
 |  t|dsJ ||
}|j|fksJ |	d st||dksJ d}d}|	d	 s.|	d rtt|| dd ||
dd W d    n	1 sw   Y  n!tt|| dd ||
j W d    n	1 s)w   Y  t|drz||
}|dkrg|	d sN|j|fksMJ n
|j|dfksXJ | dkt}t|| n|j||fksqJ tt	j|dd| |	d	 s|	d rtt|| dd ||
dd W d    n	1 sw   Y  n!tt|| dd ||
j W d    n	1 sw   Y  W n
 t y   Y nw t|drt|!|
}|j||fksJ tt	j|dd| t"t	j#|ddt	$| |	d	 sS|	d r2tt|| dd |!|
dd W d    n	1 s,w   Y  n!tt|| dd |!|
j W d    n	1 sNw   Y  t|drt|%|
}t&|t	'|ddd tt	(|t	(| q\d S )N,  r   r^  rw  r  r
   )BernoulliNBMultinomialNBComplementNBCategoricalNBr  rO   The classifier  does not raise an error when incorrect/malformed input data for fit is passed. The number of training examples is not the same as the number of labels. Perhaps use check_X_y in fit.r  r  rk  rg  g(\?zuThe classifier {} does not raise an error when shape of X in  {} is not equal to (n_test_samples, n_training_samples)z|The classifier {} does not raise an error when the number of features in {} is different from the number of features in fit.rI   r   r   r  rv   rh  r  predict_log_proba   r
  )r	  ))rA   r  r9   r>   rE  rv  r  r;   appendr   ra  r  r  r!   r  r   r   r   r   r   r  rf   r   r'   r   r  Tr  r   r  r   rm  rb  r  r   sumrJ   r  r   logargsort)rl   r  rN   rt   X_my_my_bX_bproblemsrm   r   r   r`  rd  r?  r@  r   ro  msg_pairwiser  rp  rq  rs  
y_log_probrn   rn   ro   r~   L  s   






	
















r~   c                 C   sV   | |k r| }|d }n|}| d }t |}d}tt ||| dks)J |d S )Nr   zThe number of predicted outliers is not equal to the expected number of outliers and this difference is not explained by the number of ties in the decision_function values)r   sortr  ra  )num_outliersexpected_outliersrp  startendsorted_decisionr  rn   rn   ro   check_outlier_corruption  s   

&r  Tc              	   C   s  d}t |dd\}}t|dd}|rt|}|j\}}t|}t| || ||  ||}|j|fks<J |j	j
dksDJ tt|tddg ||}	||}
|	|
fD ]}|j	t	d	kskJ |j|fkssJ q_tt ||j W d    n1 sw   Y  |	dkt}d||dk< t|| tt ||j W d    n1 sw   Y  |
|j }t||	 tt ||j W d    n1 sw   Y  t|d
rAt|dsCd}|| }|j|d || ||}t|dk}||kr||}	t|||	 d}dD ])}|j|d tt|d || W d    n	1 s:w   Y  qd S d S d S )Nr  r   r^  rw  r  rf  r  r   floatcontaminationnoveltyr  r  "contamination must be in \(0, 0.5])      ffffff@r  )rA   r9   r   r  r!   r   r   r  r   r  rK   r   r   ra  r  r  r  r   r   r  r  r  offset_r   rf   ru  r  r  )rl   r   rN   r?  r   r  r@  rk   ro  rp  scoresoutputrq  y_decr  r  r  r  rn   rn   ro   r     sh   














r   c              	   C   s   t dddddddd\}}t|}|d d	 |d d	 }}|d	d  }| }t|}t|}	t|	 |	|||}
|	|||}|	|||}t|
| t|
| |
j	|j	ksaJ |
j	|j	ksiJ t
|
t
|kssJ t
|
t
|ks}J d S )
NrS  r
   r   ro  r]  Tr   r?  r@  rd  rc  lengthallow_unlabeledr  P   )rB   r?   r  r  r!   r   r   r   r   r  r)  )rl   r  r   r   rA  y_trainr  y_train_list_of_listsy_train_list_of_arraysr   ro  y_pred_list_of_listsy_pred_list_of_arraysrn   rn   ro   r   <	  s:   
	

r   c              	   C   s4  t |}t| d\}}}t|d|ddddd\}}t|}|d|  || d }}	|d|  || d }
}|||
 d	}t||d}|du rXt|  d
| d||	}t|tj	snJ |  dt
| d|j|jksJ |  d|j d|j d|j|jksJ |  d|j d|j ddS )zeCheck the output of the `predict` method for classifiers supporting
    multilabel-indicator targets.rS     r   r
   ro  r]  Tr   r  Nr    does not have a  method.z2.predict is expected to output a NumPy array. Got 	 instead.z(.predict outputs a NumPy array of shape  instead of .z>.predict does not output the same dtype than the targets. Got )r!   r   rB   r?   r   r  r   r   r   rj  r)  r  r  )rl   r  r   r?  	test_size	n_outputsr   r   rA  r  r  y_testresponse_method_namepredict_methodro  rn   rn   ro   r   e	  sL   

	r   c              	   C   s  t |}t| d\}}}t|d|ddddd\}}t|}|d|  || d }}	|d|  }
|||
 d	}t||d}|du rPt|  d
| d||	}t|trt	||ksoJ d|  dt	| d| d|D ]=}|j
|dfksJ d|  d|j
 d|df d|jjdksJ d|  d|j dd|  d}t|jddd|d qqdS t|tjr|j
||fksJ d|  d|j
 d||f d|jjdksJ d|  d|j dd|  d}td||d t|d|d dS tdt| d|  d)zkCheck the output of the `predict_proba` method for classifiers supporting
    multilabel-indicator targets.r  r
   ro  r]  Tr   r  Nr  r  r  zWhen zn.predict_proba returns a list, the list should be of length n_outputs and contain NumPy arrays. Got length of r  r  zx.predict_proba returns a list, this list should contain NumPy arrays of shape (n_samples, 2). Got NumPy arrays of shape fzW.predict_proba returns a list, it should contain NumPy arrays with floating dtype. Got r  z.predict_proba returns a list, each NumPy array should contain probabilities for each class and thus each row should sum to 1 (or close to 1 due to numerical errors).r   rh  r  zX.predict_proba returns a NumPy array, the expected shape is (n_samples, n_outputs). Got zN.predict_proba returns a NumPy array, the expected data type is floating. Got z.predict_proba returns a NumPy array, this array is expected to provide probabilities of the positive class and should therefore contain values between 0 and 1.zUnknown returned type z by z4.predict_proba. A list or a Numpy array is expected.)r!   r   rB   r?   r   r  r   r   r  r  r  r  rK   r   r  r   rj  r   r   r)  )rl   r  r   r?  r  r  r   r   rA  r  r  r  predict_proba_methodro  r  r   rn   rn   ro   r   	  s   

	


r   c              	   C   s   t |}t| d\}}}t|d|ddddd\}}t|}|d|  || d }}	|d|  }
|||
 d	}t||d}|du rPt|  d
| d||	}t|tj	sfJ |  dt
| d|j||fks}J |  d|j d||f d|jjdksJ |  d|j ddS )zoCheck the output of the `decision_function` method for classifiers supporting
    multilabel-indicator targets.r  r
   ro  r]  Tr   r  Nr  r  r  z<.decision_function is expected to output a NumPy array. Got r  z].decision_function is expected to provide a NumPy array of shape (n_samples, n_outputs). Got r  r  r  z?.decision_function is expected to output a floating dtype. Got )r!   r   rB   r?   r   r  r   r   r   rj  r)  r  r  rK   )rl   r  r   r?  r  r  r   r   rA  r  r  r  decision_function_methodro  rn   rn   ro   r   	  sL   

	r   c                 C   sl   t ddd\}}|| 8 }t||}t|}t||}|r&t||g\}}t| ||||u s4J dS )z+Check if self is returned when calling fit.r      r  r?  N)rA   rv  r  r!   r   r   r   r   )rl   r   rN   r   r   rk   rn   rn   ro   r]   
  s   

r]   c              	   C   s`   t  \}}t|}dD ]"}t||r-tt t||| W d   n1 s(w   Y  qdS )z}Check that predict raises an exception in an unfitted estimator.

    Unfitted estimators should raise a NotFittedError.
    )r  r   r  r  N)rF  r!   rf   r   r/   r  )rl   r   r   r   rk   r  rn   rn   ro   r   &
  s   


r   c                 C   s2  t |}tjd}d}t|j|dfd|}t|d }t||}t|}t	| |
|| ||}t	| tjdd!}	tdt tdt |
||d d tjf  W d    n1 sdw   Y  ||}
d	d
dd |	D  }|d st|	dksJ |d|v sJ t| |
  d S )Nr   r  ro  r   Tr{  alwaysrs  z)expected 1 DataConversionWarning, got: %sr  c                 S   s   g | ]}t |qS rn   r   )r   w_xrn   rn   ro   r   R
  s    z)check_supervised_y_2d.<locals>.<listcomp>rq   zPDataConversionWarning('A column-vector y was passed when a 1d array was expected)r;   r   r   r   r  r  r  r   r!   r   r   r   r   r  simplefilterr.   RuntimeWarningnewaxisr   r  r   r   )rl   r   rm   r  r?  r   r   rk   ro  w	y_pred_2dr  rn   rn   ro   r   ;
  s4   


r   c                 C   sv  t |}t|}|dkr| |  k} t| || | || }t|dr|| }t	|t j
s4J t|dkra| dkt}|j| }	t|	|d|dtt|	dtt|f d n/t|dd	d	krt j|d
dt}
|j|
 }t||d|dtt|dtt|f d |dkrtt |t | t||jd|dtt|dtt|jf d d S )Nr  r  r
   r   zKdecision_function does not match classifier for %r: expected '%s', got '%s'r  r  decision_function_shapeovrr   rh  r  z=Unexpected classes_ attribute for %r: expected '%s', got '%s')r   ra  r!   meanr   r   r   rf   r  r   rj  r  r   r  r  rk  r   r   r  r   r  rm  )r   r   rl   r  r`  r   ro  rp  rq  rr  
decision_yy_exprn   rn   ro   check_classifiers_predictions_
  sZ   





 
r  c                 C   s   | dv r|S |S )N)LabelPropagationLabelSpreadingSelfTrainingClassifierrn   )rl   r   y_namesrn   rn   ro    _choose_check_classifiers_labels
  s
   r  c                 C   s,  t dddd\}}t||dd\}}t |}|| d 8 }||dk }||dk }t||}t||}g d}d	d
g}t||}t||}	|||	fg}
t|dds^|
	|||f |
D ]\}}}||
dfD ]}t| ||}t||| | qlq`ddg}t||}	t| ||	}t||| | d S )Nr  r   r
  )r?  r  r  rw  r  r
   )onetwothreer  r  r  r   Or  r   )rA   r9   r>   rE  rv  r  r   taker;   r  r  r  r  )rl   r  X_multiclassy_multiclassX_binaryy_binarylabels_multiclasslabels_binaryy_names_multiclassy_names_binaryr  r   r   r  	y_names_ir&  rn   rn   ro   r{   
  s4   


r{   c                 C   s   t  \}}t|d d |}tjd}|jd|jd d}t||}tjd}t|}t|}t	| t	| | t
v rSt|d| |jdt|d g}|j}n|}||| ||}	|||t ||}
t|	|
d| d d S )Nr]  r   ro  r   r
   r!  r  )rF  r  r   r   r   r  r  r   r!   r   ra   r  r  r  r   r   r  r  r   )rl   regressor_origr   r  r  r   regressor_1regressor_2r&  pred1r  rn   rn   ro   r   
  s&   

$

r   c           
      C   sn  t  \}}||}t||}t|}t|}t||}| tv r<tj	d}t
|d| |jdt|d g}|j}n|}|rJt|||g\}}}t|dsWt|drWd|_| dkr^d|_ttd|  d	d
 |||d d  W d    n1 s}w   Y  t| ||| || |  ||}	|	j|jksJ t|dds|||dksJ d S d S )Nr   r
   r   alphasr  r!  PassiveAggressiveRegressorr  r  r  r  rg  r   rc  )rF  r  r  r?   r!   r   ra   r   r   r   r  r  r  r  r  rf   r  r  r   r   r   r   r  r   r  r;   r.  )
rl   r  rN   rt   r   r   r   r  r&  ro  rn   rn   ro   r   
  s@   



$
	
r   c                 C   sp   t jd}t|}|jdd}t||}t||d d df }||| g d}|D ]	}t||r5J q,d S )Nr   )r   r  r   )r  r  r  )	r   r   r   r!   normalr  r   r   rf   )rl   r  r   r   r   r   r0  r1  rn   rn   ro   r     s   
r   c                 C   sJ  t |ddr
dg}nddg}|D ]}t|ddd\}}t||ddd	\}}}}	t |d
dr7t||}t||}tt|}|dkrHddd}
ndddd}
t|j|
d}t	|dra|jdd t	|drl|jdd t	|drw|jdd t	|dr|jdd t
| ||| ||}t |ddst|dkdksJ qd S )Nr  r   r
   ro  r   r=  )r  r  r  rc  r  r  rI     g-C6?)r   r   )r   r   r
   rx   rG  rS  rI  rJ  rK  min_weight_fraction_leafr!  )r  n_iter_no_change)r  rg  gףp=
?)r;   rA   r1   r4   r  r   ra  r!   ru  rf   r   r   r   r  )rl   r  r  	n_centersr   r   rA  r  r  r  rx   r   ro  rn   rn   ro   r   +  s>   






r   c           
      C   s   t |}t|dr|jdd t|dr|jdd t| ||| ||}|jdd ||| ||}	t||	d	d
t||d	d
ksJJ d S )NrG  rS  rI  rJ  r  rK  balancedr  weighted)average)r!   rf   ru  r   r   r   r)   )
rl   r  rA  r  r  r  r  r   ro  y_pred_balancedrn   rn   ro   'check_class_weight_balanced_classifiersY  s   



r
  c           
      C   s   t ddgddgddgddgddgg}t g d}| }t|dr)|jdd	 t|d
r4|jdd t|dr?|jdd t| |jdd |||j }t|}t	tt 
|}|t |dk|  |t |dk|  d}|j|d |||j }	t||	d|  d dS )z4Test class weights with non-contiguous class labels.      r   gr[          )r   r   r   r  r  rG  r  rI  rJ  rK  rn  ro  rp  r  r  r   r  )r   r  z>Classifier %s is not computing class_weight=balanced properly.r  N)r   r  rf   ru  r   r   coef_r  r  r  ra  r  r   )
rl   
Classifierr   r   r   coef_balancedr?  rd  rx   coef_manualrn   rn   ro   -check_class_weight_balanced_linear_classifiero  s0   (



r  c                 C   s   t ddd\}}|| 8 }t||td}t|}t||}t| | }t|}|	|| | }|
 D ]\}}	|| }
t|
t|	ksTJ d| ||	|
f q8d S )Nr   r  r  r-  zTEstimator %s should not change or mutate  the parameter %s from %s to %s during fit.)rA   rv  r  r4   r!   r   r   r   r   r   r   joblibhash)rl   r   r   r   rk   rx  original_params
new_params
param_nameoriginal_value	new_valuern   rn   ro   re     s$   

re   c                 C   s   zt |}W n ty   td|  dw tt|jdr dS tt|j}tr7dD ]}||v r6|| q+dd dd	 t|jD D }t	t
|t	| t	| }|r`J d
| t|f dS )zCheck setting during init.r   z9 should store all parameters as an attribute during init.r  N)r   c                 S   s   g | ]	}|D ]}|qqS rn   rn   )r   params_parentr  rn   rn   ro   r     s    z3check_no_attributes_set_in_init.<locals>.<listcomp>c                 s   s    | ]}t |V  qd S r(  r   )r   parentrn   rn   ro   r+        z2check_no_attributes_set_in_init.<locals>.<genexpr>zaEstimator %s should not set any attribute apart from parameters during init. Found attributes %s.)r!   r  rf   r)  r  r   r	   remove__mro__setvarssorted)rl   r   rk   init_paramsr   parents_init_paramsinvalid_attrrn   rn   ro   rT     s0   


rT   c                 C   s   t ddgddgddgddgddgddgddgddgddgg	}t g d}t||}t|}||| ||}|  t|j	sGJ ||}t
|| tt|}t|j	saJ ||}t
|| d S )Nr  r   r
   )	r   r   r   r
   r
   r
   ro  ro  ro  )r   r  r   r!   r   r   rQ   r   r  r  r   rT  rV  rU  )rl   r   r   r   r*  	pred_origr  rn   rn   ro   rg     s2   




rg   c                 C   s   t ddgddgddgddgddgddgddgddgddgddgddgddgg}t||}t g d}t||}dD ]
}t| |||| q<d S )Nro  r   r   r
   r  )r   r   r   r
   r
   r
   r   r   r   r
   r
   r
   
NotAnArrayPandasDataframe)r   r  r  r   "check_estimators_data_not_an_arrayrl   r   r   r   obj_typern   rn   ro   ry     s*   

ry   c                 C   s<   t  \}}t||}t||}dD ]
}t| |||| qd S )Nr&  )rF  r  r   r)  r*  rn   rn   ro   r     s   


r   c                 C   s
  | t v rtdt|}t|}t| t| |dvr#td||dkr6tt|}tt|}n/z#dd l	}	t|}|j
dkrK|	|}n|	|}|	t|}W n tyd   tdw ||| ||}
||| ||}t|
|d| d	 d S )
NzoSkipping check_estimators_data_not_an_array for cross decomposition module as estimators are not deterministic.r&  zData type {0} not supportedr'  r   r   zDpandas is not installed: not checking estimators for pandas objects.r!  r  )ra   r   r!   r   r   r   r{  r   r|  r  r$  r  r  r  r   r   r   )rl   r   r   r   r+  estimator_1estimator_2r&  X_r  r  r  rn   rn   ro   r)  %  s<   




r)  c           
         s  |j }ttd t|}t| t| | |u sJ t|jd|j}zdd   fddt	|j
 D }W n ttfyK   Y W d    d S w | }|tt|dg d  }|D ]}|j|jksrJ d|jt|jf ttttttd ttjtjh	}|tj j!j"  t|j|v sJ d	|j d
|j dt|jj dt#dd |D  d	|j|$ vr|jd u sJ d|j d
|j dq^||j }t%|tj&rt'||j q^d|j d}	t(|r||ju sJ |	q^||jksJ |	q^W d    d S 1 sw   Y  d S )Nr   r  c                 S   s"   | j dko| j| jko| j| jkS )z*Identify hyper parameters of an estimator.r~  )rl   rK   VAR_KEYWORDVAR_POSITIONAL)r7  rn   rn   ro   param_filterm  s
   


z<check_parameters_default_constructible.<locals>.param_filterc                    s   g | ]} |r|qS rn   rn   r6  r1  rn   ro   r   u  r  z:check_parameters_default_constructible.<locals>.<listcomp>r  z(parameter %s for %s has no default valuezParameter 'z' of estimator 'z' is of type z which is not allowed. All init parameters have to be immutable to make cloning possible. Therefore we restrict the set of legal types to c                 s   s    | ]}|j V  qd S r(  )rS   )r   r)  rn   rn   ro   r+    s    z9check_parameters_default_constructible.<locals>.<genexpr>r  zEstimator parameter 'zT' is not returned by get_params. If it is deprecated, set its default value to None.z
Parameter z> was mutated on init. All parameters must be stored unchanged.))rR   r   r7  r  r!   reprru  r  r  r   r9  r:  r2  r   r   r  defaultrE  rl   r)  rS   r   r  r  r  r  r  FunctionTyper  Memoryupdater   corenumerictypesallTypesr  r   r   rj  r   r   )
rl   r  rk   initr!  rx  
init_paramallowed_typesparam_valuefailure_textrn   r2  ro   r   T  s|   



	

$r   c                 C   st   t | ddr|dt|  7 }t | ddr,|jdkr,t||jd k||jd d }t | ddr8t|dS |S )Nrequires_positive_yr   r   r  r   rv   )r  r   )r;   absrv  r   r   whereflatr  )rk   r   rn   rn   ro   r     s   "r   c                 C   sx   t | ddr||j}dt | ddv r|d d df }t | ddr(|| 8 }dt | ddv r:||  tj}|S )NrI   r   1darrayr   r   r   categorical)r;   dotr  rv  r  r   r;  )rk   r   rn   rn   ro   _enforce_estimator_tags_x  s   rG  c                 C   s   g d}|t 7 }| |v rd S | dkrt|jdd}nt|}t|drMt }|j|j}}t||}t|d t	||}|
|| t|jdksOJ d S d S )N)r   RidgeClassifierr   r   rM  r   r  	LassoLarsr  r  rJ  r   r   )ra   r!   ru  rf   r@   r}  targetr   r   r  r   r   alln_iter_)rl   r   not_run_check_n_iterrk   irisr   r&  rn   rn   ro   r     s"   	



r   c                 C   s   t |}t|drg| tv r*g dg dg dg dg}ddgdd	gdd
gddgg}ntdg dg dgdddd\}}|| d 8 }t|d ||| | tv r`|jD ]}|dks]J qUd S |jdksiJ d S d S )NrJ  )r  r  r[  )r[  r  r  )       @rO  rO  )rO  r<  g      @r
  gɿg?g?r  g333333?r  r  r  r   r
   r  r   )r!   rf   ra   rA   rv  r   r   rL  )rl   r   rk   r   r&  iter_rn   rn   ro   r     s,   



r   c                    sB   t |}|jdd}|jdd t fdd| D sJ d S )NFdeepTc                 3   s    | ]	}|   v V  qd S r(  )r   )r   itemdeep_paramsrn   ro   r+  +      z.check_get_params_invariance.<locals>.<genexpr>)r!   r   rK  r   )rl   r   rF  shallow_paramsrn   rT  ro   r   #  s   "r   c                 C   s  t |}|jdd}d}|jdi | |jdd}t| t| ks*J || D ]\}}|| |u s<J |q.tj tjd g}t|}	| D ]}
||
 }|D ]}||	|
< z
|jdi |	 W n_ t	t
fy } zQ|jj}td||
|  d|}|}|jdd}z!t| t| ksJ | D ]\}}|| |u sJ qW n ty   t| Y nw W Y d }~qUd }~ww |jdd}t|	 t| ksJ || D ]\}}|	| |u sJ |qqU||	|
< qMd S )NFrQ  z>get_params result does not match what was passed to set_paramszn{0} occurred during set_params of param {1} on {2}. It is recommended to delay parameter validation until fit.z9Estimator's parameters changed after set_params raised {}rn   )r!   r   ru  r  r   r   r   r   r   r2  r   rR   rS   r   r   r   AssertionError)rl   r   rk   orig_paramsr  curr_paramsr   r   test_valuestest_paramsr  default_valuer   rF  e_typechange_warning_msgparams_before_exceptionrn   rn   ro   r   .  s^    

 
r   c                 C   s|   t  \}}|d t|jdd }t|}d}t|dds<tt|d ||| W d    d S 1 s5w   Y  d S d S )Nr   r   rh  zUnknown label type: rO   r   r  )rF  rA  rv  r!   r;   r   r   r   )rl   r   r   r   rF  r  rn   rn   ro   r   g  s   
"r   c                 C   s   ddg}t ddd|ddd\}}t||d	dd
\}}}}t|}	t|	drSt|	drU|	|| |	|d d df jdd}
|	|jdd}tt	|
t	| d S d S d S )N)r
   r
   )r  r  rS  r   r  r[  T)r?  r  r@  r  r  r9   皙?r   r  r  r   r   )decimals)
rA   r1   r!   rf   r   r  rn  r  r   r   )rl   r   r  r   r   rA  r  r  r  rk   abrn   rn   ro   r   u  s&   
r   c              	   C   s`  d}t |dd\}}t|dd}|j\}}t|}t| ||}|j|fks*J |jjdks2J tt	
|t	ddg t|d	rQ|||}t|| t|d
rd}	t|	| }
|j|
d ||}t	|dk}||	krt|dr||}t||	| d}dD ]%}
|j|
d tt|d || W d    n1 sw   Y  qd S d S )Nr  r   r^  rw  r  rf  r  r   r   r  r  r  r  r  )r  gMbPgX ?r  r  )rA   r9   r  r!   r   r   r  rK   r   r   ra  r  rf   r   r   r  ru  r  r  r  r   r   )rl   r   r?  r   r  r@  rk   ro  y_pred_2r  r  r  rp  r  rn   rn   ro   r     sB   







r   c                 C   sf   t ddgddgg}t ddg}t|}tt ||| W d    d S 1 s,w   Y  d S )Nr  r   r
   )r   r  r!   r   r   r   rQ  rn   rn   ro   r     s   
"r   c              	      s  g d}t jd}t|t d  v r jdd d}|jd|dfd}t	|}t
|r;|j|d	}n|jdd|d
}t|}ttd|d|\}}t|||\}	}
t||||\ }|	|
  fdd|D }t |	|
 |D ]=}t|rt| }t |jt jrdt |jj }n	dt t jj }t|| |t|dt|dd|d qd S )Nr  r   
warm_startFrf  rS  r
   locr   r   r  ra  r   c                    s&   i | ]}t |r|t| qS rn   )rf   r  )r   r  r  rk   rn   ro   
<dictcomp>  s    z(check_fit_idempotent.<locals>.<dictcomp>r
  r  z&Idempotency check failed for method {})r	  rtolr   )r   r   r   r!   r   r   r   ru  r  r  r$   r  r   nextr2   splitr3   r   rf   r  
issubdtyper  floatingfinfoepsr  r   maxr   )rl   r   rX  r   r?  r   r   traintestrA  r  r  r3  r  
new_resulttolrn   rj  ro   r     sJ   


r   c              
   C   s   t jd}t|}t| d| v r|jdd d}|jd|dfd}t||}t	|r5|j|d}n|j
d	d|d
}t||}t|ddsazt| t|jj d ty`   Y nw ||| zt| W d S  ty } ztd|d }~ww )Nr>  rf  Frg  rS  r
   rh  r   r   r  r   z) passes check_is_fitted before being fit!zFEstimator fails to pass `check_is_fitted` even though it has been fit.)r   r   r   r!   r   r   ru  r  r  r$   r  r   r;   r  r8   rX  rR   rS   r/   r   )rl   r   r   rk   r?  r   r   rF  rn   rn   ro   r     s@   

r   c                 C   s   t jd}t|}t| d| v r|jdd d}|jd|dfd}t||}t	|r5|j|d}n|j
dd|d	}t||}t|d
rIJ ||| t|d
sVJ |j|jd ks`J d S )Nr   rf  Frg  rS  r
   rh  r   r  n_features_in_r   )r   r   r   r!   r   r   ru  r  r  r$   r  r   rf   r   rx  r  )rl   r   r   rk   r?  r   r   rn   rn   ro   r   2  s    

r   c              
      s   t jd}t|}t| d}|jd|dfd}t||}d}z	||d  W d S  tyI   zt	 fdd|D s> W Y d   d S d   ww )Nr   rS  r
   rh  )z1requires y to be passed, but the target y is Nonez<Expected array-like (array or non-string sequence), got Nonezy should be a 1d arrayc                 3   s    | ]	}|t  v V  qd S r(  r  )r   r  vern   ro   r+  b  rV  z(check_requires_y_none.<locals>.<genexpr>)
r   r   r   r!   r   r  r  r   r   r1  )rl   r   r   rk   r?  r   expected_err_msgsrn   ry  ro   r   L  s   
r   c              	   C   s  t |}d|d v pd|d v }|r|d rd S tjd}t|}t| d| v r2|jdd d	}|j|d
fd}t	||}t
||}t|rQ|j|d}n|jdd|d}t||}||| |j|jd ksnJ g d}	|d d dgf }
d|jd  d}|	D ]1}t||sqt||}|dkrt||d}tt|d ||
 W d    n1 sw   Y  qt|dsd S t|}t|r|j||t|d n||| |j|jd ksJ tt|d ||
| W d    d S 1 sw   Y  d S )Nr   r   rE  rO   r   rf  Frg     r  r   r
   r  r   )r   r   r  r  r.  z'X has 1 features, but \w+ is expecting z features as inputr.  r  r  r5  r_  )r;   r   r   r   r!   r   r   ru  r  rG  r  r$   r  r   r   rx  r  rf   r  r   r   r   r#   r5  ra  )rl   r   rm   is_supported_X_typesr   rk   r?  r   r   rX  X_badr  r  callable_methodrn   rn   ro   !check_n_features_in_after_fittingf  sV   






"r  c                 C   s`   t |}t|dsd S t|  }tt }|||ks.J |  d|||  d S )N	_get_tagsz@._get_tags() is missing entries for the following default tags: )r!   rf   r  r  r   r:   intersection)rl   r   rk   	tags_keysdefault_tags_keysrn   rn   ro   rj     s   
rj   c                 C   sP  zdd l }W n ty   tdw t|}d|d v p!d|d v }|r(|d r*d S tjd}t|}t| |j	dd}||
 d	 8 }t||}t||}|j\}}	td
d t|	D }
|j||
d}t|rs|j	|d}n|jdd|d}t||}t  tjddtdd ||| W d    n1 sw   Y  t|dstdt|jtjsJ |jjtksJ t |j|
 |j!}|"drd|v s|#dsd|j$vrtd|  dg }dD ]}t||sqt%||}|dkrt&||d}|'||f q|D ]'\}}t  tjddtdd || W d    n	1 s'w   Y  q|
d d d dfdd t|	D d f|
d d! d"t
|
d!d   d#fg}d$d% |( ) D }t*d&d' |+ D }|D ]\}}|j||d}t,-d(| }|D ]A\} }t / tjdt.dd) t/t.||  d*d+ || W d    n	1 sw   Y  W d    n	1 sw   Y  qt|d,r|r͐qkt|}t0|rt1|}|j2|||d- n|2|| t - tjdt.dd) t/t.|d. |2|| W d    n	1 sw   Y  W d    n	1 sw   Y  qkd S )/Nr   Hpandas is not installed: not checking column name consistency for pandasr   r   rE  rO   )r|  r  r   rc  c                 S      g | ]}d | qS )col_rn   r   rf  rn   rn   ro   r         z<check_dataframe_column_names_consistency.<locals>.<listcomp>columnsr
   r  errorz#X does not have valid feature namessklearn)messager   modulefeature_names_in_zTEstimator does not have a feature_names_in_ attribute after fitting with a dataframer   r   r   r   z2 does not document its feature_names_in_ attribute)r   r   r  r  r.  r  r  r.  r  r  z<Feature names must be in the same order as they were in fit.c                 S   r  )another_prefix_rn   r  rn   rn   ro   r     r  zHFeature names unseen at fit time:
- another_prefix_0
- another_prefix_1
ro  z3Feature names seen at fit time, yet now missing:
- 
c                 S   s   i | ]\}}d |v r||qS )early_stoppingrn   )r   r   r   rn   rn   ro   rk  '  s
    z<check_dataframe_column_names_consistency.<locals>.<dictcomp>c                 s   s    | ]}|d u V  qdS )TNrn   )r   r   rn   rn   ro   r+  ,  r  z;check_dataframe_column_names_consistency.<locals>.<genexpr>zqThe feature names should match those that were passed during fit. Starting version 1.2, an error will be raised.
)r   r  z did not raiser   r5  r_  r  )3r  r  r   r;   r   r   r   r!   r   r  rv  rG  r  r  r  rl  r  r$   r  r   r   r  filterwarningsUserWarningr   rf   r   r   r  rj  r  r  r   r   r   r   r  r  r   r  r   r   r1  r:  r   escaper7  r   r#   ra  r5  )rl   r   r  rm   r}  r   rk   X_origr?  r@  namesr   r   r   rX  r  r  r  invalid_namesrx  early_stopping_enabledinvalid_nameadditional_messager~  expected_msgr`  rn   rn   ro   (check_dataframe_column_names_consistency  s   





	


	










r  c                 C   s  |  }d|d vs|d rd S tdg dg dgddd	d
\}}t |}|| 8 }t|}t||}t||}|jd }t	| |}| t
v rdtjt|t|f }|d d ddf  d9  < |j||d}dd t|D }	ttdd ||	d d d  W d    n1 sw   Y  ||	}
|
d usJ t|
tjsJ |
jtksJ tdd |
D sJ t|tr|d jd }n|jd }t|
|ksJ d| dt|
 d S )Nr   r   rO   r  r  r  r   r
   r
  r  r   r  c                 S   r  )featurern   r  rn   rn   ro   r   q  r  z;check_transformer_get_feature_names_out.<locals>.<listcomp>z'input_features should have length equalr  c                 s   r'  r(  )r   r   )r   rl   rn   rn   ro   r+  {  r,  z:check_transformer_get_feature_names_out.<locals>.<genexpr>	Expected  feature names, got )r  rA   r>   rE  rv  r!   rG  r  r  r   ra   r   r"  r|  rl  r   r   get_feature_names_outr   rj  r  r  rK  r  r  )rl   r%  rm   r   r   r   r@  r&  X_transforminput_featuresfeature_names_outn_features_outrn   rn   ro   'check_transformer_get_feature_names_outU  sJ   






r  c                 C   s  zdd l }W n ty   tdw | }d|d vs |d r"d S tdg dg dgdd	d
d\}}t |}|| 8 }t|}t	||}t
||}|jd }t| |}| tv rvtjt|t|f }|d d d	df  d	9  < dd t|D }	|j||	d}
|j|
|d}dd t|D }ttdd || W d    n1 sw   Y  | }||	}t|| t|tr|d jd }n|jd }t||ksJ d| dt| d S )Nr   r  r   r   rO   r  r  r  r
   r
  r  r   c                 S   r  )r  rn   r  rn   rn   ro   r     r  zBcheck_transformer_get_feature_names_out_pandas.<locals>.<listcomp>r  r  c                 S   r  )badrn   r  rn   rn   ro   r     r  z0input_features is not equal to feature_names_in_r  r  r  )r  r  r   r  rA   r>   rE  rv  r!   rG  r  r  r   ra   r   r"  r|  rl  r  r   r   r  r   r   r  r  )rl   r%  r  rm   r   r   r   r@  r&  feature_names_indfr  invalid_feature_namesfeature_names_out_defaultfeature_names_in_explicit_namesr  rn   rn   ro   .check_transformer_get_feature_names_out_pandas  s\   






r  )NFr5  )rJ   )F)Fr  )T)r  r   rT  r   r  r   	functoolsr   r   inspectr   numpyr   scipyr   scipy.statsr   r  r   r	   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   linear_modelr   r   r   r   r    baser!   r"   r#   r$   r%   r&   metricsr'   r(   r)   random_projectionr*   feature_selectionr+   r,   r/  r-   
exceptionsr.   r/   r0   model_selectionr1   r2   model_selection._validationr3   metrics.pairwiser4   r5   r6   utils.fixesr7   utils.validationr8   r9   _tagsr:   r;   
validationr<   r=   preprocessingr>   r?   datasetsr@   rA   rB   rC   rD  ra   rp   r   r7  r   r   r   r   r   r   r  r  r  r$  r  r4  r:  rF  rz  r{  r  r  r  rh   rW   rX   rY   rZ   r\   r[   r  r_   r^   r   r  r   r   r  r   r   r   r   r   r   r   r   r  rb   rV   rU   r   r`   rc   rd   ri   r|   r}   r   r   r   rz   r  r~   r  r   r   r   r   r   r]   r   r   r  r  r{   r   r  r   r   r   r
  r  re   rT   rg   ry   r   r)  r   r   rG  r   r   r   r   r   r   r   r   r   r   r   r   r  rj   r  r  r  rn   rn   rn   ro   <module>   s    	4#
"9&,>]i!6
+


$D(
!
'
:

%
+
$



\
!



0

4

<
;

 O
(
,
S
-

#
<
%
2

-

(
#
#
"


.b
*



8

2
:'E 2