
    0Ph             
      $   d Z ddlmZ 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mZmZ ddlmZ ddlmZmZ dd	lmZmZ ddlZddlZdd
lmZ ddlmZ ddlmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( ddl)m*Z* ddl+m,Z,m-Z-m.Z.m/Z/m0Z0 ddl1m2Z2m3Z3m4Z4m5Z5m6Z6 ddl7m8Z8m9Z9m:Z:m;Z; ddl<m=Z= ddl>m?Z?m@Z@mAZA ddlBmCZCmDZDmEZE ddlFmGZGmHZHmIZI ddlJmKZK ddlLmMZM ddlNmOZOmPZP ddlQmRZR ddlSmTZTmUZUmVZVmWZW ddlSmXZY ddlZm[Z[m\Z\m]Z] ddl)m^Z^ ddl_m`Z` dd lambZbmcZcmdZd dd!lemfZfmgZgmhZhmiZimjZjmkZk dd"llmmZmmnZnmoZo dd#lpmqZqmrZrmsZsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{m|Z| dd$l}m~Z~ dd%lmZmZmZ dad& Zd' Zd( Zd) Zd* Zd+ Zd, Zd- Zd. Zdd1Zd2 Z	 	 	 ddd7Z	 ddd:Zd;ddd<dd=Zd;dd>dd@Z eddAgdAgedg ecdBh          dg ecdCdBh          dgedgdDdEF          	 	 dd;ddBdCddGddM            ZdN Z G dO dP          ZdQ ZdR Z ezeS          dT             Z	 	 	 ddVZ	 	 ddWZdX ZdY ZdZ Zd[ Zd\ Z ezeS          d]             Z ezeS          d^             Z ezeS          d_             Z ezeS          d`             Z ezeS          da             Zdb Zdc Zdd Z ezeefS          de             Zdf Zezdg             Zdh Z ezeS          di             Z ezeS          dj             Zdk Z ezeS          dl             Z ezeS          dm             Zezdn             Zezdo             Zezdp             Z ezeS          ddq            Z ezeS          dr             Z ezeS          ds             Z ezeS          dt             Zdu Zezdv             Zezdw             Zezdx             Zezdy             Zdz Z ezeS          d{             Z ezeS          d|             Zezd}             Zezdd~            Z ezeS          d             Z ezeS          d             Z ezeS          d             Z ezeS          dd            Z ezeS          d             Z ezeS          d             Z ezeS          d             Zez	 dd            Zd ZddZd Z ezeS          d             Z ezeS          d             Z ezeS          d             Z ezeS          d             Z ezeS          d             Z ezeS          d             Z ezeS          d             Zezd             Z ezeS          d             Zezd             Zd Zd Z ezeS          d             Z ezeS          dEej        fd            Zezd             Z ezeS          d             Z ezeS          d             Z ezeS          d             Z ezeS          d             Z ezeS          d             Z ezeS          d             Z ezeS          d             Z ezeS          d             Z ezeS          d             Zd Zd Zd Zd ZdeCfdZ ezeS          d             Z ezeS          d             Z ezeS          d             Z ezeS          d             Z ezeS          d             Z ezeS          d             Z ezeS          d             Zd Zd Zd Zd Zd Zd Z ezeS          d             Zd Zd Zd Zd Z d Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
dÄ ZdĄ Z ezeS          dń             ZdƄ ZdǄ ZdS )zQVarious utilities to check the compatibility of estimators with scikit-learn API.    )annotationsN)nullcontext)deepcopy)partialwraps)	signature)IntegralReal)CallableLiteral)sparse)rankdata)BaseEstimatorBiclusterMixinClassifierMixinClassNamePrefixFeaturesOutMixinDensityMixinMetaEstimatorMixinMultiOutputMixinOneToOneFeatureMixinOutlierMixinRegressorMixinTransformerMixin   )config_context)ClusterMixincloneis_classifieris_outlier_detectoris_regressor)	load_iris
make_blobsmake_classificationmake_multilabel_classificationmake_regression)DataConversionWarningEstimatorCheckFailedWarningNotFittedErrorSkipTestWarning)LinearClassifierMixin)accuracy_scoreadjusted_rand_scoref1_score)linear_kernelpairwise_distances
rbf_kernel)LeaveOneGroupOutShuffleSplittrain_test_split)_safe_split)make_pipeline)StandardScalerscale)_safe_indexing)_atol_for_type_convert_to_numpyget_namespace)yield_namespace_device_dtype_combinationsdevice)InvalidParameterErrorgenerate_invalid_param_valmake_constraint   )shuffle)is_scalar_nan)Interval
StrOptionsvalidate_params)ClassifierTags	InputTagsRegressorTags
TargetTagsTransformerTagsget_tags)CROSS_DECOMPOSITION_get_check_estimator_ids_yield_instances_for_check)SkipTest_array_api_for_tests	_get_argsassert_allcloseassert_allclose_dense_sparseassert_array_almost_equalassert_array_equalassert_array_lesscreate_memmap_backed_dataignore_warningsraisesset_random_state)SPARSE_ARRAY_PRESENT)_num_samplescheck_is_fittedhas_fit_parameterc                    t          |           }|j                            dd          }t          ||          3t	          d| j        j         d| d| d|j         d|j         d          d S )	NMixin 
Estimator z seems to be a z, but the `zB` tag is not set. Either set the tag manually or inherit from the z2. Note that the order of inheritance matters, the z" should come before BaseEstimator.)rM   __name__replacegetattrRuntimeError	__class__)	estimatortag_namerb   tagsestimator_types        ^/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/utils/estimator_checks.py_raise_for_missing_tagsro   r   s    ID^++GR88NtX&P,5 P Pn P P!P P$)NP P #^P P P
 
 	
 '&    c              #    K   t          | t                    s)t          j        d| j        j         dt                     t          |           }t          V  t          V  t          V  t          V  t          V  t          V  t          V  t          V  t           V  t"          V  |j        r	t&          V  t(          V  t*          V  t,          V  t.          V  d S )Nrd   z does not inherit from `sklearn.base.BaseEstimator`. This might lead to unexpected behavior, or even errors when collecting tests.category)
isinstancer   warningswarnri   re   UserWarningrM   check_estimator_cloneablecheck_estimator_tags_renamedcheck_valid_tag_typescheck_estimator_reprcheck_no_attributes_set_in_initcheck_fit_score_takes_y!check_estimators_overwrite_paramscheck_dont_overwrite_parameters!check_estimators_fit_returns_selfcheck_readonly_memmap_inputrequires_fitcheck_estimators_unfitted/check_do_not_raise_errors_in_init_or_set_params!check_n_features_in_after_fittingcheck_mixin_order"check_positive_only_tag_during_fit)rj   rl   s     rn   _yield_api_checksr   ~   s&     i// 
2,5 2 2 2 !		
 	
 	
 	
 ID
####
&&&&


))))
!!!!
++++
))))
++++
%%%% (''''
9999
++++

,,,,,,rp   c              #    K   | j         j        }t          |           }t          V  t	          | d          rKt
          V  t          V  t          V  |j        j	        s$t          V  t          V  t          V  t          V  |j        st          V  t           V  t"          V  |t$          vr	t&          V  |j        j        s|j        s	t*          V  |j        j	        r	t,          V  t/          | d          r	t0          V  t2          V  t4          V  t6          V  t8          V  t;          t8          d          V  |j        rt?          |           D ]}|V  t@          V  d S )Nsample_weightsparsifyTreadonly_memmap)!ri   re   rM   check_estimators_dtypesr`   "check_sample_weights_pandas_series!check_sample_weights_not_an_arraycheck_sample_weights_list
input_tagspairwisecheck_sample_weights_shape$check_sample_weights_not_overwritten-check_sample_weight_equivalence_on_dense_data.check_sample_weight_equivalence_on_sparse_datano_validationcheck_complex_datacheck_dtype_object$check_estimators_empty_data_messagesrN   check_pipeline_consistency	allow_nancheck_estimators_nan_infcheck_nonsquare_errorhasattrcheck_sparsify_coefficientscheck_estimator_sparse_tagcheck_estimator_sparse_arraycheck_estimator_sparse_matrixcheck_estimators_pickler   array_api_support_yield_array_api_checks"check_f_contiguous_array_estimator)rj   namerl   checks       rn   _yield_checksr      s     'DID
!!!!O44 A0000////''''' 	A,,,,6666???? A@@@  3        2222&&&((((?$ 'T-? '&&&& $####y*%% *))))
$$$$
&&&&
'''' "!!!
)4
@
@
@@@@ ,Y77 	 	EKKKK
,,,,,,rp   c              #    K   t          | dt                     t          |           }t          V  t          V  t
          V  t          V  t          V  |j        j	        r	t          V  t          V  t          t          d          V  t          t          dd          V  t          V  |j        j        r$t           V  t"          V  t$          V  t&          V  |j        st*          V  |j        j        r	t.          V  d|                                                                 v r	t4          V  t6          V  t8          V  t;          | t<                    r1d|                                                                 v r	t>          V  t;          | t<                    r1d|                                                                 v r	t>          V  |j        j         stB          V  d S d S )Nclassifier_tagsTr   float32r   X_dtypeclass_weight)"ro   r   rM   "check_classifier_data_not_an_arraycheck_classifiers_one_label*check_classifiers_one_label_sample_weightscheck_classifiers_classes'check_estimators_partial_fit_n_featurestarget_tagsmulti_outputcheck_classifier_multioutputcheck_classifiers_trainr   #check_classifiers_regression_targetr   multi_label6check_classifiers_multilabel_representation_invariance2check_classifiers_multilabel_output_format_predict8check_classifiers_multilabel_output_format_predict_proba<check_classifiers_multilabel_output_format_decision_functionr   check_supervised_y_no_nansingle_outputcheck_supervised_y_2d
get_paramskeyscheck_class_weight_classifiers'check_non_transformer_estimators_n_iter check_decision_proba_consistencyrt   r*   -check_class_weight_balanced_linear_classifiermulti_class*check_classifier_not_supporting_multiclass)
classifierrl   s     rn   _yield_classifier_checksr      s2     J(9?KKKJD -,,,
%%%%
4444
####
1111$ +****
!!!!
)4
@
@
@@@@
)4
S
S
SSSS
----' KDDDD@@@@FFFFJJJJ ('''') 	(''''..00557777,,,,
1111
*****344 @Z224499;;;;????:455<j3355::<<<<;;;;+ 98888889 9rp   c              #    K   t          | dt                     t          |           }t          V  t	          t          d          V  t	          t          dd          V  t
          V  t          V  |j        j        r	t          V  t          V  |j        s|j        j        r	t          V  t          V  | j        j        }|dk    r	t"          V  t$          V  d S )Nregressor_tagsTr   r   r   CCA)ro   r   rM   check_regressors_trainr   !check_regressor_data_not_an_arrayr   r   r   check_regressor_multioutput%check_regressors_no_decision_functionr   r   r   r   ri   re   check_regressors_intr   )	regressorrl   r   s      rn   _yield_regressor_checksr     s
     I'7HHHID !   
($
?
?
????
($	
R
R
RRRR
++++
1111$ *))))
//// $$"2"@ $####
####'Du}}""""
111111rp   c              #  l  K   t          | dt                     t          |           }|j        s	t          V  t
          V  |j        j        r	t          V  t          t
          d          V  t          |           j
        r
t          V  n	t          V  g d}| j        j        }||vrt          V  d S d S )Ntransformer_tagsTr   )Isomap	KernelPCALocallyLinearEmbeddingLogisticRegressionCVBisectingKMeans)ro   r   rM   r   #check_transformer_data_not_an_arraycheck_transformer_generalr   preserves_dtype!check_transformer_preserve_dtypesr   r   check_transformers_unfitted%check_transformers_unfitted_statelessri   re   check_transformer_n_iter)transformerrl   external_solverr   s       rn   _yield_transformer_checksr     s      K);=MNNNK  D  21111
####, 0////
+T
B
B
BBBB) 4)))))3333  O  )D?""&&&&&& #"rp   c              #     K   t           V  | j        j        }|dvr*t          V  t	          t          d          V  t
          V  t          | d          st          V  d S d S )N)WardAgglomerationFeatureAgglomerationTr   	transform)&check_clusterer_compute_labels_predictri   re   check_clusteringr   r   r   r   )	clustererr   s     rn   _yield_clustering_checksr   9  s      
0000'D@@@ &======55559k** 65555556 6rp   c              #     K   t          | d          r	t          V  t          | d          r	t          V  t          | d          r*t          V  t	          t          d          V  t
          V  t          V  d S )Ncontaminationfit_predictpredictTr   )r   check_outlier_contaminationcheck_outliers_fit_predictcheck_outliers_trainr   r   r   )rj   s    rn   _yield_outliers_checksr   F  s      y/** *)))) y-(( )(((( y)$$ 1""""*DAAAAAA0000
111111rp   c              #  h   K   t                      D ] \  }}}t          t          |||          V  !d S )N)array_namespace
dtype_namer>   )r<   r   check_array_api_input)rj   r   r>   r   s       rn   r   r   X  se      
 
3	4	4	

 

 	!+!	
 
 
 	
 	
 	
 	


 

rp   legacyboolc              #  l  K   | j         j        }t          |           }|j        j        s5t          j        d                    ||j                  t                     d S |j	        r/t          j        d                    |          t                     d S t          |           D ]}|V  |sd S t          |           D ]}|V  t          |           rt          |           D ]}|V  t          |           rt          |           D ]}|V  t!          | d          rt#          |           D ]}|V  t%          | t&                    rt)          |           D ]}|V  t+          |           rt-          |           D ]}|V  t.          V  |j        st2          V  t4          V  t6          V  t8          V  t:          V  t<          V  t>          V  t@          V  tB          V  |j"        s0tF          V  tH          V  tJ          V  |j&        j'        r	tP          V  |j        j)        rtT          V  d S d S )Nz8Can't test estimator {} which requires input  of type {}z2Explicit SKIP via _skip_test tag for estimator {}.r   )+ri   re   rM   r   two_d_arrayru   rv   formatr)   
_skip_testr   r   r   r   r    r   r   r   rt   r   r   r   r   &check_parameters_default_constructiblenon_deterministic%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_fit_idempotentcheck_fit_check_is_fittedr   check_n_features_incheck_fit1dcheck_fit2d_predict1dr   requiredcheck_requires_y_nonepositive_onlycheck_fit_non_negative)rj   r   r   rl   r   s        rn   _yield_all_checksr  f  s     'DID?& FMMdo  		
 	
 	
 	 @GGMM	
 	
 	
 	"9--   y))  Y -i88 	 	EKKKKI ,Y77 	 	EKKKKy+&& .y99 	 	EKKKK)\** -i88 	 	EKKKK9%% +I66 	 	EKKKK
0000! .3333----


%%%%



#### (!!!!####$ 	(''''$ %$$$$$$% %rp   c                    t          | d          rt          | j                  S t          | t                    r| j        j        n| j        S )N__wrapped__)r   _check_namer  rt   r   funcre   )r   s    rn   r  r    sF    um$$ .5,---",UG"<"<P5:%.Prp   expected_failed_checksdict[str, str] | NonemarkLiteral['xfail', 'skip', None]c                   t          | |          \  }|r|| fS | j        j        |dk    r1|                    | |j                                                S t                    fd            }| |fS )a  Mark the test as xfail or skip if needed.

    Parameters
    ----------
    estimator : estimator object
        Estimator instance for which to generate checks.
    check : partial or callable
        Check to be marked.
    expected_failed_checks : dict[str, str], default=None
        Dictionary of the form {check_name: reason} for checks that are expected to
        fail.
    mark : "xfail" or "skip" or None
        Whether to mark the check as xfail or skip.
    pytest : pytest module, default=None
        Pytest module to use to mark the check. This is only needed if ``mark`` is
        `"xfail"`. Note that one can run `check_estimator` without having `pytest`
        installed. This is used in combination with `parametrize_with_checks` only.
    Nxfail)reason)marksc                 N    t          dt                     d d           )Nz	Skipping  for : )rQ   r  )argskwargsr   estimator_namer   s     rn   wrappedz_maybe_mark.<locals>.wrapped  s8    OK..OO^OOvOO  rp   )_should_be_skipped_or_markedri   re   paramr  r  r   )	rj   r   r  r  pytestshould_be_markedr(  r'  r   s	    `     @@rn   _maybe_markr-    s    2  <50   f   t|%(1Nw||IuFK4E4EV4E4T4T|UUU 
u	 	 	 	 	 	 
	
 '!!rp   returntuple[bool, str]c                H    |pi }t          |          }||v r
d||         fS dS )a>  Check whether a check should be skipped or marked as xfail.

    Parameters
    ----------
    estimator : estimator object
        Estimator instance for which to generate checks.
    check : partial or callable
        Check to be marked.
    expected_failed_checks : dict[str, str], default=None
        Dictionary of the form {check_name: reason} for checks that are expected to
        fail.

    Returns
    -------
    should_be_marked : bool
        Whether the check should be marked as xfail or skipped.
    reason : str
        Reason for skipping the check.
    T)FzCheck is not expected to fail)r  )rj   r   r  
check_names       rn   r)  r)    s?    . 49rU##J++++J77711rp   Tr   r  r  c          	   #    K   |dk    rddl }nd}t          |           j        }| t          t          |          fV  t          | |          D ];}t          ||          }t          ||           D ]}t          |||||          V  <dS )a  Iteratively yield all check callables for an estimator.

    .. versionadded:: 1.6

    Parameters
    ----------
    estimator : estimator object
        Estimator instance for which to generate checks.
    legacy : bool, default=True
        Whether to include legacy checks. Over time we remove checks from this category
        and move them into their specific category.
    expected_failed_checks : dict[str, str], default=None
        Dictionary of the form {check_name: reason} for checks that are expected to
        fail.
    mark : {"xfail", "skip"} or None, default=None
        Whether to mark the checks that are expected to fail as
        xfail(`pytest.mark.xfail`) or skip. Marking a test as "skip" is done via
        wrapping the check in a function that raises a
        :class:`~sklearn.exceptions.SkipTest` exception.

    Returns
    -------
    estimator_checks_generator : generator
        Generator that yields (estimator, check) tuples.
    r  r   N)r   )r  r  r+  )r+  typere   r   rx   r  rP   r-  )	rj   r   r  r  r+  r   r   check_with_namecheck_instances	            rn   estimator_checks_generatorr7    s      @ w	??#D W6==
===="9V<<< 	 	!%..8	JJ 	 	N'=      		 	rp   )r   r  Callable | Nonec                   ddl }t          d | D                       rd}t          |          d }|j                            d || ||          t
                    S )a  Pytest specific decorator for parametrizing estimator checks.

    Checks are categorised into the following groups:

    - API checks: a set of checks to ensure API compatibility with scikit-learn.
      Refer to https://scikit-learn.org/dev/developers/develop.html a requirement of
      scikit-learn estimators.
    - legacy: a set of checks which gradually will be grouped into other categories.

    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


    legacy : bool, default=True
        Whether to include legacy checks. Over time we remove checks from this category
        and move them into their specific category.

        .. versionadded:: 1.6

    expected_failed_checks : callable, default=None
        A callable that takes an estimator as input and returns a dictionary of the
        form::

            {
                "check_name": "my reason",
            }

        Where `"check_name"` is the name of the check, and `"my reason"` is why
        the check fails. These tests will be marked as xfail if the check fails.


        .. versionadded:: 1.6

    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              3  @   K   | ]}t          |t                    V  d S N)rt   r4  ).0ests     rn   	<genexpr>z*parametrize_with_checks.<locals>.<genexpr>w  s,      
7
7S:c4  
7
7
7
7
7
7rp   uPassing a class was deprecated in version 0.23 and isn't supported anymore from 0.24.Please pass an instance instead.c              3  ~   K   | D ]7}||dd}t          |          r ||          |d<   t          di |E d {V  8d S )Nr  )rj   r   r  r   )callabler7  )
estimatorsr   r  rj   r%  s        rn   _checks_generatorz2parametrize_with_checks.<locals>._checks_generator  s      # 	: 	:I!*fgNND.// S1G1G	1R1R-.199D9999999999		: 	:rp   zestimator, check)ids)r+  any	TypeErrorr  parametrizerO   )rC  r   r  r+  msgrD  s         rn   parametrize_with_checksrJ  ,  s    R MMM

7
7J
7
7
777 / 	
 nn: : : ;""*f.DEE$ #   rp   booleanrv   raise)generate_onlyr   r  on_skipon_failcallbackF)prefer_skip_nested_validation)r   r  rN  rO  rP  rN  Literal['warn'] | NonerO  Literal['raise', 'warn'] | NonerP  c                  t          | t                    rd}t          |          |dk    r|t          d          t          |           j        }|r-t          j        dt                     t          | |dd          S g }	t          | ||d          D ]9\  } }
t          | |
|          \  }}	  |
|            | t          |
          dd||d	}n# t          $ rk}| t          |
          |d
||d	}|dk    rEt          j        dt          |
           d| dt          |          j         d| t                     Y d}~nmd}~wt          $ r]}|dk    r|s | t          |
          |||d}|rd|d<   nd}d|d<   |dk    r t          di |}t          j        |           Y d}~nd}~ww xY w|	                    |           |r |di | ;|	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.

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

    Checks are categorised into the following groups:

    - API checks: a set of checks to ensure API compatibility with scikit-learn.
      Refer to https://scikit-learn.org/dev/developers/develop.html a requirement of
      scikit-learn estimators.
    - legacy: a set of checks which gradually will be grouped into other categories.

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

    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

        .. deprecated:: 1.6
            `generate_only` will be removed in 1.8. Use
            :func:`~sklearn.utils.estimator_checks.estimator_checks_generator` instead.

    legacy : bool, default=True
        Whether to include legacy checks. Over time we remove checks from this category
        and move them into their specific category.

        .. versionadded:: 1.6

    expected_failed_checks : dict, default=None
        A dictionary of the form::

            {
                "check_name": "this check is expected to fail because ...",
            }

        Where `"check_name"` is the name of the check, and `"my reason"` is why
        the check fails.

        .. versionadded:: 1.6

    on_skip : "warn", None, default="warn"
        This parameter controls what happens when a check is skipped.

        - "warn": A :class:`~sklearn.exceptions.SkipTestWarning` is logged
          and running tests continue.
        - None: No warning is logged and running tests continue.

        .. versionadded:: 1.6

    on_fail : {"raise", "warn"}, None, default="raise"
        This parameter controls what happens when a check fails.

        - "raise": The exception raised by the first failing check is raised and
          running tests are aborted. This does not included tests that are expected
          to fail.
        - "warn": A :class:`~sklearn.exceptions.EstimatorCheckFailedWarning` is logged
          and running tests continue.
        - None: No exception is raised and no warning is logged.

        Note that if ``on_fail != "raise"``, no exception is raised, even if the checks
        fail. You'd need to inspect the return result of ``check_estimator`` to check
        if any checks failed.

        .. versionadded:: 1.6

    callback : callable, or None, default=None
        This callback will be called with the estimator and the check name,
        the exception (if any), the status of the check (xfail, failed, skipped,
        passed), and the reason for the expected failure if the check is
        expected to fail. The callable's signature needs to be::

            def callback(
                estimator,
                check_name: str,
                exception: Exception,
                status: Literal["xfail", "failed", "skipped", "passed"],
                expected_to_fail: bool,
                expected_to_fail_reason: str,
            )

        ``callback`` cannot be provided together with ``on_fail="raise"``.

        .. versionadded:: 1.6

    Returns
    -------
    test_results : list
        List of dictionaries with the results of the failing tests, of the form::

            {
                "estimator": estimator,
                "check_name": check_name,
                "exception": exception,
                "status": status (one of "xfail", "failed", "skipped", "passed"),
                "expected_to_fail": expected_to_fail,
                "expected_to_fail_reason": expected_to_fail_reason,
            }

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

        ..
            TODO(1.8): remove return value

        .. deprecated:: 1.6
            ``generate_only`` will be removed in 1.8. Use
            :func:`~sklearn.utils.estimator_checks.estimator_checks_generator` instead.

    Raises
    ------
    Exception
        If ``on_fail="raise"``, the exception raised by the first failing check is
        raised and running tests are aborted.

        Note that if ``on_fail != "raise"``, no exception is raised, even if the checks
        fail. You'd need to inspect the return result of ``check_estimator`` to check
        if any checks failed.

    See Also
    --------
    parametrize_with_checks : Pytest specific decorator for parametrizing estimator
        checks.
    estimator_checks_generator : Generator that yields (estimator, check) tuples.

    Examples
    --------
    >>> from sklearn.utils.estimator_checks import check_estimator
    >>> from sklearn.linear_model import LogisticRegression
    >>> check_estimator(LogisticRegression())
    [...]
    r?  rL  Nz9callback cannot be provided together with on_fail='raise'z`generate_only` is deprecated in 1.6 and will be removed in 1.8. Use :func:`~sklearn.utils.estimator_checks.estimator_checks` instead.skipr2  passed)rj   r1  	exceptionstatusexpected_to_failexpected_to_fail_reasonskippedrv   zSkipping check r#  z because it raised r$  )rj   r1  rW  rY  rZ  r  rX  TfailedrA  )rt   r4  rG  
ValueErrorre   ru   rv   FutureWarningr7  r)  r  rQ   r)   	Exceptionr'   append)rj   rM  r   r  rN  rO  rP  rI  r   test_resultsr   test_can_failr   check_resulter\  warnings                    rn   check_estimatorrf    s   P )T"" / 	
 nn'h2TUUU	??#D  
T	
 	
 	

 *fT
 
 
 	
 L65   B% B%	5 !=u4!
 !
v3	E)X ')%00!"$1+1 LLU  	 	 	
 ')%00#$1+1 L &  /k%&8&8 / /t / /Aww'/ /+,/ /#  
  	' 	' 	''!!-! ')%00$1+1 L  2 *1X&&)1X&&  5EEEEg&&&-	'B 	L))) 	%H$$|$$$s&   1C
F-A!EF-AF((F-c                     t           =t          dddddd          \  } }t                                          |           } | |fa t           S )N   
   rB         @   *   )	n_samples
n_featuresn_informativebiasnoiserandom_state)REGRESSION_DATASETr%   r6   fit_transform)Xys     rn   _regression_datasetrw    s]    !
 
 
1 **1--Trp   c                  &    e Zd ZdZd ZddZd ZdS )_NotAnArrayzvAn object that is convertible to an array.

    Parameters
    ----------
    data : array-like
        The data.
    c                8    t          j        |          | _        d S r;  )npasarraydata)selfr}  s     rn   __init__z_NotAnArray.__init__  s    Jt$$			rp   Nc                    | j         S r;  )r}  )r~  dtypecopys      rn   	__array__z_NotAnArray.__array__  s
    yrp   c                j    |j         dk    rdS t          d                    |j                             )Nmay_share_memoryTz%Don't want to call array_function {}!)re   rG  r  )r~  r  typesr%  r&  s        rn   __array_function__z_NotAnArray.__array_function__  s4    =...4?FFt}UUVVVrp   )NN)re   
__module____qualname____doc__r  r  r  rA  rp   rn   ry  ry    sU         % % %   W W W W Wrp   ry  c                J    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)rg   r   )rj   r  s     rn   _is_pairwise_metricr    s(     Y$//F-'(((rp   c              #    K   | j         dk    sJ d|                                 fV  dD ]}||                     |          fV  |                     d          }|j                            d          |_        |j                            d          |_        d|fV  dD ]^}|                     |          }|j                            d          |_        |j                            d          |_        |dz   |fV  _dS )	au  Generate sparse matrices or arrays with {32,64}bit indices of diverse format.

    Parameters
    ----------
    X_csr: scipy.sparse.csr_matrix or scipy.sparse.csr_array
        Input in CSR format.

    Returns
    -------
    out: iter(Matrices) or iter(Arrays)
        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  r  asformatrowastypecolindicesindptr)X_csrsparse_formatX_cooru  s       rn   _generate_sparse_datar    s#      <5    

C ; ;U^^M::::::: NN5!!E	  ))EI	  ))EI
E/' ' 'NN=))I$$W--	8??7++e#Q&&&&&	' 'rp   rr   c                F   t          |          }t          j                            d          }|                    d          }t          j        t          j        fD ]}t          j        d|          }t          ||          }|j	        }|
                    d          r3d|v s/|                    d          st          j        |          rd}nd	}nd }d
|  d}	t          t          ||	          5  |                    ||           d d d            n# 1 swxY w Y   d S )Nix  )ri     sizeri  sklearn.test__testingzJInput (y|Y) contains infinity or a value too large for dtype\('float64'\).zInput (y|Y) contains NaN.rd   z< should have raised error on fitting array y with inf value.matcherr_msg)r   r{  randomRandomStatestandard_normalnaninffull_enforce_estimator_tags_yr  
startswithendswithisinfr[   r]  fit)
r   estimator_origrj   rngru  valuerv  module_namer  r  s
             rn   r   r     s    n%%I
)


$
$C))A&"&!    GB%i33*!!*-- 	{""k&:&::&F&F" x 5, 
 5 E    	 JeW=== 	  	 MM!Q	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 1   s   2DD	D	float64c           	        t          ||          }t          d          \  }}|                    |d          }t          ||          }t	          ||          }t          |          }	|                    ||          }
|                    ||          }|	                    ||           d t          |	          	                                D             }t          |	          }t          d          5  |                    |
|           t          |
          d	         j        }d
d
d
           n# 1 swxY w Y   |	                                D ]\  }}t          ||          }t          d          5  t          |          d	         j        }d
d
d
           n# 1 swxY w Y   ||k    sJ d| d| d|             t          |          t          |
          k    sJ t          ||          }|r)t!          ||| dt#          |j                             |j        |j        k    sJ |j        |j        k    sJ d}	 t)          j        |
           t)          j        |           |j        dk    }n# t*          $ r d}Y nw xY w|rZt          |	                              |
|          }|D ]4}t          ||d
          }||dk    r ||
|           ) ||
           5|D ]}t          |	|d
          }||dk    r |||          }t          d          5   t          ||          |
|          }d
d
d
           n# 1 swxY w Y   t-          |t.                    sJ t-          |t.                    sJ |r*t1          ||z
            t#          |j                  k     sJ  ||          }t          d          5   t          ||          |
          }d
d
d
           n# 1 swxY w Y   t          d          5  t          |          d	         j        }d
d
d
           n# 1 swxY w Y   ||k    sJ d| d| d| d            t          |          t          |
          k    sJ t          ||          }|r)t!          ||| dt#          |j                             n4t3          |d          r$|j        |j        k    sJ |j        |j        k    sJ |dk    rt3          |	d          r|	                    |          }t          d          5  |                    |          }t          |          d	         j        }d
d
d
           n# 1 swxY w Y   ||k    sJ d| d| d            t          |          t          |
          k    sJ t          ||          } |r't!          || dt#          |j                             |j        | j        k    sJ |j        | j        k    sJ d
S )a_  Check that the estimator can work consistently with the Array API

    By default, this just checks that the types and shapes of the arrays are
    consistent with calling the same estimator with numpy arrays.

    When check_values is True, it also checks that calling the estimator on the
    array_api Array gives the same results as ndarrays.
    rl  rr  Fr  r=   c                N    i | ]"\  }}t          |t          j                  ||#S rA  )rt   r{  ndarrayr<  keyr  s      rn   
<dictcomp>z)check_array_api_input.<locals>.<dictcomp>0  s?       !sE*UBJ:W:WU  rp   T)array_api_dispatchr   N'z,' attribute is in wrong namespace, expected z got )xpz not the samer  atol)scorescore_samplesdecision_functionr   predict_log_probapredict_probar   array_api_strictr  z)' output is in wrong namespace, expected , got .z# did not the return the same resultshaper   inverse_transformz;'inverse_transform' output is in wrong namespace, expected z4inverse_transform did not the return the same result)rR   r#   r  _enforce_estimator_tags_Xr  r   r|  r  varsitemsr   r;   re   rg   array_devicer:   rT   r9   r  r  r{  rG  rt   floatabsr   r  )!r   r  r   r>   r   check_valuesr  ru  rv  r=  X_xpy_xparray_attributesest_xpinput_nsr  	attributeest_xp_paramattribute_nsest_xp_param_npmethodsnumpy_asarray_worksest_fitted_with_as_arraymethod_namemethodresult	result_xp	result_nsresult_xp_npinverse_resultinvese_result_xpinverse_result_nsinvese_result_xp_nps!                                    rn   r   r     s	     
ov	6	6BB///DAq	%((A!.!44A!.!44A


C::a:''D::a:''DGGAqMMM %)#YY__%6%6   3ZZF	4	0	0	0 3 3

4 &&q)23 3 3 3 3 3 3 3 3 3 3 3 3 3 3 +0022 < <Yvs++t444 	C 	C(66q9BL	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	Cx'''" " " " "" " (''
 L))\$-?-?????+LR@@@ 		<---#AG,,	     ?o&;;;;;?o&;;;;;;G$

4

4 !k-?? $ $ $ $	$   $)::>>$#=#=  # 	 	K5{DIIF~g%%tT""""t @I @Ik400>'!!VAq\\F4888 E E8GFK88tDD	E E E E E E E E E E E E E E E fe,,,,,i///// I6I-..1H1HHHHHVAYYF4888 ? ?8GFK88>>	? ? ? ? ? ? ? ? ? ? ? ? ? ? ? t444 	= 	=%i003<I	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=H$$$               %$$
 I&&,t*<*<<<<<(r::: 
	:!FFF#AG,,	     vw'' :||'99999||'99999+%%'#7J*K*K% 226::N4888 P P#)#;#;I#F#F $12B$C$CA$F$O!P P P P P P P P P P P P P P P %00099 9$59 9 9 100
   011\$5G5GGGGG"34D"L"L"L 	I"'R'00	     &+/B/HHHHH%+/B/HHHHHA@I @Is~   81D55D9<D99F  F$	'F$	
3I> >JJ'MM	M	O55O9	<O9	P77P;	>P;	+0U''U+	.U+	c                ,    t          | ||||d          S )NT)r   r>   r   r  )r   )r   r  r   r>   r   s        rn    check_array_api_input_and_valuesr    s-     !'   rp   c                   t           rt          j        }nt          j        }t	          |          }t
          j                            d          }| dk    rdnd}|                    |df          }d||dk     <   |	                    dd|          }t          ||          }t          ||          } ||          }t          |          }|j        j        rN	 |                    ||           dS # t          $ r(}	d|  d	|j        j         d
}
t!          |
          |	d}	~	ww xY wd|  d|j        j         d}
	 |                    ||           nn# t"          t$          f$ r=}	t'          j        dt+          |	                    rY d}	~	dS t!          |
          |	d}	~	wt          $ r}	t!          |
          |	d}	~	ww xY wt!          d|  d|j        j         d          )zLCheck that estimator tag related with accepting sparse data is properly set.r   SpectralCoclustering   (      r  333333?rd   z5 raised an exception. The tag self.input_tags.sparse=z might not be consistent with the estimator's ability to handle sparse data (i.e. controlled by the parameter `accept_sparse` in `validate_data` or `check_array` functions).Nzx raised an exception. The estimator failed when fitted on sparse data in accordance with its tag self.input_tags.sparse=z but didn't raise the appropriate error: error message should state explicitly that sparse input is not supported if this is not the case, e.g. by using check_array(X, accept_sparse=False).z	[Ss]parsezd didn't fail when fitted on sparse data but should have according to its tag self.input_tags.sparse=z,. The tag is inconsistent and must be fixed.)r]   r   	csr_array
csr_matrixr   r{  r  r  uniformrandintr  r  rM   r   r  r_  AssertionErrorr]  rG  researchstr)r   r  sparse_containerrj   r  rm  ru  rv  rl   rd  r  s              rn   r   r     se    -!+!,n%%I
)


"
"C444"I)Q((AAa#gJAqy))A!)Q//A!)Q//AAID #

	1MM!Q 	1 	1 	1CT C C26/2HC C C  !))q0	1O O O37?3IO O O 		1MM!QI& 	1 	1 	1yc!ff--  ))q0 	1 	1 	1 ))q0	1: : :&*o&<: : :
 
 	
sB   C1 1
D#;#DD#:E F<""F
FF<'F77F<c                   t           j                            d          }|                    d          }d||dk     <   t	          ||          }d|                    |j        d                   z                      t           j                  }t          t                    5  t          |          }d d d            n# 1 swxY w Y   t          ||          }t          |          }t           ||                    D ]\  }}t          t                    5  t          |          }| dv r|                    d	           d d d            n# 1 swxY w Y   d
|v r
d|  d| d}	nd|  d}	t          t           t"          fddgd|	          5  t          t                    5  |                    ||           d d d            n# 1 swxY w Y   t'          |d          ra|                    |          }
|j        j        r'|j        j        s|
j        |j        d         dfk    sJ n|
j        |j        d         fk    sJ t'          |d          rM|                    |          }|j        j        s|j        d         df}n|j        d         df}|j        |k    sJ d d d            n# 1 swxY w Y   d S )Nr   )r  r  r  r     rr   )Scalerr6   F)	with_mean64rd   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, e.g. by using check_array(X, accept_sparse=False).r   SparseTr  may_passr  r   rB   r  r   )r{  r  r  r  r  r  r  int32rZ   r^  r   r  rM   r  
set_paramsr[   rG  r]  r  r   r   r   r   r   r  r   r   )r   r  sparse_typer  ru  rv  rj   rl   matrix_formatr  predprobsexpected_probs_shapes                rn   !_check_estimator_sparse_containerr    s   
)


"
"C!!AAa#gJ!.!44A	
S[[agaj[))	)11"(;;A	-	0	0	0 * *.))	* * * * * * * * * * * * * * *!)Q//AN##D1++a..AA (; (;qm444 	6 	6n--I333$$u$555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6
 =  =T = =M = = = G7T 7 7 7  
#X&	
 
 
 	; 	; !-888 $ $a###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $y),, 7 ((++#0 79I9W 7:!'!*a88888:!'!*6666y/22 ;!//22+7 ;,-GAJ?((,-GAJ?({&:::::)	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;)(; (;s[   %CCC*EE	E	J2*GJ2GJ2GCJ22J6	9J6	c                <    t          | |t          j                   d S r;  )r  r   r  r   r  s     rn   r   r   A  s    %dNF<MNNNNNrp   c                N    t           rt          | |t          j                   d S d S r;  )r]   r  r   r  r  s     rn   r   r   E  s2     R)$@PQQQQQR Rrp   c                   t          |          }t          j                            d          }d|                    d          z  }t          ||          }t          j        |          }|d d df                             t                    }t          ||          }|
                    ||           t          |d          r|                    |           t          |d          r|                    |           d S d S )Nr   r  rk  r  r  r   r   )r   r{  r  r  r  r  asfortranarrayr  intr  r  r   r   r   )r   r  rj   r  ru  rv  s         rn   r   r   J  s     n%%I
)


"
"C	CKKWK%%%A!.!44A
!A	!!!Q$sA!.!44AMM!Qy+&& Ay)$$ ! rp   c                   t          |          }	 dd l}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g          }|                    t          ||          d          }|                    g d          }|                    dgd	z            }t          |          j        j	        s0t          |          j        j
        r|                    |d          }	 |                    |||
           d S # t          $ r# t          d                    |                     w xY w# t          $ r t          d          w xY w)Nr   rB   r   r  r  Fr  rB   rB   rB   rB   r   r   r   r   rB   rB   r   r      r   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  SeriesrM   r   r   r   r  r]  r  ImportErrorrQ   )r   r  rj   pdru  rv  weightss          rn   r   r   `  s    n%%I'
HAAAAAAAAAAAA
 
  LL2>1EEELRRII:::;;))QC"H%%##/=	,##/<	, QU++A	MM!QgM66666 	 	 	%%+VD\\  	  
 
 
;
 
 	

s   CD6 ,D -D33D6 6Ec                   t          |          }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g          }t          t	          ||                    }t          g d          }t          dgdz            }t          |          }|j        j        s4|j        j        r(t          |j	        
                    dd                    }|                    |||           d S )	NrB   r   r  r  r  r  r  )r   r{  r  ry  r  rM   r   r   r   r}  reshaper  )r   r  rj   ru  rv  r$  rl   s          rn   r   r     s    n%%I
FFFFFFFFFFFF	
	 	A  	-na@@AAA88899A1#(##GID) /d.>.K /r1--..MM!QgM.....rp   c                <   t          |          }t          j                            d          }d}t	          ||                    |df                    }t          j        |          dz  }t          ||          }dg|z  }|                    |||           d S )Nr      r  r  r  )	r   r{  r  r  r  r  aranger  r  )r   r  rj   rndrm  ru  rv  r   s           rn   r   r     s     n%%I
)


"
"CI!.#++Iq>+2R2RSSA
	)q A!)Q//AC)OMMM!QmM44444rp   c                   t          |          }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        g d          }t          ||          }|                    ||t          j        t          |                               t          t                    5  |                    ||t          j        dt          |          z                       d d d            n# 1 swxY w Y   t          t                    5  |                    ||t          j        t          |          df                     d d d            d S # 1 swxY w Y   d S )NrB   r  r   r  rB   rB   rB   rB   r   r   r   r   rB   rB   rB   rB   r   r   r   r   r  )	r   r{  r  r  r  oneslenr[   r]  )r   r  rj   ru  rv  s        rn   r   r     s'    n%%I
FFFFFFFFFFFFFFFF!	
	 	A( 	AAABBA!)Q//AMM!Qbgc!ffooM666	
		 ? ?a"'!c!ff**=*=>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 

		 @ @a"'3q661+*>*>???@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @s$   ;DDD+:E22E69E6c                2   t          |          }t          |          }t          |d           t          |d           t          j                            d          }d}|                    ||dz            }|                    dd|          }|                    dd|          }	|}
|}|
                    |	d	          }|                    |	
          }t          |
||	d          \  }
}}	d|	                                v rt          j
        t          j        |d          t          j        |d          t          j        |d          g          }t          j
        |	t          j        |          t          j        |          g          }	t          j        |
||g          }
t          j
        |||g          }t          t                                          |
|                    }|                    |           t          j
        t          j        |d          t          j        |d          t          j        |d          g          }t          j        |||g          }t          j
        |||g          }t          t                                          ||                    }|                    |           t%          ||          }t%          ||          }| ||
          }
 ||          }|                    ||d            |                    |
||	           dD ]_}t)          ||          rM t+          ||          |          } t+          ||          |          }d|  d| d}t-          |||           `d S )Nr   r  rl  r  r   r  r  r  )repeatsaxis)r1  cvrB   )groupsr3  )rv  r   )r  r  r   r   zComparing the output of r  zn revealed that fitting with `sample_weight` is not equivalent to fitting with removed or repeated data points.r  )r   r\   r{  r  r  randr  repeatrC   r   hstack	full_like	ones_likevstacklistr1   splitr  r  r  r   rg   rU   )r   r  r  estimator_weightedestimator_repeatedr  rm  ru  rv  sw
X_weighted
y_weighted
X_repeated
y_repeatedgroups_weightedsplits_weightedgroups_repeatedsplits_repeatedr  X_pred1X_pred2r  s                         rn    _check_sample_weight_equivalencerL    s    ~..~..'a8888'a8888
)


#
#CIIM**AAqy))A	Q		*	*BJJ""2A"66J""2"..J!(ZRS!T!T!TJ
B ~((****)\*a((",q!*<*<bl1a>P>PQ
 
 YBLOOR\!__=>>Y
Aq122
Y
Aq122
$$Z$HH
 
 	%%%999)\*a((",q!*<*<bl1a>P>PQ
 
 Y
Aq122
Y
Aq122
$$Z$HH
 
 	%%%999*+=zJJJ*+=zJJJ #%%j11
%%j11
:4HHH:2FFFP 	L 	L>6** 	L9g0&99!<<G9g0&99!<<G+4 + +& + + + 
 )'7KKKK	L 	Lrp   c                *    t          | |d            d S )N)r  )rL  r  s     rn   r   r   (  s    $T>DQQQQQQrp   c                    t           rt          j        }nt          j        }	 t	          | ||           d S # t
          $ r Y d S w xY wr;  )r]   r   r  r  rL  rG  )r   r  r  s      rn   r   r   ,  s_     -!+!,(~?OPPPPP   s   5 
AAc                   t          |          }t          |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                  }t          j        g dt
                    }t          ||          }t          j        |j        d                   }d	|d<   |	                                }|
                    |||
           |  d}t          |||           d S )Nr   r  rB   r  r   r  r  r-  g      $@r  z8 overwrote the original `sample_weight` given during fitr6  )r   r\   r{  r  r  r  r  r.  r  r  r  rT   )r   r  rj   ru  rv  sample_weight_originalsample_weight_fitr  s           rn   r   r   8  sW   n%%IYQ////
FFFFFFFFFFFFFFFF!	
$ j'	 	 	A* 	AAAMMMA!)Q//AWQWQZ00 $1.3355MM!Q&7M888OOOG%'=wOOOOOOrp   c                   t           j                            d          }t          ||                    d                    }|                    t                    }t          |          }|d d df         dz                      t                    }t          |          }t          ||          }|                    ||           t          |d          r|                    |           t          |d          r|                    |           d}t          t           dd	|
          5  |                    ||                    t                               d d d            n# 1 swxY w Y   |j        j        sPddi|d<   d}t          t&          |          5  |                    ||           d d d            d S # 1 swxY w Y   d S |                    ||           d S )Nr   )r  ri  r  r  r   r   zy with unknown label type is passed, but an error with no proper message is raised. You can use `type_of_target(..., raise_unknown=True)` to check and raise the right error, or include 'Unknown label type' in the error message.zUnknown label typeTr	  foobarr   r   z#argument must be .* string.* numberr  )r{  r  r  r  r  r  objectrM   r  r   r  r  r   r   r   r[   r_  r   stringrG  )	r   r  r  ru  rl   rv  rj   r  rI  s	            rn   r   r   `  sV    )


"
"C!.#++8+2L2LMMA	AN##D	
111a41S!!An%%I!)Q//AMM!Qy)$$ !y+&& A	  
	!5g	V	V	V + +a&))***+ + + + + + + + + + + + + + + ?! %.$ 4IS))) 	  	 MM!Q	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	as$   -/E((E,/E,GG	Gc                   t           j                            d          }|                    d          d|                    d          z  z   }|                    dd          }|                    ddd	          dz   }t          |          }t          |d
           t          t          d          5  |
                    ||           d d d            d S # 1 swxY w Y   d S )Nrl  ri  r  y              ?r&  rB   r   r   lowhighr  r  zComplex data not supportedrW  )r{  r  r  r  r'  r  r   r\   r[   r]  r  )r   r  r  ru  rv  rj   s         rn   r   r     s   
)


#
#CrCKKRK$8$888A			"aA 	++b0An%%IYQ////	
">	?	?	?  a                 s   7CC"Cc                &   t           j                            d          }d|                    d          z  }t	          ||          }|d d df                             t                    }t          |          }t          ||          }t          |d           |
                    ||           dD ]\}t          ||          rJ|j                                        } t          ||          |           |j        |k    sJ d|z              ]d S )Nr   r  r  r  rB   r   r   r  r  z$Estimator changes __dict__ during %s)r{  r  r  r  r  r  r  r   r  r\   r  r   __dict__r  rg   )r   r  r+  ru  rv  rj   r  dict_befores           rn   r  r    s   
)


"
"C	CKKWK%%%A!.!44A	!!!Q$sAn%%I!)Q//AY"""MM!QP  9f%% 	#,1133K&GIv&&q)))%4446? 544	 rp   c                X    |                      d          p|                     d           S )N_)r  r  )attrs    rn   _is_public_parameterre    s(    $$:c(:(:;;rp   c                4  	
 t          |j        d          rd S t          |          }t          j                            d          }d|                    d          z  }t          ||          }|d d df                             t                    }t          ||          }t          |d          rd|_        t          |d          rd|_        t          |d           |j                                        
|                    ||           |j        	d	 	                                D             }
fd
|D             }|r J dd                    |          z              	
fd|D             }|r J dd                    |          z              d S )Ndeprecated_originalr   r  r  r  n_componentsrB   
n_clustersc                0    g | ]}t          |          |S rA  )re  )r<  r  s     rn   
<listcomp>z3check_dont_overwrite_parameters.<locals>.<listcomp>  s6       0DS0I0I  rp   c                @    g | ]}|                                 v|S rA  )r   )r<  r  dict_before_fits     rn   rk  z3check_dont_overwrite_parameters.<locals>.<listcomp>  s6       ?;O;O;Q;Q0Q0Q0Q0Q0Qrp   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                4    g | ]}|         |         u|S rA  rA  )r<  r  dict_after_fitrm  s     rn   rk  z3check_dont_overwrite_parameters.<locals>.<listcomp>  s8       C s(;;; 	;;;rp   zEstimator changes public attribute(s) during the fit method. Estimators are only allowed to change attributes started or ended with _, but %s changed)r   r  r   r{  r  r  r  r  r  r  r  rh  ri  r\   r`  r  r  r   join)r   r  rj   r+  ru  rv  public_keys_after_fitattrs_added_by_fitattrs_changed_by_fitrp  rm  s            @@rn   r   r     s
    ~&(=>> n%%I
)


"
"C	CKKWK%%%A!.!44A	!!!Q$sA!)Q//Ay.)) #!"	y,'' ! 	Y"""(--//OMM!Q'N %**,,     ,  
 "  	 "&+=!>!>		?      (   $  	 		"677		8    rp   c                   t           j                            d          }d|                    d          z  }t	          ||          }|d d df                             t                    }t          |          }t          ||          }t          |d          rd|_
        t          |d          rd|_        t          |d           |                    ||           dD ]_}t          ||          rMt          t          d	
          5   t!          ||          |d                    d d d            n# 1 swxY w Y   `d S )Nr   r  r  r  rh  rB   ri  r_  zReshape your datarW  )r{  r  r  r  r  r  r  r   r  r   rh  ri  r\   r  r[   r]  rg   )r   r  r+  ru  rv  rj   r  s          rn   r  r    s    )


"
"C	CKKWK%%%A!.!44A	!!!Q$sAn%%I!)Q//Ay.)) #!"	y,'' ! 	Y"""MM!QP 1 19f%% 	1
*=>>> 1 1*	6**1Q40001 1 1 1 1 1 1 1 1 1 1 1 1 1 11 1s   
 D66D:	=D:	c                      |          }|j         d          fd|D             }t          |t                    r&|d         }t          t	          d |                    }t          j        |          r |                                }d |D             }t          j	        |          t          j	        |          fS )NrB   c                N    g | ]!} |                     d                     "S )rB   )r'  )r<  batchr  rn  s     rn   rk  z%_apply_on_subsets.<locals>.<listcomp>  s1    IIIettEMM!Z8899IIIrp   r   c                    | d         S )Nr   rA  )xs    rn   <lambda>z#_apply_on_subsets.<locals>.<lambda>  s
    QqT rp   c                6    g | ]}|                                 S rA  )toarray)r<  rz  s     rn   rk  z%_apply_on_subsets.<locals>.<listcomp>  s     @@@1199;;@@@rp   )
r  rt   tupler=  mapr   issparser}  r{  ravel)r  ru  result_fullresult_by_batchrn  s   `   @rn   _apply_on_subsetsr    s    $q''KJIIIIIqIIIO +u%% E!!ns>>?CCDD{## A!))++@@@@@8K  "(?";";;;rp   c                   t           j                            d          }d|                    d          z  }t	          ||          }|d d df                             t                    }t          |          }t          ||          }t          |d          rd|_
        t          |d          rd|_        t          |d           |                    ||           dD ]]}d	                    || 
          }t          ||          r4t          t!          ||          |          \  }}	t#          ||	d|           ^d S )Nr   r  r  r  rh  rB   ri  r   r   r  r  r  z={method} of {name} is not invariant when applied to a subset.r  r   Hz>r  r  )r{  r  r  r  r  r  r  r   r  r   rh  ri  r\   r  r  r  rg   rT   )
r   r  r+  ru  rv  rj   r  rI  r  r  s
             rn   r  r    se    )


"
"C	CKKWK%%%A!.!44A	!!!Q$sAn%%I!)Q//Ay.)) #!"	y,'' ! 	Y"""MM!Q R R OVV W 
 
 9f%% 	R+<	6**A, ,(K KtSQQQQR Rrp   c           
        t           j                            d          }d|                    d          z  }t	          ||          }|d d df                             t           j                  }t          |          }|j        |j        j	        s	d||dk    <   t          |          }t          ||          }t          |d          rd|_        t          |d          rd|_        t          |d           |                    ||           t           j                            |j        d                   }d	D ]}d
                    ||           }	t          ||          r]t)          t+           t-          ||          |          |           t-          ||          t+          ||                    d|	           d S )Nr   r  r  r  rB   r   rh  ri  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  rM   r   r   r   r  r   rh  ri  r\   r  permutationr  r  rU   r8   rg   )
r   r  r+  ru  rv  rl   rj   idxr  rI  s
             rn   r  r  :  s    )


"
"C	CKKWK%%%A!.!44A	!!!Q$rx  AN##D'0D0P'!q&	n%%I!)Q//Ay.)) #!"	y,'' ! 	Y"""MM!Q
)



+
+C  +
&T&
*
* 	
 9f%% 	(9wy&99!<<cBB*	6**>!S+A+ABB	    rp   c                   t           j                            d          }d|                    d          z  }t	          ||          }|d d df                             t                    }t          |          }t          ||          }t          |d          rd|_
        t          |d          rd|_        t          |d           | dk    r|                    d	
           | dk    r|                    d           g d}t          t          |d          5  |                    ||           d d d            d S # 1 swxY w Y   d S )Nr   r  )rB   ri  r  rh  rB   ri  OPTICS      ?)min_samplesTSNE      ?)
perplexity)z1 samplezn_samples = 1zn_samples=1z
one samplez1 classz	one classTr  r
  )r{  r  r  r  r  r  r  r   r  r   rh  ri  r\   r  r[   r]  r  r   r  r+  ru  rv  rj   msgss          rn   r  r  g  s   
 )


"
"C	CKKWK%%%A!.!44A	!!!Q$sAn%%I!)Q//Ay.)) #!"	y,'' ! 	Y""" x--- v~~,,,  D 

$	6	6	6  a                 s   EEEc                   t           j                            d          }d|                    d          z  }t	          ||          }|d d df                             t                    }t          |          }t          ||          }t          |d          rd|_
        t          |d          rd|_        | dk    rd|_        | d	k    rd
|_        t          ||          }t          |d           g d}t          t           |d          5  |                    ||           d d d            d S # 1 swxY w Y   d S )Nr   r  )ri  rB   r  rh  rB   ri  RandomizedLogisticRegressionRANSACRegressorr  )z1 feature\(s\)zn_features = 1zn_features=1Tr  )r{  r  r  r  r  r  r  r   r  r   rh  ri  sample_fractionresidual_thresholdr\   r[   r]  r  r  s          rn   r  r    s    )


"
"C	CKKWK%%%A!.!44A	!!!Q$sAn%%I!)Q//Ay.)) #!"	y,'' ! 	---$%	!   '*	$!)Q//AY"""@@@D	
$	6	6	6  a                 s   D33D7:D7c                   t           j                            d          }d|                    d          z  }|                    t
                    }t          |          }t          ||          }t          |d          rd|_	        t          |d          rd|_
        t          |d           t          t                    5  |                    ||           d d d            d S # 1 swxY w Y   d S )Nr   r  rk  r  rh  rB   ri  )r{  r  r  r  r  r  r   r  r   rh  ri  r\   r[   r]  r  )r   r  r+  ru  rv  rj   s         rn   r  r    s&    )


"
"C	CKKbK"""A	An%%I!)Q//Ay.)) #!"	y,'' ! 	Y"""	
		  a                 s   C((C,/C,c                    t          dg dg dgddd          \  }}t                                          |          }t          ||          }|rt	          ||g          \  }}t          | |||           d S Nr)  r   r   r   rB   rB   rB   r   r   皙?rm  centersrr  rn  cluster_std)r"   r6   rt  r  rY   _check_transformer)r   r   r   ru  rv  s        rn   r   r     s    III&  DAq 	&&q))A!+q11A 1(!Q001t[!Q/////rp   c                   t          dg dg dgddd          \  }}t                                          |          }t          ||          }t	          |          }t	          t          j        |                    }t          | |||           t          | ||                                |                                           d S r  )	r"   r6   rt  r  ry  r{  r|  r  tolist)r   r   ru  rv  this_Xthis_ys         rn   r   r     s    III&  DAq 	&&q))A!+q11A^^FA''Ft[&&999t[!((**ahhjjAAAAArp   c                    t                      \  }}t          |          }t          t          t          fd|  d          5  |                    |           d d d            d S # 1 swxY 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.r6  )rw  r   r[   AttributeErrorr]  r   )r   r   ru  rv  s       rn   r   r     s      DAq$$K		$,, , ,
 
 
 	! 	! 	a   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!s   A%%A),A)c                   t           j                            d          }|                    d          }t	          ||          }t          |          }|                    |          }|j        d         |j        d         k    sJ dS )ztCheck that using transform without prior fitting
    doesn't raise a NotFittedError for stateless transformers.
    r   rk  r  r  N)r{  r  r  r  r  r   r   r  )r   r   r  ru  X_transs        rn   r   r     s    
 )


"
"C!!A!+q11A$$K##A&&G=qwqz))))))rp   c                l   t          j        |          j        \  }}t          |          }t	          |           | t
          v rrt           j        t          j        |          t          j        |          f         }|d d ddfxx         dz  cc<   t          |t                    rt          |          }n|}|	                    ||           t          |          }|
                    ||          }	t          |	t                    r|	D ]}
|
j        d         |k    sJ n|	j        d         |k    sJ t          |d          r| t
          v r.|                    ||          }|
                    ||          }n,|                    |          }|
                    ||          }t          |          j        r| dz   }t!          |          t          |	t                    rZt          |t                    rEt#          |	||          D ]2\  }
}}t%          |
|dd|z  	           t%          |
|dd
|z  	           3nVt%          |	|d|z  d           t%          |	|dd
|z  	           t'          |          |k    sJ t'          |          |k    sJ t          |d          rt          |          j        rv|j        dk    rm|j        d         dk    r^t-          t.          d|  d          5  |                    |d d d df                    d d d            d S # 1 swxY w Y   d S d S d S d S d S d S )Nr   rB   rv  r   r    is non deterministic{Gz?z9fit_transform and transform outcomes not consistent in %sr  z7consecutive fit_transform outcomes not consistent in %sr  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.r6  r&  )r{  r|  r  r   r\   rN   c_rt   ry  r  rt  r~  r   r   rM   r  rQ   ziprU   r^   r   ndimr[   r]  )r   transformer_origru  rv  rm  rn  r   y_transformer_cloneX_predx_predrK  X_pred3rI  x_pred2x_pred3s                   rn   r  r    s8   JqMM/Iz())K[!!! """U2:a=="*Q--/0
33Q36


a


a%% 	!RBOOArk**,,Q",55F&%   , 	0 	0F<?i/////	0 |A)++++{K(( =1&&&!++Ar22G!//R/88GG!++A..G!//R/88G$%%7 	 00C3--fe$$  	6GU)C)C  	6,/,I,I  (,W!"	    -U!"	      )S    )Q	     ((I5555((I5555 Aw	1%%2	1 !
Q 5t 5 5 5   1 1 %%a3B3i0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1k=1 =1\	1 	1 	1 	1 s   0"LL#&L#c                8   t          |          j        r| dz   }t          |          t          dg dg dgddd          \  }}t	          ||t
          	          }t          |          }t          ||          }t          |           t          |          }|
                    ||           |
                    ||           d
dg}|D ]M}t          ||d           }	|	8t          ||          }
 |	||          } |
||          }t          ||           Nd S )Nr  r)  r  r  r   r   r  r  kernelr  rt  )rM   r  rQ   r"   r  r0   r   r  r\   r5   r  rg   rU   )r   r  rI  ru  rv  rj   pipelinefuncs	func_namer  func_pipeliner  result_pipes                rn   r   r   a  sQ   1 ,,smm III&  DAq 	".!JGGGAn%%I!)Q//AYY''HMM!QLLAo&E > >	y)T22#Hi88MT!QZZF'-1--K(===> >rp   c                t   t           t          ft          t          ft          t          ft          t          ft
          t          ft          t          ft          t          ft          t          ft          t          ft          t          ft          t          fg}g }t          |                                          }|D ]P\  }}||v rG||v rC|                    |          |                    |          k    r|                    ||f           Qd                    d |D                       }|rJ |  d|             dS )z5Check that mixins are inherited in the correct order.
c              3  >   K   | ]\  }}|j          d |j          V  dS )z comes before/left side of Nre   )r<  mixin_amixin_bs      rn   r>  z$check_mixin_order.<locals>.<genexpr>  sN        GW JJ8HJJ     rp   a   is inheriting from mixins in the wrong order. In general, in mixin inheritance, more specialized mixins must come before more general ones. This means, for instance, `BaseEstimator` should be on the right side of most other mixins. You need to change the order so that:
N)r   r   r   r   r   r   r   r   r   r   r   r   r4  mroindexr`  rq  )r   r  dag
violationsr  r  r  violation_strs           rn   r   r     sY    
-(	'	}%	=)	'	}-	(-8	}%	}%	]+	=)C J
~


"
"
$
$C 2 2sNN3		'""SYYw%7%777w0111II   *    M    	 	 		 	    rp   c           	     ^   t           j                            d          }d}|                    |df          }t	          ||          }t          j        |          dz  }t          |          }t          ||          }t          |           g d}|D ]}t          ||d           }	|	 |	||           d t          |	          j                                        D             }
|
d         dk    r
|
dd          }
|
d         d	v s&J d
|dt          |          j        d|
d            d S )Nr   r)  r  r  )r  r  partial_fitr   rt  c                    g | ]	}|j         
S rA  r   )r<  ps     rn   rk  z+check_fit_score_takes_y.<locals>.<listcomp>  s    HHHqAFHHHrp   r~  rB   )rv  Yz.Expected y or Y as second argument for method  of z. Got arguments: r  )r{  r  r  r  r  r*  r   r  r\   rg   r   
parametersvaluesr4  re   )r   r  r+  rm  ru  rv  rj   r  r  r  r%  s              rn   r}   r}     sX    )


"
"CI)Q((A!.!44A
	)q An%%I!)Q//AYKKKE  	y)T22DAJJJHHIdOO$>$E$E$G$GHHHDAw&   ABBx7j(((( 99d9oo666> )(( rp   c                   t           j                            d          }d|                    d                              t           j                  z  }t          ||          }|                    t           j                  }|                    t           j                  }|                    t           j	                  }t          j
        ddgdz  t           j                  }t          ||          }g d	}||||fD ]e}	t          |          }
t          |
d           |
                    |	|           |D ]+}t          |
|          r t!          |
|          |	           ,fd S )
Nr   r  r  r  rB   r   ri  rP  r_  )r{  r  r  r  r  r   r  r  r  r  r  r  r   r\   r  r   rg   )r   r  r+  
X_train_32
X_train_64X_train_int_64X_train_int_32rv  r  X_trainrj   r  s               rn   r   r     sY   
)


"
"CS[[g[..55bjAAAJ*>:FFJ""2:..J&&rx00N&&rx00N
!Q"BH---A!.!44ALLLG
NNK 4 4.))	A&&&gq!!! 	4 	4Fy&)) 4*	6**7333	44 4rp   c                   t          |          }t          |d          r|                    d           t          dg dg dgdd	          \  }}t	                                          |          }t          ||          }t          |          j        j	        D ]}|
                    |          }t          |           |                    ||          }|                    ||                              |          }t          ||gd
dg          D ]H\  }	}
t          |	t                     r|	d         }	|	j        |k    sJ |  d|
 d| d|	j         d            Id S )N
set_outputdefaultr   r)  r  r  r   r  )rm  r  rr  r  rt  r   z	 (method=z3) does not preserve dtype. Original/Expected dtype=z, got dtype=r  )r   r   r  r"   r6   rt  r  rM   r   r   r  r\   r  r   r  rt   r~  r  )r   r  r   ru  rv  r  X_castX_trans1X_trans2Xtr  s              rn   r   r     s    ())K{L)) 4333III&	  DAq 	&&q))A!"2A66A*++<L  %%%%,,VQ77??61--77??x2_k4RSS 
	 
	JB"e$$  U 8u$$$ J J& J J+0J J>@hJ J J %$$$
	 rp   c                N   t          |          }t          |d           t          j        d                              dd          }d|  d}t          t          |          5  |                    |g            d d d            n# 1 swxY w Y   t          j        d                              dd          }t          |t          j	        g d                    }d	}t          t          |
          5  |                    ||           d d d            d S # 1 swxY w Y   d S )NrB   r   r  The estimator zc does not raise a ValueError when an empty data is used to train. Perhaps use check_array in train.r6  r  )rB   r   rB   r   rB   r   rB   r   rB   r   rB   r   zG0 feature\(s\) \(shape=\(\d*, 0\)\) while a minimum of \d* is required.rW  )
r   r\   r{  emptyr'  r[   r]  r  r  r  )r   r  rd  X_zero_samplesr  X_zero_featuresrv  rI  s           rn   r   r   	  s   nAQXa[[((A..N	I 	I 	I 	I  

G	,	,	, " "	nb!!!" " " " " " " " " " " " " " " hqkk))"a00O 	"!RX.R.R.R%S%STTA
WC	
#	&	&	& " "	oq!!!" " " " " " " " " " " " " " " " " "s$   $BBB6DD!Dc                V   t           j                            d          }t          ||                    d                    }|                    d          }t           j        |d<   |                    d          }t           j        |d<   t          j        d          }d|d d<   t          ||          }d|  d}d|  d	}d|  d
}	||fD ]X}
t          t                    5  t          |          }t          |d           t          t          ddg|          5  |                    |
|           d d d            n# 1 swxY w Y   |                    ||           t!          |d          rFt          t          ddg|          5  |                    |
           d d d            n# 1 swxY w Y   t!          |d          rFt          t          ddg|	          5  |                    |
           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   Zd S )Nr   ri  r  r  rV  ri  r  rd   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.rr   rB   r  NaNr  r   r   )r{  r  r  r  r  r  r  r.  r  rZ   r^  r   r\   r[   r]  r  r   r   r   )r   r  r+  X_train_finiteX_train_nanX_train_infrv  error_string_fiterror_string_predicterror_string_transformr  rj   s               rn   r   r   	  sX    )


"
"C.11 N ++7+++KK++7+++KK
AAbqbE!.!44APDPPPXXXXGTGGG   - 1 1m444 	1 	1n--IY***
5%.BRSSS * *gq)))* * * * * * * * * * * * * * * MM.!,,, y),, / %.0   / /
 %%g.../ / / / / / / / / / / / / / / y+.. 1 %.2   1 1
 ''0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1)	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	11 1s   '9H E7HEH
EAHF/#H/F33H6F37,H#H9HH		HH	HH 	#H 	c                    t          dd          \  }}t          |          }t          t          d|  d          5  |                    ||           ddd           dS # 1 swxY w Y   dS )z8Test that error is thrown when non-square data provided.rk  ri  )rm  rn  zThe pairwise estimator z+ does not raise an error on non-square datar6  N)r"   r   r[   r]  r  r   r  ru  rv  rj   s        rn   r   r   K	  s     r222DAqn%%I	WdWWW
 
 
   	a                 s   A""A&)A&c                   g d}t          dg dg dgddd          \  }}t          ||t          	          }t          |          }|j        j        r^t          j                            d
          }|	                    |j
        dd          }t          j        |                    d          |<   t          |          }	t          |	|          }t          |	           |	                    ||           |rt#          |	          }
nct%          j        |	          }|	j        }|                    d          rd|v s|                    d          sd|v sJ t%          j        |          }
t1                      }|D ].}t3          |	|          r t5          |	|          |          ||<   /|D ]1} t5          |
|          |          }t7          ||         |           2dS )z'Test that we can pickle all estimators.r_  r)  r  r  r   r   r  r  r  rl  ri  F)rf   r&  r  r  r  s   _sklearn_versionN)r"   r  r0   rM   r   r   r{  r  r  choicer  r  r'  r   r  r\   r  rY   pickledumpsr  r  r  loadsdictr   rg   rU   )r   r  r   check_methodsru  rv  rl   r  maskrj   unpickled_estimatorpickled_estimatorr  r  r  unpickled_results                   rn   r   r   [	  s    SRRMIII&  DAq 	".!JGGGAN##D  %i##B''zz!&"ez44 f		"dn%%I!)Q//AYMM!Q >7	BB #L33*!!*-- 	<{""k&:&::&F&F" '*;;;;;$l+<==VVF ; ;9f%% 	;7WY77::F6N G G?7#6??BB$VF^5EFFFFG Grp   c                $   t          |d          sd S t          |          }t          dd          \  }}t          ||          }t	          ||          }	 t          |          r-t          j        |          }|                    |||           n|                    ||           n# t          $ r Y d S w xY wt          t          d|  d          5  |                    |d d d d	f         |           d d d            d S # 1 swxY w Y   d S )
Nr  2   rB   rm  rr  classesr  zZ does not raise an error when the number of features changes between calls to partial_fit.r6  r&  )r   r   r"   r  r  r   r{  uniquer  NotImplementedErrorr[   r]  )r   r  rj   ru  rv  r  s         rn   r   r   	  s    >=11 n%%I333DAq!.!44A!.!44A## 	(illG!!!Q!8888!!!Q'''    
GT G G G
 
 
 , , 	a3B3i+++, , , , , , , , , , , , , , , , , ,s%   AB* *
B87B8#DD	D	c           	        d\  }}}t          |          }t          |          }t          d|||          \  }}t          ||          }|                    ||           |                    |          }	|	j        ||fk    s%J d                    ||f|	j                              |	j        j	        dk    sJ t          |d          r|                    |          }
t          |
t          j                  sJ |
j        ||fk    s%J d                    ||f|
j                              |
dk                        t                     }|j        |         }t%          ||	           t          |d	          rK|                    |          }t          |t(                    r|j        j        st/          |          D ]}||         j        |d
fk    s+J d                    |d
f||         j                              t%          t          j        ||         d                              t                     |	d d |f                    nx|j        j        sl|j        ||fk    s%J d                    ||f|j                              t%          |                                                    t                     |	           t          |d          rt          |d	          r|t/          |          D ]n}|                    |          d d |f         }|                    |          }t%          t5          |          t5          |d d |f                              kd S d S d S )N)rl  r  r  rl  )rr  rm  n_labels	n_classeszSThe 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  r   zTThe shape of the probability for multioutput data is incorrect. Expected {}, got {}.rB   r2  )rM   r   r$   r  r  r   r  r  r  kindr   r  rt   r{  r  r  r  classes_rW   r  r=  r   
poor_scorerangeargmaxroundr   )r   r  rm  r  r  rl   rj   ru  rv  y_preddecisiondec_preddec_expy_probr  y_proba
y_decisions                    rn   r   r   	  s   %-"IxN##Dn%%I)9x9  DAq 	")Q//AMM!Qq!!F<Iy1111	**0&)X1F*U*U 211 <####y-.. ,..q11(BJ/////~)Y!7777BBH&I&C C 877 qL((--$X.7F+++y/** C((++fd## 	CD,@,K 	C9%% 	 	ay9a.88877=v"Aq	8 8 988 #IfQia00077<<fQQQTl   	 %0 	C<Iy#99993396	*FL4 4 :99 v||~~44S996BBBy-.. N79o3V3V Ny!! 	N 	NA--a00A6G"44Q77Jx00(:aaad;K2L2LMMMM	N N N N	N 	Nrp   c                   t          |          }dx}}t          |          s|dz   }t          dd||          \  }}t          ||          }|                    ||           |                    |          }|j        t          j        d          k    sJ d|j         d            |j        |j        k    sJ d	|j         d
|j         d            d S )Nri  rB   rl  r  )rr  	n_targetsrm  rn  r  zXMultioutput predictions by a regressor are expected to be floating-point precision. Got z insteadzHThe shape of the prediction for multioutput data is incorrect. Expected r  r  )	r   r  r%   r  r  r   r  r{  r  )r   rj   rm  rn  ru  rv  r  s          rn   r   r   	  s   i  II
y)) "M	1	j  DAq 	")Q//AMM!Qq!!F<28I.....	A*0,	A 	A 	A /.. <17"""	4\	4 	4)*	4 	4 	4 #""""rp   c                   t          |          }t          dd          \  }}t          ||d          \  }}t                                          |          }t
          j                            d          }t          j        ||	                    ddd	          g          }|rt          |||g          \  }}}|j        \  }}	t          |d
          r|                    d           t          |           | dk    r,|                    d           |                    d           |                    |           |                    |                                           |j        }
|
j        |fk    sJ t%          |
|          dk    sJ t'          |          j        rd S t          |           t+          j        d          5  |                    |          }d d d            n# 1 swxY w Y   t1          |
|           |
j        t          j        d          t          j        d          fv sJ |j        t          j        d          t          j        d          fv sJ |                    |          }t          j        |          }t1          |t          j        |d         |d         dz                        |d         dv sJ t          |d
          r!t9          |d
          }|dz
  |d         k    sJ d S d S )Nr  rB   r     r  r  )r  r   r[  ri  )ri  AffinityPropagationi)
preferenced   max_iterg?Trecordr  r  r   r&  )r   r&  )r   r"   rC   r6   rt  r{  r  r  concatenater  rY   r  r   r  r\   r  r  labels_r,   rM   r  ru   catch_warningsr   rW   r  r	  r*  rg   )r   clusterer_origr   r   ru  rv  r  X_noiserm  rn  r  pred2labelslabels_sortedri  s                  rn   r   r   
  s]   n%%I333DAq1aa(((DAq&&q))A
)


"
"Cna!&!I!IJKKG C11a/BB1gGIzy,'' +***Y$$$---c*** MM!MM!((**D:)%%%%tQ''#----	, Y		 	-	-	- ) )%%a(() ) ) ) ) ) ) ) ) ) ) ) ) ) )tU### :"(7++RXg->->?????;28G,,bhw.?.?@@@@@ ""7++F
 If%%Mryq!1=3Dq3HII  
 w&&&&y,'' 3Y55
A~r!222223 322s   G11G58G5c                z   t          dd          \  }}t          |          }t          |           t          |d          rx|                    |                              |          }|                    d           |                    |                              |          }t          ||           dS dS )z2Check that predict is invariant of compute_labels.rk  r   r  compute_labelsF)r2  N)r"   r   r\   r   r  r   r  rW   )r   r,  ru  rv  r   rJ  rK  s          rn   r   r   B
  s     333DAqn%%IYy*++ ---""**1--E222--""**1--7G,,,,,- -rp   c                p   d}d}t          |          }t          j                            d          }|                    d          }|                    d          }t          |||          \  }}t          j        d          }t          t                    5  t          t          d	d
|          5 }	|                    ||           d d d            n# 1 swxY w Y   |	j        r	 d d d            d S t          |                    |          ||           d d d            d S # 1 swxY w Y   d S )Nz6Classifier can't train when only one class is present.z8Classifier can't predict when only one class is present.r   r  r  X_testri  rr   classTr	  r6  )r   r{  r  r  r  r  r.  rZ   r^  r[   r]  r  raised_and_matchedrW   r   )
r   classifier_origr  r  r   r+  r  r5  rv  cms
             rn   r   r   Q
  s   OU''J
)


"
"Ckkwk''G[[g[&&F/
GFSSSOGV
A	-	0	0	0 
X 
Xg>N
 
 
 	'NN7A&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'
   	
X 
X 
X 
X 
X 
X 
X 
X 	:--f55qBVWWWW
X 
X 
X 
X 
X 
X 
X 
X 
X 
X 
X 
X 
X 
X 
X 
X 
X 
Xs<   D+6CD+C	D+ C	!D+9%D++D/2D/c                   |  d}|  d}t           j                            d          }|                    d          }|                    d          }t          j        d          dz  }|                                }t          |          }	t          |	d          rd	|g}
t          t          f|}}nd
}
t          t          fd}}t          ||
d|          5 }|	                    |||           |j        r	 ddd           dS t          |	                    |          t          j        d          |           ddd           dS # 1 swxY w Y   dS )zCheck that classifiers accepting sample_weight fit or throws a ValueError with
    an explicit message if the problem is reduced to one class.
    zu failed when fitted on one label after sample_weight trimming. Error message is not explicit, it should have 'class'.z; prediction results should only output the remaining class.r   )ri  ri  r  ri  r   r   z\bclass(es)?\bz\bsample_weight\bNTr	  r  r6  )r{  r  r  r  r*  r  r   r`   r  r]  rG  r[   r  r7  rW   r   r.  )r   r8  	error_fiterror_predictr+  r  r5  rv  r   r   r  err_typer  r9  s                 rn   r   r   i
  s     	; 	; 	;  XXXM
)


"
"Ckkxk((G[[h[''F
	"AFFHHM''J_55 :"M2+Z8)'$&
3T'	g	F	F	F 	
"w???  			
 	
 	
 	
 	
 	
 	
 	
 	v&&]	
 	
 	
 	
	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
s   !E7EEEc                   t          dd          \  }}|                    |          }t          ||d          \  }}t                                          |          }||dk             }||dk             }| dv r.||                                z  }||                                z  }|rt          ||||g          \  }}}}||fg}t          |          }	|	j        j	        r|
                    ||f           |D ]\  }
}t          j        |          }t          |          }|
j        \  }}t          |          }t!          ||
          }
t#          ||          }t%          |           |	j        sPt)          t*          d|  d	
          5  |                    |
|d d                    d d d            n# 1 swxY w Y   |                    |
|           |                    |
                                |                                           t1          |d          sJ |                    |
          }|j        |fk    sJ |	j        j        st7          ||          dk    sJ d}d}|	j        s|	j        j        rlt)          t*          |                    | d          
          5  |                    |
                    dd                     d d d            n# 1 swxY w Y   n\t)          t*          |                    | d          
          5  |                    |
j                    d d d            n# 1 swxY w Y   t1          |d          r	 |!                    |
          }|dk    rk|	j"        j#        r|j        |fk    sJ n|j        |dfk    sJ |$                                dk                        tJ                    }tM          ||           n3|j        ||fk    sJ tM          t          j'        |d          |           |	j        s|	j        j        rlt)          t*          |                    | d          
          5  |!                    |
                    dd                     d d d            n# 1 swxY w Y   n\t)          t*          |                    | d          
          5  |!                    |
j                    d d d            n# 1 swxY w Y   n# tP          $ r Y nw xY wt1          |d          r|)                    |
          }|j        ||fk    sJ tM          t          j'        |d          |           tU          t          j+        |d          t          j,        |                     |	j        s|	j        j        rlt)          t*          |                    | d          
          5  |)                    |
                    dd                     d d d            n# 1 swxY w Y   n\t)          t*          |                    | d          
          5  |)                    |
j                    d d d            n# 1 swxY w Y   t1          |d          rn|-                    |
          }t]          |t          j/        |          dd           tM          t          j0        |          t          j0        |                     d S )N,  r   r  r   r  r   )BernoulliNBMultinomialNBComplementNBCategoricalNB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.r6  r&  r  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.r   rB   r  r  r  r     r  )r  )1r"   r  rC   r6   rt  minrY   rM   r   r   r`  r{  r	  r/  r  r   r  r  r\   r   r[   r]  r  r  r   r   r  r+   r   r   r  r'  Tr  r   r   r  r  rW   r  r
  r  rV   sumr.  r  rT   logargsort)r   r8  r   r   X_my_my_bX_bproblemsrl   ru  rv  r  r  rm  rn  r   r  msg_pairwiserI  r  r  r  
y_log_probs                           rn   r   r   
  s	    Ca888HC
**W

CsCa000HC



(
(
-
-C
cQh-C
cQh-CPPPswwyyswwyy M6S#s7KLLS#sc
|HO$$D' $c
### pO pO1)A,,LL	 !	:?++
%j!44%j!44$$$! 
	*<d < < <   	* 	* q!CRC&)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	q!qxxzz188::...z:.....##A&&|	|++++#. 	4!!V,,t3333G 	
 	 ! 		,' ,(//i@@   9 9 &&qyyQ'7'7888	9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 J

40K0KLLL , ,&&qs+++, , , , , , , , , , , , , , ,:233 	%77::>>'5 @'~)====='~)Q???? ( 0 01 4<<SAAH&x8888#>i-CCCCC&ry'B'B'BFKKK ) >/ >#&$0$7$7>Q$R$R   K K '882q9I9IJJJ	K K K K K K K K K K K K K K K $&$'JJt5H$I$I   > > '88===	> > > > > > > > > > > > > > >
 '    :// 	O--a00F<Iy#99999rya888&AAA%bfV!&<&<&<bgi>P>PQQQ% 6?+ 6" , 3 3D/ J J   C C #002q1A1ABBB	C C C C C C C C C C C C C C C  " #

4 A A   6 6 #00555	6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
 z#677 O'99!<<

BF6NNADIIII"2:j#9#92:f;M;MNNNapO pOs   F::F>	F>	-*K##K'	*K'	M  M	M	C6S2*R	=S2	R	S2R	.S2?S&S2&S*	*S2-S*	.S22
S?>S?*XX	X	:Y!!Y%	(Y%	c                    | |k     r| }|dz   }n|}| dz   }t          j        |          }d}t          t          j        |||                             dk    s
J |            d S )NrB   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/  r	  )num_outliersexpected_outliersr  startendsorted_decisionrI  s          rn   check_outlier_corruptionrZ    s     '''!#!Q
 gh''O	9 
 rys34455:::C:::::rp   c                x   d}t          |d          \  }}t          |d          }|rt          |          }|j        \  }}t	          |          }t          |           |                    |           |                    |                                           |                    |          }|j        |fk    sJ |j	        j
        dk    sJ t          t          j        |          t          j        ddg                     |                    |          }	|                    |          }
|	|
fD ]/}|j	        t          j	        d	          k    sJ |j        |fk    sJ 0t#          t$                    5  |                    |j                   d d d            n# 1 swxY w Y   |	dk                        t*                    }d||dk    <   t          ||           t#          t$                    5  |                    |j                   d d d            n# 1 swxY w Y   |
|j        z
  }t/          ||	           t#          t$                    5  |                    |j                   d d d            n# 1 swxY w Y   t1          |d
          rt1          |d          sd}||z  }|                    |           |                    |           |                    |          }t          j        |dk              }||k    r,|                    |          }	t7          |||	           d S d S d S d S )Nr?  r   r  r   r  r  r&  rB   r  r   noveltyr)  r   )r"   rC   rY   r  r   r\   r  r  r   r  r  rW   r{  r	  r  r  r  r[   r]  rH  r  r  offset_rT   r   r  rI  rZ  )r   r  r   rm  ru  rc  rn  rj   r  r  scoresoutputr  y_decrV  r   rU  s                    rn   r   r   /  s   I	:::DAq"""A )%a((GIzn%%IY MM!MM!((**q!!F<I<''''<####ry(("(B7*;*;<<<**1--H$$Q''FV$ , ,|rx000000|	|+++++ 

		  !#               A%%c**H HX]x((( 

		 ) )##AC((() ) ) ) ) ) ) ) ) ) ) ) ) ) ) Y&&EE8$$$ 

		 % %$$$% % % % % % % % % % % % % % % y/** P79i3P3P P
 )I5=999a""1%%vfk** ,,, 22155H$\3DhOOOOO'P P P P" -,s6   :F!!F%(F%7HH"%H"I>>JJc                f   t          |d          sd S d|j        vrd S |j        d         }t          d |D                       st          d          |D ][}t	          |t
                    rD|j        t          k    r*|j        dk    r|j	        dk    r|j        dk    s|j
        dv s
J d	            \d S )
N_parameter_constraintsr   c                8    g | ]}t          |t                    S rA  )rt   rE   )r<  cs     rn   rk  z/check_outlier_contamination.<locals>.<listcomp>  s"    KKKA
1h''KKKrp   zDcontamination constraints should contain a Real Interval constraint.        r  r   >   rightneitherz:contamination constraint should be an interval in (0, 0.5])r   rc  rF  r  rt   rE   r4  r
   leftrg  closed)r   r  contamination_constraints
constraints       rn   r   r   w  s     >#;<< nCCC . Eo VKK1JKKKLL 
R
 
 	
 0 L L
j(++ 	L4''Os**$++_q((J,=AU,U,U,UK -V,U,UL Lrp   c           	     D   t          ddddddd          \  }}t          |          }|d d	         |d d	         }}|d	d          }t          |||
          \  }}|                                }t	          |          }t          |          }	t          |	           |	                    ||                              |          }
|	                    ||                              |          }|	                    ||                              |          }t          |
|           t          |
|           |
j
        |j
        k    sJ |
j
        |j
        k    sJ t          |
          t          |          k    sJ t          |
          t          |          k    sJ d S )Nr$  r   r  r  r  Tr   rm  rn  r  r  lengthallow_unlabeledrr  P   r4  )r$   r7   r  r  r=  r   r\   r  r   rW   r  r4  )r   r8  ru  rv  r  y_trainr5  y_train_list_of_listsy_train_list_of_arraysr   r  y_pred_list_of_listsy_pred_list_of_arrayss                rn   r   r     s   )  DAq 	aA"vq"vWGrssVF/QWXXXOGV#NN,,!']]''JZ   ^^GW--55f==F%>>'3HIIQQ  'NN74JKKSS  v4555v3444<066666</55555<<4 5666666<<4 455555555rp   c           	        t          |          }t          |           d\  }}}t          |d|dddd          \  }}t          |          }|d|          || d         }	}|d|          || d         }}
t	          |||		          \  }}	|                    ||
           d
}t          ||d          }|t          |  d| d           ||	          }t          |t          j
                  sJ |  dt          |           d            |j        |j        k    sJ |  d|j         d|j         d            |j        |j        k    sJ |  d|j         d|j         d            dS )zeCheck the output of the `predict` method for classifiers supporting
    multilabel-indicator targets.r$     r  r   r  r  Tr   rn  Nr4  r    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 r  z>.predict does not output the same dtype than the targets. Got )r   r\   r$   r7   r  r  rg   rQ   rt   r{  r  r4  r  r  )r   r8  r   rm  	test_size	n_outputsru  rv  r  r5  rr  y_testresponse_method_namepredict_methodr  s                  rn   r   r     s    ''JZ   &0#Iy))  DAq 	aA)na
nVG)na
nVG/QWXXXOGVNN7G$$$$Z)=tDDN$OO1EOOOPPP^F##F fbj))   	# 	#<<	# 	# 	#   <6<''' 	& 	& 	& 	&l	& 	& 	& ('' <6<''' 	9 	9|	9 	9)/	9 	9 	9 (''''rp   c           	        t          |          }t          |           d\  }}}t          |d|dddd          \  }}t          |          }|d|          || d         }	}|d|          }
t	          |||		          \  }}	|                    ||
           d
}t          ||d          }|t          |  d| d           ||	          }t          |t                    rt          |          |k    s!J d|  dt          |           d| d            |D ]|}|j        |dfk    sJ d|  d|j         d|df d            |j        j        dk    sJ d|  d|j         d            d|  d}t          |                    d          d|           }dS t          |t           j                  rz|j        ||fk    sJ d|  d|j         d||f d            |j        j        dk    sJ d|  d|j         d            d|  d}t%          d||           t%          |d|           dS t'          dt)          |           d|  d          )zkCheck the output of the `predict_proba` method for classifiers supporting
    multilabel-indicator targets.rx  r   r  r  Tr   rn  Nr4  r  rz  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).rB   r  r6  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\   r$   r7   r  r  rg   rQ   rt   r=  r/  r  r  r  rT   rI  r{  r  rX   r]  r4  )r   r8  r   rm  r~  r  ru  rv  r  r5  rr  r  predict_proba_methodr  r  r  s                   rn   r   r     s    ''JZ   &0#Iy))  DAq 	aA)na
nVG)nG/QWXXXOGVNN7G$$$*":/CTJJ#$OO1EOOOPPP!!&))F &$ /
6{{i'''8D 8 8f++8 8+48 8 8 (''
  	B 	BD:)Q///% % %)-% % q>% % % 0// :?c)))) ) ):) ) ) *))% % % %  DHH!H,,aAAAAA'	B 	B( 
FBJ	'	' 
|	955555D 5 5=C\5 5%y15 5 5 655
 | C'''KD K K39<K K K (''
CD C C C 	
 	!VW5555&!W555555BT&\\ B Bt B B B
 
 	
rp   c           	        t          |          }t          |           d\  }}}t          |d|dddd          \  }}t          |          }|d|          || d         }	}|d|          }
t	          |||		          \  }}	|                    ||
           d
}t          ||d          }|t          |  d| d           ||	          }t          |t          j
                  sJ |  dt          |           d            |j        ||fk    sJ |  d|j         d||f d            |j        j        dk    sJ |  d|j         d            dS )zoCheck the output of the `decision_function` method for classifiers supporting
    multilabel-indicator targets.rx  r   r  r  Tr   rn  Nr4  r  rz  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\   r$   r7   r  r  rg   rQ   rt   r{  r  r4  r  r  r  )r   r8  r   rm  r~  r  ru  rv  r  r5  rr  r  decision_function_methodr  s                 rn   r   r   ?  s    ''JZ   &0#Iy))  DAq 	aA)na
nVG)nG/QWXXXOGVNN7G$$$.&z3GNN'$OO1EOOOPPP%%f--F fbj))   	( 	(V	( 	( 	(   <Iy1111 	% 	%06	% 	%y!	% 	% 	% 211
 <### 	( 	(	( 	( 	( $####rp   c                    t          |          }d|  d}t          t          |          5  |                                 ddd           dS # 1 swxY w Y   dS )zCheck the error raised by get_feature_names_out when called before fit.

    Unfitted estimators with get_feature_names_out should raise a NotFittedError.
    rd   zU should have raised a NotFitted error when fit is called before get_feature_names_outr6  N)r   r[   r(   get_feature_names_out)r   r  rj   r  s       rn   !check_get_feature_names_out_errorr  n  s     n%%I	(T 	( 	( 	(  
	0	0	0 * *'')))* * * * * * * * * * * * * * * * * *s   AAAc                    t          dd          \  }}t          ||          }t          |          }t          ||          }t	          |           |                    ||          |u sJ dS )z+Check if self is returned when calling fit.r      rr  rm  N)r"   r  r   r  r\   r  r  s        rn   r   r   ~  sx     1333DAq!.!44An%%I!)Q//AY==A)++++++rp   c                   t          dd          \  }}t          ||          }t          |          }t          ||          }t	          ||g          \  }}t          |           |                    ||          |u sJ dS )zCheck that the estimator can handle readonly memmap backed data.

    This is particularly needed to support joblib parallelisation.
    r   r  r  N)r"   r  r   r  rY   r\   r  r  s        rn   r   r     s     1333DAq!.!44An%%I!)Q//A$aV,,DAqY==A)++++++rp   c                *   d}t                      \  }}t          |          }dD ]m}t          ||          r[t          t          |                    |                    5   t          ||          |           ddd           n# 1 swxY w Y   ndS )z}Check that predict raises an exception in an unfitted estimator.

    Unfitted estimators should raise a NotFittedError.
    a  Estimator should raise a NotFittedError when calling `{method}` before fit. Either call `check_is_fitted(self)` at the beginning of `{method}` or set `tags.requires_fit=False` on estimator tags to disable this check.
- `check_is_fitted`: https://scikit-learn.org/dev/modules/generated/sklearn.utils.validation.check_is_fitted.html
- Estimator Tags: https://scikit-learn.org/dev/developers/develop.html#estimator-tags)r  r   r  r  )r  r6  N)rw  r   r   r[   r(   r  rg   )r   r  r  ru  rv  rj   r  s          rn   r   r     s    	    DAqn%%I . . 9f%% 	.f0M0MNNN . .*	6**1---. . . . . . . . . . . . . . .. .s   !BB	B	c                   t          |          }t          j                            d          }d}t	          ||                    |df                    }t          j        |          dz  }t          ||          }t          |          }t          |           |
                    ||           |                    |          }t          |           t          j        d          5 }	t          j        dt                     t          j        dt                      |
                    ||d d t          j        f                    d d d            n# 1 swxY w Y   |                    |          }
d	d
                    d |	D                       z  }|j        j        s#t+          |	          dk    s
J |            d|v sJ t-          |                                |
                                           d S )Nr   r)  r  r  Tr'  alwaysignorez)expected 1 DataConversionWarning, got: %srn  c                ,    g | ]}t          |          S rA  r  )r<  w_xs     rn   rk  z)check_supervised_y_2d.<locals>.<listcomp>  s    cSrp   zPDataConversionWarning('A column-vector y was passed when a 1d array was expected)rM   r{  r  r  r  r  r*  r  r   r\   r  r   ru   r+  simplefilterr&   RuntimeWarningnewaxisrq  r   r   r/  rT   r  )r   r  rl   r+  rm  ru  rv  rj   r  w	y_pred_2drI  s               rn   r   r     s   N##D
)


"
"CI!.#++Iq>+2R2RSSA
	)q A!.!44An%%IYMM!Qq!!FY 
	 	-	-	- +h(=>>>h777a111bj=)***+ + + + + + + + + + + + + + + !!!$$I
5		Q9 9 C ( 
1vvzzz3zzz7:=> > > > FLLNNIOO$5$566666s   +AEEEc                F   t          j        |          }t          |          }|dk    r| |                                 k    } t	          |           |                    | |           |                    |           }t          |d          r|                    |           }t          |t           j
                  sJ t          |          dk    r|                                dk                        t                    }|j        |         }	t!          |	|d|dd                    t%          t&          |	                    dd                    t%          t&          |                    d	
           nt)          |dd          dk    rt          j        |d                              t                    }
|j        |
         }t!          ||d|dd                    t%          t&          |                    dd                    t%          t&          |                    d	
           t!          ||j        d|dd                    t%          t&          |                    dd                    t%          t&          |j                            d	
           d S )Nr@  r  r   r   z0decision_function does not match classifier for z: expected 'rn  z', got 'r  r6  decision_function_shapeovrrB   r  z"Unexpected classes_ attribute for )r{  r	  r   meanr\   r  r   r   r  rt   r  r/  r  r  r  r  rW   rq  r  r  rg   r  )ru  rv  r   r8  r  r   r  r  r  r  
decision_yy_exps               rn   check_classifiers_predictionsr    s   illG''J}LZ   NN1a""Fz.// "//22(BJ/////w<<1 ((1,44S99H )(3G JJIIc#w//0000IIc#v..////     Z!:EBBeKK8!444;;C@@J'
3E JJIIc#uoo....IIc#v..////     JJIIc#w''((((IIc#z2334444	
	 	 	 	 	 	rp   c                    | dv r|n|S )N)LabelPropagationLabelSpreadingSelfTrainingClassifierrA  )r   rv  y_namess      rn    _choose_check_classifiers_labelsr    s    
 SSS 	
rp   c                   t          ddd          \  }}t          ||d          \  }}t                                          |          }||dk             }||dk             }t	          ||          }t	          ||          }g d}d	d
g}t          j        ||          }t          j        ||          }	|||	fg}
t          |          j        j	        r|

                    |||f           |
D ]C\  }}}||                    d          fD ]%}t          | ||          }t          ||| |           &Dddg}t          j        ||          }	t          | ||	          }t          ||| |           d S )Nr)  r   r  )rm  rr  r  r   r  r   )onetwothreer  r  Or&  rB   )r"   rC   r6   rt  r  r{  takerM   r   r   r`  r  r  r  )r   r8  X_multiclassy_multiclassX_binaryy_binarylabels_multiclasslabels_binaryy_names_multiclassy_names_binaryrP  ru  rv  r  	y_names_ir  s                   rn   r   r   $  s   !+1#" " "L, ")|RS!T!T!TL,!##11,??LLA-.HLA-.H,_lKKL((CCH///ENM!2LAAW]H55N8^45H  0< J|5GHIII! H H1g!7>>##6#67 	H 	HI1$9EEB)!RGGGG	H GMW]H55N/hOOH!(HdOLLLLLrp   c           
     T   t                      \  }}t          ||d d                   }t          j                            d          }|                    d|j        d                   }t          ||          }t          j                            d          }t          |          }t          |          }t          |           t          |           | t          v rFt          j        |d|z  |                    dt          |                    z   g          }|j        }n|}|                    ||           |                    |          }	|                    ||                    t"                               |                    |          }
t%          |	|
d|            d S )Nr  r   r  r  r   r  r  )rw  r  r{  r  r  r  r  r  r   r\   rN   r<  r/  rH  r  r   r  r  rT   )r   regressor_origru  rc  r+  rv  regressor_1regressor_2r  pred1r.  s              rn   r   r   F  sx     DAq!.!CRC&99A
)


"
"CAAGAJ''A!.!44A
)


"
"C''K''K[!!![!!!"""Y1q53;;qs1vv;#>#>>?@@T OOAr""EOOAryy''(((""EE5tT::::::rp   c           
     `   t                      \  }}|                    |          }t          |          }t          |          }t	          ||          }t          ||          }| t          v ret          j        	                    d          }t          j
        |d|z  |                    dt          |                    z   g          }|j        }n|}|rt          |||g          \  }}}t          |d          st          |d          rd|_        | dk    rd|_        t%          t&          d|  d	
          5  |                    ||d d                    d d d            n# 1 swxY w Y   t+          |           |                    ||           |                    |                                |                                           |                    |          }	|	j        |j        k    sJ t3          |          j        j        s|                    ||          dk    sJ d S d S )Nr   r   r  alphasalphar  PassiveAggressiveRegressorrD  rE  r6  r&  r  )rw  r  r7   r   r  r  rN   r{  r  r  r<  r  r/  rH  rY   r   r  Cr[   r]  r  r\   r  r   r  rM   r   r  r  )
r   r  r   r   ru  rv  r   r+  r  r  s
             rn   r   r   b  st      DAq	AaAn%%I!)Q//A!)Q//A"""i##A&&Y1q53;;qs1vv;#>#>>?@@T 9,aBZ881b9h'' GIw,G,G 	+++	 
$d $ $ $
 
 
 	! 	! 	a3B3   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! YMM!RMM!((**biikk***q!!F<28####
 I-8 ,q"%%++++, ,++s   ;E&&E*-E*c                D   t           j                            d          }t          |          }|                    d          }t          ||          }t          ||d d df                   }|                    ||           g d}|D ]}t          ||          rJ d S )Nr   )ri  r  r  )r  r  r  )	r{  r  r  r   normalr  r  r  r   )r   r  r  r   ru  rv  r  r  s           rn   r   r     s     )


"
"Cn%%I


  A!.!44A!)Qqqq!tW55AMM!QGGGE 1 1	9i0000001 1rp   c                   t          |          j        j        rddg}ndg}|D ]}t          |dd          \  }}t	          ||dd          \  }}}}	t          |          j        j        r t          ||          }t          ||          }t          t          j
        |                    }|dk    rdd	d
}
ndd	d	d}
t          |                              |
          }t          |d          r|                    d           t          |d          r|                    d           t          |d          r|                    d           t          |d          r|                    d           t          |           |                    ||           |                    |          }t          |          j        j        st          j        |dk              dk    sJ d S )Nr   r  r   rk  )r  rr  r  r  r~  rr    g-C6?)r   rB   )r   rB   r   r   n_iterr$  r  r&  r%  min_weight_fraction_leafr  )r  n_iter_no_change)r  gףp=
?)rM   r   r   r"   r3   r   r   r0   r/  r{  r	  r   r  r   r\   r  r   r  r  )r   r8  rP  	n_centersru  rv  r  r5  rr  r  r   r   r  s                rn   r   r     s(     0< q63 #/ #/	)!LLL1+;qCa,
 ,
 ,
(&
 O$$/8 	300F '22G	'**++	>>#//LL#6::L?++66L6QQ
:x(( 	.!!!---:z** 	1!!4!000:9:: 	A!!4!@@@:122 	7!!2!666$$$w(((##F++ ((8C 	/76Q;''$....G#/ #/rp   c                   t          |          }t          |d          r|                    d           t          |d          r|                    d           t          |           |                    ||           |                    |          }|                    d           |                    ||           |                    |          }	t          ||	d	
          t          ||d	
          k    sJ d S )Nr  r$  r  r&  r  r%  balancedr  weighted)average)r   r   r  r\   r  r   r-   )
r   r8  r  rr  r5  r  r$  r   r  y_pred_balanceds
             rn   'check_class_weight_balanced_classifiersr    s!    ''Jz8$$ *S)))z:&& -t,,,Z   NN7G$$$''Fz222NN7G$$$ ((00OFOZ@@@8
D D D      rp   c                   t          j        ddgddgddgddgddgg          }t          j        g d          }t          |          }t          |d          r|                    d	           t          |d
          r|                    d           t          |d          r|                    d           t          |           |                    d           |                    ||          j                                        }t          |          }t          t          t          j        |                              }|t          j        |dk              |z  z  |t          j        |dk              |z  z  d}|                    |           |                    ||          j                                        }	t          ||	d| z             dS )z4Test class weights with non-contiguous class labels.      r   gr  rf  )rB   rB   rB   r&  r&  r  r  r  r&  r%  r3  r  r5  r  r  rB   r&  )rB   r&  z>Classifier %s is not computing class_weight=balanced properly.r6  N)r{  r  r   r   r  r\   r  coef_r  r/  r  r	  rI  rT   )
r   r  ru  rv  r   coef_balancedrm  r  r   coef_manuals
             rn   r   r     s    	4,q	D$<#sc3ZPQQA
"""##A~&&Jz8$$ + 	T***z:&& -t,,,z4   $###Z    z222NN1a((.3355M AIc")A,,''((I qAv23R945 L |444..A&&,1133KPSWW     rp   c                   t          dd          \  }}t          ||t                    }t          |          }t	          ||          }t          |           |                                }t          |          }|                    ||           |                                }|	                                D ]N\  }}	||         }
t          j        |
          t          j        |	          k    sJ d| d|d|	d|
d		            Od S )
Nr   r  r  r  rd   z, should not change or mutate  the parameter z from z to z during fit.)r"   r  r0   r   r  r\   r   r   r  r  joblibhash)r   r  ru  rv  rj   paramsoriginal_params
new_params
param_nameoriginal_value	new_values              rn   r~   r~     s)   1333DAq!.!JGGGAn%%I!)Q//AY !!##Fv&&O MM!Q %%''J&5&;&;&=&= 
 
"
Nz*	 {9%%^)D)DDDDD ttZZZ< EDDD
 
rp   c                .   	 t          |          }n!# t          $ r t          d|  d          w xY wt          t          |          j        d          rdS t          t          |          j                  }d d t          |          j        D             D             }t          t          |                    t          |          z
  t          |          z
  }t          d |D                       }|rJ d| dt          |          d	            dS )
zCheck setting during init.rd   z9 should store all parameters as an attribute during init.rg  Nc                    g | ]	}|D ]}|
S rA  rA  )r<  params_parentr*  s      rn   rk  z3check_no_attributes_set_in_init.<locals>.<listcomp>D  s?       "   	   rp   c              3  4   K   | ]}t          |          V  d S r;  )rS   )r<  parents     rn   r>  z2check_no_attributes_set_in_init.<locals>.<genexpr>F  s*      VVFi//VVVVVVrp   c                <    g | ]}|                     d           |S )rc  )r  )r<  rd  s     rn   rk  z3check_no_attributes_set_in_init.<locals>.<listcomp>M  s)    RRRT__S=Q=QRRRRrp   zR should not set any attribute apart from parameters during init. Found attributes r  )
r   r  r   r4  r  rS   __mro__setr  sorted)r   r  rj   init_paramsparents_init_paramsinvalid_attrs         rn   r|   r|   4  sW   
 .))		 
 
 
XXXX
 
 	


 tI')>?? DOO455K VVd9oo>UVVV   tI''#k*:*::SAT=U=UULRRRRRSSL    44%%%%	'    s    0c                   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g	          }t          j        g d          }t          ||          }t          |          }|                    ||           |                    |          }|                                 t          j        |j	                  sJ |                    |          }t          ||           t          j        t          j        |                    }t          j        |j	                  sJ |                    |          }t          ||           d S )Nr&  rB   r   )	rB   rB   rB   r   r   r   r  r  r  )r{  r  r  r   r  r   r   r   r  r  rW   r  r  r  )r   r  ru  rv  r=  	pred_origr  s          rn   r   r   U  sI   
HHHFFFHFH
	
	 	A 	,,,--A!.!44A


CGGAqMMMAI LLNNN?39%%%%%;;q>>DtY''' ,v|C((
)
)C?39%%%%%;;q>>DtY'''''rp   c                   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g          }t          ||          }t          j        g d          }t          ||          }dD ]}t	          | ||||           d S )Nr  r   rB   r   r  )rB   rB   rB   r   r   r   rB   rB   rB   r   r   r   
NotAnArrayPandasDataframe)r{  r  r  r  "check_estimators_data_not_an_arrayr   r  ru  rv  obj_types        rn   r   r   x  s    
FFFFFFFFFFFF	
	 	A  	".!44A
55566A!.!44A5 Q Q*4AxPPPPQ Qrp   c                    t                      \  }}t          ||          }t          ||          }dD ]}t          | ||||           d S )Nr  )rw  r  r  r  r  s        rn   r   r     se      DAq!.!44A!.!44A5 Q Q*4AxPPPPQ Qrp   c                   | t           v rt          d          t          |          }t          |          }t          |           t          |           |dvr"t	          d                    |                    |dk    rCt          t          j        |                    }t          t          j        |                    }n	 dd l	}	t          j        |          }|j
        dk    r|	                    |d          }n|	                    |d          }|	                    t          j        |          d          }n# t          $ r t          d	          w xY w|                    ||           |                    |          }
|                    ||           |                    |          }t!          |
|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   rB   Fr  zDpandas is not installed: not checking estimators for pandas objects.r  r  )rN   rQ   r   r\   r]  r  ry  r{  r|  r  r  r!  r   r"  r  r   rT   )r   r  ru  rv  r  estimator_1estimator_2r  X_r#  r  r.  s               rn   r  r    s   """%
 
 	
 ''K''K[!!![!!!8886==hGGHHH<A''A''
	ABw!||YYrY..\\"5\11bjmm%88BB 	 	 	V  	 OOB##EOOAq""EE5tT::::::s   A;E Ec                x    	 t          |           dS # t          $ r}t          d|  d| d          |d}~ww xY w)z+Checks whether the estimator can be cloned.zCloning of  failed with error: r  N)r   r_  r  )r   r  rd  s      rn   rx   rx     sd    Rn R R RI4IIQIIIJJPQQRs    
949c                    t          |          }	 t          |           dS # t          $ r}t          d|  d| d          |d}~ww xY w)z0Check that the estimator has a functioning repr.zRepr of r  r  N)r   reprr_  r  )r   r  rj   rd  s       rn   r{   r{     sk    n%%IOY O O OFFF!FFFGGQNOs   " 
AAAc                   |j         }t          |          }t          t                    5  |                                |u sJ t          |j        d|j                  }	 d d fdt          |          j        	                                D             fdt          |          j        	                                D             }n## t          t          f$ r Y d d d            d S w xY w|                                fdD             } |di |}|                                }|D ]}t          t          t          t           t"          t%          d           t$          h}	|	                    t(          j        	                                           t%          |j                  |	v pt/          |j                  }
|
sWJ d|j         d	|j         d
t%          |j                  j         d|j         dt5          d |	D                        d            |j        |                                vr$|j        J d|j         d	|j         d            *||j                 }t9          |t(          j                  rt=          ||j                   hd|j         d}t?          |          r||j        u s
J |            ||j        k    s
J |            	 d d d            d S # 1 swxY w Y   d S )Nrr   rg  c                x    | j         dk    o/| j        | j        k    o| j        | j        k    o| j        | j        k    S z*Identify hyper parameters of an estimator.r~  r   r  VAR_KEYWORDVAR_POSITIONALr  r  r  s    rn   param_default_valuezCcheck_parameters_default_constructible.<locals>.param_default_value  sI     Ff$ -!-/-!"22- 	QW,rp   c                x    | j         dk    o/| j        | j        k    o| j        | j        k    o| j        | j        k    S r  r  r  s    rn   param_requiredz>check_parameters_default_constructible.<locals>.param_required  sK     Ff$ -!-/- !"22- 	QW,rp   c                4    g | ]} |          |j         S rA  r  )r<  r  r  s     rn   rk  z:check_parameters_default_constructible.<locals>.<listcomp>  s;     % % %~~VWGXGX%% % %rp   c                *    g | ]} |          |S rA  rA  )r<  r  r  s     rn   rk  z:check_parameters_default_constructible.<locals>.<listcomp>  s;     $ $ $BUBUVWBXBX$$ $ $rp   c                *    i | ]}|v ||         S rA  rA  )r<  r*  
old_paramsrequired_params_namess     rn   r  z:check_parameters_default_constructible.<locals>.<dictcomp>  s6     
 
 
--- :e$---rp   zParameter 'z' of estimator 'z' is of type z which is not allowed. 'z(' must be a callable or must be of type c              3  $   K   | ]}|j         V  d S r;  r  )r<  r4  s     rn   r>  z9check_parameters_default_constructible.<locals>.<genexpr>?  s$      ??t}??????rp   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.rA  ) ri   r   rZ   r^  r  rg   r  r   r  r  rG  r]  r   r  r  r  r   r~  r4  updater{  
sctypeDictr  rB  r   re   r  r   rt   r  rW   rD   )r   r  	Estimatorrj   initdefault_value_paramsr  r  
init_paramallowed_typesallowed_valueparam_valuefailure_textr  r  r  r  s                @@@@rn   r  r    s    (In%%I	-	0	0	0 uK uK ##%%2222 y)+@)BTUU(	    "% % % % )$ : A A C C% % %!$ $ $ $$T??5<<>>$ $ $   :& 	 	 	 kuK uK uK uK uK uK uK uKd	 ))++

 
 
 
 
#
 
 

 I,,,,	%%''. 3	K 3	KJT

M   !5!5!7!7888 Z'((M9 - +,,  !  Cjo C C&C C
*++4C C OC C ???????	C C C   fkkmm33!)11JJO J J!*J J J 211
  1K+rz22 K";
0BCCCC; ; ; ;  !-- K&**<<<<l<<<<&**<<<<l<<<<g3	KEuK uK uK uK uK uK uK uK uK uK uK uK uK uK uK uK uK uKs7   4K0%A*CK0C0!K0/C00G2K00K47K4c                   t          |           }|j        j        r'|dt          |                                          z   z  }|j        J|j        j        s>|j        dk    r3t          j	        ||j
        d         k    ||j
        d         dz             }|j        j        r!|j        j        st          j        |d          S |S )NrB   r   )r&  rB   )rM   r   r  r  rG  r   r   r  r{  whereflatr   r   r'  )rj   rv  rl   s      rn   r  r  Y  s     ID%  	
QQUUWW($0 	)FQJJHQ!&)^Qq	A66 $ &T-=-K &z!W%%%Hrp   c                   t          |           j        j        r|d d df         }||d d df         }t          |           j        j        r0||                                z
  }|||                                z
  }t          |           j        j        rt          |           j        j        rt          j        nt          j	        }t          j
        ||                                z
                                |          }|<t          j
        ||                                z
                                |          }| j        j        dk    r0||                                z
  }|||                                z
  }|}t          |           r&t          |d          }|t          ||d          }n3t          |           j        j        r |||          }| |||          }|||fS |S )Nr   SkewedChi2Sampler	euclidean)r  )rM   r   one_d_arrayr  rG  categoricalr   r{  r  r  r  r  ri   re   r  r/   r   )rj   ru  r5  r  r  X_ress         rn   r  r  n  s    	%1 "aaadGAAAqD\F 	%3 +Kfjjll*F	%1 E&y11<FT

BHHa!%%''k##**511Xv

466==eDDF#':::Kfjjll*FE 9%% 	'"1[999'+  F 
)			'	0 'q!VFA&&Ff}Lrp   c                N   t          |          }t          |          }t          d          \  }}t          ||          }t	          |d           t          ||          }||                                z  }|j        j        rGt          t          d          5  |                    ||           ddd           dS # 1 swxY w Y   dS 	 |                    ||           dS # t          $ r5}dt          |            d|j        j         d	}t!          |          |d}~ww xY w)
zTest that the estimator correctly sets the tags.input_tags.positive_only

    If the tag is False, the estimator should accept negative input regardless of the
    tags.input_tags.pairwise flag.
    T)
return_X_yr   zNegative values in datarW  Nrd   z raised z unexpectedly. This happens when passing negative input values as X. If negative values are not supported for this estimator instance, then the tags.input_tags.positive_only tag needs to be set to True.)r   rM   r!   r  r\   r  r  r   r  r[   r]  r  r_  r  ri   re   r  )r   r  rj   rl   ru  rv  rd  r  s           rn   r   r     s    n%%IID%%%DAq!)Q//AY"""!)Q//AMA$ 1J&?@@@ 	  	 MM!Q	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 		1MM!Q 	1 	1 	1WT$ZZ W W1E W W W  !))q0	1s*   B??CCC% %
D$/0DD$c                ~   t          |d          sd S t          |          }t                      }|j        |j        }}t          ||          }t          |d           t          ||          }|                    ||           t          j
        t          j        |j                  dk              s
J d            d S )Nr&  r   rB   zEstimators with a `max_iter` parameter, should expose an `n_iter_` attribute, indicating the number of iterations that were executed. The values in the `n_iter_` attribute should be greater or equal to 1.)r   r   r!   r}  targetr  r\   r  r  r{  allr|  n_iter_)r   r  rj   irisru  r  s         rn   r   r     s    
 >:.. n%%I;;DIt{rA	"9b	1	1BY"""!.!44AMM!R6"*Y.//1455  	?    rp   c                   t          |          }t          |d          r| 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          \  }}t	          ||          }t          |d           |                    ||           | t          v r|j        D ]
}|dk    sJ d S |j        dk    sJ d S d S )Nr&  )rf  rf  r  )r  rf  rf  )       @r*  r*  )r*  rj        @r  gɿg?g?g      g333333?r)  r  r  r   r   r  rB   )r   r   rN   r"   r  r\   r  r'  )r   r  rj   ru  r  iter_s         rn   r   r     s9    n%%Iy*%% *&&& ///???OOOTA+SzC;dDBB "III.  EAr *.!<<AA&&&a &&&"* " "zzzzz" " $))))/* *. *)rp   c                    t          |          }|                    d          }|                    d          t          fd|                                D                       sJ d S )NFdeepTc              3  D   K   | ]}|                                 v V  d S r;  )r  )r<  itemdeep_paramss     rn   r>  z.check_get_params_invariance.<locals>.<genexpr>  s4      NNtt{((***NNNNNNrp   )r   r   r&  r  )r   r  rd  shallow_paramsr2  s       @rn   r	  r	    ss     	nA\\u\--N,,D,))KNNNN~7K7K7M7MNNNNNNNNNNrp   c           
        t          |          }|                    d          }d} |j        di | |                    d          }t          |                                          t          |                                          k    s
J |            |                                D ]\  }}||         |u s
J |            t          j         t          j        d g}t          |          }	|                                D ]}
||
         }|D ]}||	|
<   	  |j        di |	 |                    d          }t          |	                                          t          |                                          k    s
J |            |                                D ]\  }}|	|         |u s
J |            # t          t          f$ r}|j        j        }t          j        d                    ||
|                      d                    |          }|}|                    d          }	 t          |                                          t          |                                          k    sJ |                                D ]\  }}||         |u sJ n$# t           $ r t          j        |           Y nw xY wY d }~d }~ww xY w||	|
<   d S )NFr.  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 {}rA  )r   r   r  r  r   r  r{  r  r   rG  r]  ri   re   ru   rv   r  r  )r   r  rj   orig_paramsrI  curr_paramskvtest_valuestest_paramsr  default_valuer  rd  e_typechange_warning_msgparams_before_exceptions                    rn   r
  r
    si    n%%I&&E&22K
JCI'';'''&&E&22K{!!""c+*:*:*<*<&=&====s===!!## ( (11~"""C"""" F7BFD)K;''K!&&(( #0 #0
#J/   	4  	4E&+K
#4$	$33{3334 (222>>;++--..#k6F6F6H6H2I2IIII3III'--// 4 4DAq&q>Q.......47 z* 6 6 6-,,2F6:t,L,L   PVV  #
 +6''222>>66;;==>>##((**C C     !, 1 1 3 3 ? ?16q9Q>>>>>?% 6 6 6M"4555556-6: #0JG#0 #0s>   F::K
A"K.A,JKJ<	9K;J<	<KK
c                &   t                      \  }}t          ||          }t          |          }d}d}t          |          j        sHt          t          ||          5  |                    ||           d d d            d S # 1 swxY w Y   d S d S )NzWhen a classifier is passed a continuous target, it should raise a ValueError with a message containing 'Unknown label type: ' or a message indicating that a continuous target is passed and the message should include the word 'continuous'zUnknown label type: |continuousr  )rw  r  r   rM   r   r[   r]  r  )r   r  ru  rv  rd  r  rI  s          rn   r   r   6  s       DAq!.!44AnA	  ,CA;;$ Jc7;;; 	 	EE!QKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 s    BBBc           	     .   ddg}t          ddd|dd          \  }}t          ||d	d
          \  }}}}t          |          }	t          |	d          r<t          |	d          r-|	                    ||           |	                    |          d d df                             d          }
|	                    |                              d          t          |
          t                    c}	 t          |           d S # t          $ rz t          j        fdt          j                  D                       }t          j        |          }t          |t          j        t#          |                               Y d S w xY wd S d S )N)r   r   )r  r  r$  r   r  r  T)rm  rr  rn  r  r  rC   皙?r  r  r  rB   ri  )decimalsc                L    g | ] }|k                                              !S rA  )r  )r<  groupb
rank_probas     rn   rk  z4check_decision_proba_consistency.<locals>.<listcomp>q  s/    RRR5:&',,..RRRrp   )r"   r3   r   r   r  r  r  r  r   rV   r  r{  r  r	  rK  rW   r*  r/  )r   r  r  ru  rv  r  r5  rr  r  rj   a
rank_scoregrouped_y_score
sorted_idxrE  rF  s                 @@rn   r   r   J  s   
 vG  DAq (8	1!( ( ($GVWf n%%Iy-.. G79o3V3V Ggw''' ##F++AAAqD1777DD''//55r5BB!)!hqkk
J	G%j*===== 
	G 
	G 
	G !hRRRRRBIj<Q<QRRR O O44Jz29S__+E+EFFFFFF
	GG G G Gs   :D B FFc                \   d}t          |d          \  }}t          |d          }|j        \  }}t          |          }t	          |           |                    |          }|j        |fk    sJ |j        j        dk    sJ t          t          j
        |          t          j        ddg                     t          |d	          r8|                    |                              |          }t          ||           t          |d
          rd}	t          |	          |z  }
|                    |
           |                    |          }t          j        |dk              }||	k    r:t          |d          r,|                    |          }t'          ||	|           d S d S d S d S )Nr?  r   r  r   r  r  r&  rB   r   r   r)  r]  r  )r"   rC   r  r   r\   r   r  r  rW   r{  r	  r  r   r  r   r  r  rI  r  rZ  )r   r  rm  ru  rc  rn  rj   r  y_pred_2rV  r   rU  r  s                rn   r   r   w  s    I	:::DAq"""AGIzn%%IY""1%%F<I<''''<####ry(("(B7*;*;<<<
 y)$$ -==##++A..68,,,y/** P /009<=999&&q))vfk**
 ,,,*2
 2
, !22155H$\3DhOOOOO#P P -,,,rp   c                
   t          j        ddgddgg          }t          j        ddg          }t          |          }t          t                    5  |                    ||           d d d            d S # 1 swxY w Y   d S )Nr  rB   r   )r{  r  r   r[   r]  r  r  s        rn   r  r    s     	4)dAY'((A
!QAn%%I	
		  a                 s   A88A<?A<c           
     2   g d}t           j                            d          }t          |          t	                     d                                                                v r                    d           d}|                    d|df          }t          |          }t          |          r|                    |	          }n|                    dd|
          }t          |          }t          t          d|                              |                    \  }}t!          |||          \  }	}
t!          ||||          \  }                    |	|
           fd|D             }t	                                         |	|
           |D ]}t%          |          r t'          |                    }t%          |d          rFt          j        |j        t           j                  r"dt          j        |j                  j        z  }n&dt          j        t           j                  j        z  }t5          ||         |t7          |d          t7          |d          d                    |                     d S )Nr_  r   
warm_startFrO  r$  r   locr  r  r[  rA  r  c                d    i | ],}t          |          | t          |                    -S rA  )r   rg   )r<  r  r5  rj   s     rn   r  z(check_fit_idempotent.<locals>.<dictcomp>  sP       9f%%*	6**622  rp   r  r  r  z&Idempotency check failed for method {})r  rtolr  )r{  r  r  r   r\   r   r   r  r  r  r    r  r  nextr2   r>  r4   r  r   rg   
issubdtyper  floatingfinfoepsr  rU   maxr  )r   r  r  r  rm  ru  rv  traintestr  rr  r  r  r  
new_resulttolr5  rj   s                   @@rn   r  r    s    SRRM
)


"
"Cn%%IYy++--224444...I

s)Q
00A!)Q//AN## 7JJIJ&&KKAAIK66!)Q//A|cDDDJJ1MMNNKE4"9aE::GW Aq$>>NFF MM'7###    #  F YMM'7###  9f%% 	3F33F;;Jz7++ 3 "+1 1 3 "(:#34488"(2:..22(vd^^d^^@GGOO    rp   c                   t           j                            d          }t          |          }t	          |           d|                                v r|                    d           d}|                    d|df          }t          ||          }t          |          r|                    |          }n|
                    d	d|
          }t          ||          }t          |          j        r<	 t          |           t          |j        j         d          # t$          $ r Y nw xY w|                    ||           	 t          |           d S # t$          $ r}t%          d          |d }~ww xY w)Nrl  rO  FrP  r$  r   rQ  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   r  r  r  r    r  r  rM   r   r_   r  ri   re   r(   r  )r   r  r  rj   rm  ru  rv  rd  s           rn   r  r    s    )


#
#Cn%%IYy++----...I

s)Q
00A!)Q//AN## 7JJIJ&&KKAAIK66!)Q//A	' 		I&&& &/       	 	 	D	MM!Q	"""""   T
 
	s*   8+D# #
D0/D0
E 
E:%E55E:c                n   t           j                            d          }t          |          }t	          |           d|                                v r|                    d           d}|                    d|df          }t          ||          }t          |          r|                    |          }n|
                    dd|	          }t          ||          }t          |d
          rJ |                    ||           t          |d
          sJ |j        |j        d         k    sJ d S )Nr   rO  FrP  r$  r   rQ  r  r[  n_features_in_rB   )r{  r  r  r   r\   r   r  r  r  r    r  r  r   r  ra  r  )r   r  r  rj   rm  ru  rv  s          rn   r  r    s<    )


"
"Cn%%IYy++----...I

s)Q
00A!)Q//AN## 7JJIJ&&KKAAIK66!)Q//Ay"233333MM!Q9./////#qwqz111111rp   c                t   t           j                            d          }t          |          }t	          |           d}|                    d|df          }t          ||          }d}	 |                    |d            d S # t          $ r(t          fd|D                       sY d d S d ww xY w)Nr   r$  r   rQ  )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  :   K   | ]}|t                    v V  d S r;  r  )r<  rI  ves     rn   r>  z(check_requires_y_none.<locals>.<genexpr>?  s-      ??c3#b''>??????rp   )
r{  r  r  r   r\   r  r  r  r]  rF  )r   r  r  rj   rm  ru  expected_err_msgsrd  s          @rn   r  r  )  s     )


"
"Cn%%IYI

s)Q
00A!)Q//Aa   ????->????? 	H	 	 	 	 	 	s   -B 
B7B22B7c           	        t          |          }|j        j        p|j        j        }|r|j        rd S t
          j                            d          }t          |          }t          |           d|
                                v r|                    d           d}|                    |df          }t          ||          }t          |          r|                    |          }n|                    dd|	          }t!          ||          }d
                    |           }	|                    ||           t'          |d          s
J |	            |j        |j        d         k    s
J |	            g d}
|d d dgf         }d}	t-          j        |	          }	d|j        d          d}|
D ]}t'          ||          st1          ||          }|dk    rt3          ||          }t5          t6          ||	                    | |                    5   ||           d d d            n# 1 swxY w Y   t'          |d          sd S t          |          }t9          |          r+|                    ||t          j        |                     n|                    ||           |j        |j        d         k    sJ t5          t6          |          5  |                    ||           d d d            d S # 1 swxY w Y   d S )Nr   rO  FrP  ri  r  r  r   r[  z`{name}.fit()` does not set the `n_features_in_` attribute. You might want to use `sklearn.utils.validation.validate_data` instead of `check_array` in `{name}.fit()` which takes care of setting the attribute.r  ra  rB   )r   r   r  r  r  a          `{name}.{method}()` does not check for consistency between input number
        of features with {name}.fit(), via the `n_features_in_` attribute.
        You might want to use `sklearn.utils.validation.validate_data` instead
        of `check_array` in `{name}.fit()` and {name}.{method}()`. This can be done
        like the following:
        from sklearn.utils.validation import validate_data
        ...
        class MyEstimator(BaseEstimator):
            ...
            def fit(self, X, y):
                X, y = validate_data(self, X, y, ...)
                ...
                return self
            ...
            def {method}(self, X):
                X = validate_data(self, X, ..., reset=False)
                ...
            return X
    z'X has 1 features, but \w+ is expecting z features as inputr  r  )r   r  r  r  r  rW  )rM   r   r   r   r   r{  r  r  r   r\   r   r  r  r  r    r  r  r  r  r   ra  r  textwrapdedentrg   r   r[   r]  r   r  r	  )r   r  rl   is_supported_X_typesr  rj   rm  ru  rv  r  r  X_badrI  r  callable_methods                  rn   r   r   C  s    N##D?6U$/:U 4#5 
)


"
"Cn%%IYy++----...I

A
''A!)Q//AI 7JJIJ&&KKAAIK66!)Q//A	 VV&&	  MM!Q9.//88888#qwqz1117111  M aaa!fIEG( og&&G
SQWQZ
S
S
SC # #y&)) 	!)V44W%o;;;Oc7>>tF>+S+S
 
 
 	# 	# OE"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 9m,, n%%IY $aBIaLL9999a####qwqz1111	
#	&	&	& ( (eQ'''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s$   H22H6	9H6	LLLc                
   t          |d          sJ d|  d            d}t          |          }t          |j        t          t          d          f          s
J |            t          |j        t                    s
J |            t          |j        t          t          d          f          s
J |            t          |j
        t          t          d          f          s
J |            t          |j        t          t          d          f          s
J |            t          |j        t                    s
J |            t          |j        t"                    s
J |            t          |j        t"                    s
J |            t          |j        t"                    s
J |            t          |j        t"                    s
J |            t          |j        t"                    s
J |            t          |j        j        t"                    s
J |            t          |j        j        t"                    s
J |            t          |j        j        t"                    s
J |            t          |j        j        t"                    s
J |            t          |j        j        t"                    s
J |            t          |j        j        t"                    s
J |            t          |j        j        t"                    s
J |            t          |j        j        t"                    s
J |            t          |j        j        t"                    s
J |            t          |j        j        t"                    s
J |            t          |j        j         t"                    s
J |            t          |j        j!        t"                    s
J |            t          |j        j"        t"                    s
J |            t          |j        j#        t"                    s
J |            t          |j        j$        t"                    s
J |            t          |j        j        t"                    s
J |            |j        {t          |j        j%        t"                    s
J |            t          |j        j&        t"                    s
J |            t          |j        j'        t"                    s
J |            |j
        )t          |j
        j%        t"                    s
J |            |j        )t          |j        j(        tR                    sJ |            dS dS )z$Check that estimator tags are valid.__sklearn_tags__rd   z does not have `__sklearn_tags__` method. This method is implemented in BaseEstimator and returns a sklearn.utils.Tags instance.ztTag values need to be of a certain type. Please refer to the documentation of `sklearn.utils.Tags` for more details.N)*r   rM   rt   rm   r  r4  r   rK   r   rH   r   rJ   r   rL   r   rI   r   r   r   r  r   r  r  one_d_labelstwo_d_labelsr  r   r   r   r   r   r   rY  r  r  r   three_d_arrayr  r   r   r   r=  )r   rj   r  rl   s       rn   rz   rz     s   9011  	ST 	S 	S 	S  
	V  IDd)Cd+<==FFwFFFd&
33<<W<<<d*^T$ZZ,HIIRR7RRRd)M4::+FGGPPPPPd+otDzz-JKKTTWTTTdoy11::7:::d,d33<<W<<<d($//88888d,d33<<W<<<d'..77777dot,,55g555d&/66?????d&3T::CCGCCCd&3T::CCGCCCd&4d;;DDWDDDd&3T::CCGCCCd&4d;;DDWDDDdo.55>>w>>>do/66?????do,d33<<W<<<do1488AA'AAAdo,d33<<W<<<do*D11::7:::do1488AA'AAAdo1488AA'AAAdo3T::CCGCCCdo3T::CCGCCC'$.94@@II'III$.:DAAJJ7JJJ$.:DAAJJ7JJJ&$-8$??HHHHH($/?FFOOOOO )(OOrp   c                    d}t          |                                          D ]H}dt          |          v sdt          |          v r$dt          |          vrt          d|  d          Id S )Nz{tags_func}() was removed in 1.6. Please use __sklearn_tags__ instead.
You can implement both __sklearn_tags__() and {tags_func}() to support multiple
scikit-learn versions.

_more_tags	_get_tagsrm  rd   a   has defined either `_more_tags` or `_get_tags`, but not `__sklearn_tags__`. If you're customizing tags, and need to support multiple scikit-learn versions, you can implement both `__sklearn_tags__` and `_more_tags` or `_get_tags`. This change was introduced in scikit-learn=1.6)r4  r  r  rG  )r   r  helpklasss       rn   ry   ry     s    D
 n%%))++   T%[[((K4;;,F,F"$u++552T 2 2 2   rp   c           	     	   	 dd l }n# t          $ r t          d          w xY wt          |          }|j        j        p|j        j        }|r|j        rd S t          j	        
                    d          }t          |          }t          |           |                    d          }t          ||          }|j        \  }}	t          j        d t#          |	          D                       }
|                    ||
d          }t'          |          r|                    |          }n|                    dd|	          }t+          ||          }t-          j                    5  t-          j        d
dt2          d           |                    ||           d d d            n# 1 swxY w Y   t7          |d          st9          d          t;          |j        t          j                  sJ |j        j         tB          k    sJ tE          |j        |
           |j#        }|$                    d          r5d|v s1|%                    d          sd|j&        vrt9          d|  d          g }dD ]Q}t7          ||          stO          ||          }|dk    rtQ          ||          }|)                    ||f           R|D ]X\  }}t-          j                    5  t-          j        d
dt2          d            ||           d d d            n# 1 swxY w Y   Y|
d d d         dfd t#          |	          D             df|
d d         dtU          |
dd                     dfg}d |+                                ,                                D             }t[          d  |.                                D                       }|D ]2\  }}|                    ||d          }t_          j0        d!|           }|D ]B\  } }tc          t8          ||  d"#          5   ||           d d d            n# 1 swxY w Y   Ct7          |d$          r|rt          |          }te          |          r-t          j3        |          }|4                    |||%           n|4                    ||           tc          t8          |&          5  |4                    ||           d d d            n# 1 swxY w Y   4d S )'Nr   Hpandas is not installed: not checking column name consistency for pandas)   rF  r  c                    g | ]}d | S )col_rA  r<  r  s     rn   rk  z<check_dataframe_column_names_consistency.<locals>.<listcomp>	  s    <<<QjQjj<<<rp   Fcolumnsr  r   r[  errorz#X does not have valid feature namessklearn)messagers   modulefeature_names_in_zTEstimator does not have a feature_names_in_ attribute after fitting with a dataframer  r  r  rd   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                    g | ]}d | S )another_prefix_rA  r{  s     rn   rk  z<check_dataframe_column_names_consistency.<locals>.<listcomp>O  s!    >>>q"q"">>>rp   zHFeature names unseen at fit time:
- another_prefix_0
- another_prefix_1
r  z3Feature names seen at fit time, yet now missing:
- r  c                "    i | ]\  }}d |v 	||S )early_stoppingrA  r  s      rn   r  z<check_dataframe_column_names_consistency.<locals>.<dictcomp>Z  s3       Cs"" 	U"""rp   c              3     K   | ]}|d u V  	dS )TNrA  )r<  r  s     rn   r>  z;check_dataframe_column_names_consistency.<locals>.<genexpr>_  s&       L L5$ L L L L L Lrp   zBThe feature names should match those that were passed during fit.
z did not raiser  r  r  rW  )5r  r"  rQ   rM   r   r   r   r   r{  r  r  r   r\   r  r  r  r  r  r   r    r  r  ru   r+  filterwarningsrw   r  r   r]  rt   r  r  r  rX  rW   r  r  r  r  rg   r   r`  rG  r   r  rF  r  r  escaper[   r   r	  r  )r   r  r#  rl   ri  r  rj   X_origrm  rn  namesru  rv  r  r  r  rk  rc  invalid_namesr  early_stopping_enabledinvalid_nameadditional_messagerj  expected_msgr  s                             rn   (check_dataframe_column_names_consistencyr    s   
 
 
 
V
 
 	


 N##D?6U$/:U 4#5 
)


"
"Cn%%IYZZXZ&&F&y&99F"LIzH<<%
*;*;<<<==E
VU77AI 7JJIJ&&KKAAIK66!)Q//A 
	 	"	"  9 		
 	
 	
 	
 	a               9122 
7
 
 	
 i12:>>>>>&,6666y2E::: !+Kz**
K'';+?+?
+K+K' )?@@QQQQ
 
 	
 M 8 8 y&)) 	!)V44W%o;;;Ofo67777"  	6$&& 	 	#=$ 	    F1III	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 
tttTU>>E*,=,=>>>&	
 "1"IU3uQRRy>>UUU	
M #..006688  F
 ! L LFMMOO L L LLL,9 , ,((Q5AAy$!$ $
 
 * 	 	LD&,48O8O8O     u               y-00 	4J 	.))	## 	(illG!!!Q!8888!!!Q'''Jl333 	, 	,!!%+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,3, ,sP    !'4F''F+.F+)LL	L	P77P;>P;S00S4	7S4	c                x   t          |          }|j        j        r|j        rd S t	          dg dg dgddd          \  }}t                                          |          }t          |          }t          ||          }|j	        d         }t          |           |}| t          v rMt          j        t          j        |          t          j        |          f         }|d d ddfxx         dz  cc<   |                    ||	          }d
 t          |          D             }	t!          t"          d          5  |                    |	d d d                    d d d            n# 1 swxY w Y   |                    |	          }
|
J t'          |
t          j                  sJ |
j        t,          k    sJ t/          d |
D                       sJ t'          |t0                    r|d         j	        d         }n|j	        d         }t3          |
          |k    sJ d| dt3          |
                       d S )Nr)  r  r  r   r   r  r  rB   r  c                    g | ]}d | S )featurerA  r{  s     rn   rk  z;check_transformer_get_feature_names_out.<locals>.<listcomp>  s    ???mmm???rp   z'input_features should have length equalrW  c              3  @   K   | ]}t          |t                    V  d S r;  )rt   r  )r<  r   s     rn   r>  z:check_transformer_get_feature_names_out.<locals>.<genexpr>  s,      CCz$$$CCCCCCrp   	Expected  feature names, got )rM   r   r   r   r"   r6   rt  r   r  r  r\   rN   r{  r  r|  r  r[   r]  r  rt   r  r  rX  r&  r~  r/  )r   r  rl   ru  rv  r   rn  r  X_transforminput_featuresfeature_names_outn_features_outs               rn   'check_transformer_get_feature_names_outr  ~  s   $%%D?& $*< III&  DAq 	&&q))A())K!+q11AJ[!!!	
B"""U2:a=="*Q--/0
33Q36


a


++A+44K??U:->->???N 

"K	L	L	L ? ?)).1*=>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ? $99.II((('44444"f,,,,CC1BCCCCCCCC+u%% .$Q-a0$*1- 	.000O>OOs;L7M7MOO 	10000s   <E''E+.E+c                   	 dd l }n# t          $ r t          d          w xY wt          |          }|j        j        r|j        rd S t          dg dg dgddd          \  }}t                      	                    |          }t          |          }t          ||          }|j        d	         }t          |           |}| t          v rMt          j        t          j        |          t          j        |          f         }|d d dd	fxx         dz  cc<   d
 t%          |          D             }	|                    ||	d          }
|	                    |
|          }d t%          |          D             }t)          t*          d          5  |                    |           d d d            n# 1 swxY w Y   |                                }|                    |	          }t/          ||           t1          |t2                    r|d         j        d	         }n|j        d	         }t5          |          |k    sJ d| dt5          |                       d S )Nr   rw  r)  r  r  r   r  r  rB   c                    g | ]}d | S r  rA  r{  s     rn   rk  zBcheck_transformer_get_feature_names_out_pandas.<locals>.<listcomp>      ===a	a		===rp   Fr|  r  c                    g | ]}d | S )badrA  r{  s     rn   rk  zBcheck_transformer_get_feature_names_out_pandas.<locals>.<listcomp>  s    BBB1Y1YYBBBrp   z0input_features is not equal to feature_names_in_rW  r  r  )r  r"  rQ   rM   r   r   r   r"   r6   rt  r   r  r  r\   rN   r{  r  r|  r  r   r[   r]  r  rW   rt   r~  r/  )r   r  r#  rl   ru  rv  r   rn  r  feature_names_indfr  invalid_feature_namesfeature_names_out_defaultfeature_names_in_explicit_namesr  s                   rn   .check_transformer_get_feature_names_out_pandasr    s   
 
 
 
V
 
 	


 $%%D?& $*< III&  DAq 	&&q))A())K!+q11AJ[!!!	
B"""U2:a=="*Q--/0
33Q36


a


==5+<+<===	a!1	>	>B++B"+55K CBj0A0ABBB	
"T	U	U	U A A))*?@@@A A A A A A A A A A A A A A A !, A A C C&1&G&G' '# 02QRRR+u%% .$Q-a0$*1- 	%&&.888W>WWs;T7U7UWW 	98888s    !F22F69F6c           	     Z   t           j                            d          }|                    d          }|                    ddd          }t          ||          }t          |          }|                    d                                          }|rr|j	                                        }t          |          t          |          z
  }t          |          t          |          z
  }	d|  d	| d
|	 }
||k    s
J |
             t          ddi                       }g d}|D ]}|j	        |         }|dk    rt          d |D                       r/t          d |D                       rt          d| d|  d          d| d|  d}|  d| d}
t          |          } |j        di ||i |D ]}t!          ||          s|  d| d}
t#          t$          ||
          5  |j        j        s|j        j        r t-          ||          |           n t-          ||          ||           d d d            n# 1 swxY w Y   d |D             }|D ]}	 t/          |          }n# t0          $ r Y w xY w |j        di ||i |D ]}t!          ||          s|  d| d}
t#          t$          ||
          5  |j        j        s|j        j        r t-          ||          |           n t-          ||          ||           d d d            n# 1 swxY w Y   ̐d S )Nr   r  r  r   rk  Fr.  z>Mismatch between _parameter_constraints and the parameters of z%.
Consider the unexpected parameters z% and expected but missing parameters BadTyperA  )r  r  rt  r   r   c              3  `   K   | ])}t          |t                    o|j        t          k    V  *d S r;  )rt   rE   r4  r	   r<  rl  s     rn   r>  z)check_param_validation.<locals>.<genexpr>  sL       
 
 z8,,LH1L
 
 
 
 
 
rp   c              3  `   K   | ])}t          |t                    o|j        t          k    V  *d S r;  )rt   rE   r4  r
   r  s     rn   r>  z)check_param_validation.<locals>.<genexpr>  sL       
 
 z8,,HD1H
 
 
 
 
 
rp   zThe constraint for parameter r  zc can't have a mix of intervals of Integral and Real types. Use the type RealNotInt instead of Real.zThe 'z' parameter of z must be .* Got .* instead.z@ does not raise an informative error message when the parameter z% does not have a valid type or value.zc does not have a valid type. If any Python type is valid, the constraint should be 'no_validation'.r  c                ,    g | ]}t          |          S rA  )rA   r  s     rn   rk  z*check_param_validation.<locals>.<listcomp>8  s     QQQzz22QQQrp   a   does not have a valid value.
Constraints should be disjoint. For instance [StrOptions({'a_string'}), str] is not a acceptable set of constraint because generating an invalid string for the first constraint will always produce a valid string for the second constraint.)r{  r  r  r  r  r  rM   r   r   rc  r  r4  rF  r]  r   r  r   r[   r?   r   rn  ro  rg   r@   r
  )r   r  r  ru  rv  rl   estimator_paramsvalidation_paramsunexpected_paramsmissing_paramsr  param_with_bad_typefit_methodsr  constraintsr  rj   r  rl  	bad_values                       rn   check_param_validationr    s0    )


"
"C!!AAqr""A!.!44AN##D%00e0<<AACC  	>*AFFHH 122S9I5J5JJ-..5F1G1GG4T 4 44E4 4#14 4 	
 !$4444g444 2$y"b1133HHHK& S9 S9
$;JG/))  
 
)
 
 
 
 
 	  
 
)
 
 
 
 
	 $
 $ $ $ $ $   VUUDUUU K K#K K K 	
 .))	 		AA
,?@AAA! 	5 	5F9f--   D DD D D  -UGLLL 5 5#0 5D4D4Q 5.GIv..q1111.GIv..q!4445 5 5 5 5 5 5 5 5 5 5 5 5 5 5 RQ[QQQ% 	9 	9J6zBB		&    !I ;;J	#:;;;% 9 9y&11   " "!+" " "  1PPP 9 9'4 98H8U 92	622155552	6221a8889 9 9 9 9 9 9 9 9 9 9 9 9 9 99	9oS9 S9s8   *AII
I I00
I=<I=AL	L #L c                    t          |          }|j        j        r|j        rd S t          j                            d          }t          |          }|                    d          t          |          |
                    ddd          t          |          t          |            fd}fd}||d}|                                D ]\   }t          |          }t          |           s% ||          }	 t          v r|	d         }	|                    d	
            ||          }
 t          v r|
d         }
t#          |	|
           d S )Nr   r  r  r   rk  c                    t           v r*|                                                             S |                                                             S r;  )rN   r  r   )r=  ru  r   rv  s    rn   fit_then_transformz6check_set_output_transform.<locals>.fit_then_transformi  sQ    &&&771a==**1a000wwq!}}&&q)))rp   c                0    |                                S r;  )rt  )r=  ru  rv  s    rn   rt  z1check_set_output_transform.<locals>.fit_transformn  s      A&&&rp   )r   rt  r  r  )rM   r   r   r   r{  r  r  r   r  r  r  r  r\   r  r   rN   r  rU   )r   r  rl   r  r   r  rt  transform_methodstransform_methodX_trans_no_settingX_trans_defaultru  rv  s   `          @@rn   check_set_output_transformr  Y  s    $%%D?& $*< 
)


"
"C())K!!A!"2A66AAqr""A!"2A66A[!!!* * * * * * *
' ' ' ' ' ' (&  #4"9"9";"; J JK(({D)) 	--k:: &&&!3A!6333**;77&&&-a0O 	%%7IIII#J Jrp   c                *    i }d||fd||fd||fd||fg}t           fddD                       rp|D ]m\  }}}	                     ||           |t          v r                     |	|          \  }
}n                     |	          }
|
                                 f||<   nd|fd|fg}t           d	          rZ|D ]W\  }}|t          v r                     ||          \  }
}n                     ||          }
|
                                 f||<   X|S )
zGenerate output to test `set_output` for different configuration:

    - calling either `fit.transform` or `fit_transform`;
    - passing either a dataframe or a numpy array to fit;
    - passing either a dataframe or a numpy array to transform.
    zfit.transform/df/dfzfit.transform/df/arrayzfit.transform/array/dfzfit.transform/array/arrayc              3  8   K   | ]}t          |          V  d S r;  )r   )r<  methr   s     rn   r>  z-_output_from_fit_transform.<locals>.<genexpr>  s-      
G
G$7;%%
G
G
G
G
G
Grp   )r  r   zfit_transform/dfzfit_transform/arrayrt  )r&  r  rN   r   r  r   rt  )r   r   ru  r  rv  outputscasescasedata_fitdata_transformr  rc  r}  s   `            rn   _output_from_fit_transformr    s    G 
B'	!2q)	!1b)	$a+	E 
G
G
G
G2F
G
G
GGG K
 	
	K 
	K 
OOHa(((***(22>1EE
%//??$k&G&G&I&IJGDMM 
R 	"E {O,, K 	K 	KJD$***(66tQ??
%33D!<<$k&G&G&I&IJGDMMNrp   c                    |\  }}	|\  }
} ||
          sJ |                     d          r|nd} ||||          }	  ||
|           dS # t          $ r}t          |  d| d|           |d}~ww xY w)a  Check if the generated DataFrame by the transformer is valid.

    The DataFrame implementation is specified through the parameters of this function.

    Parameters
    ----------
    name : str
        The name of the transformer.
    case : str
        A single case from the cases generated by `_output_from_fit_transform`.
    index : index or None
        The index of the DataFrame. `None` if the library does not implement a DataFrame
        with an index.
    outputs_default : tuple
        A tuple containing the output data and feature names for the default output.
    outputs_dataframe_lib : tuple
        A tuple containing the output data and feature names for the pandas case.
    is_supported_dataframe : callable
        A callable that takes a DataFrame instance as input and return whether or
        E.g. `lambda X: isintance(X, pd.DataFrame)`.
    create_dataframe : callable
        A callable taking as parameters `data`, `columns`, and `index` and returns
        a callable. Be aware that `index` can be ignored. For example, polars dataframes
        would ignore the idnex.
    assert_frame_equal : callable
        A callable taking 2 dataframes to compare if they are equal.
    r  Nr}  r  z, does not generate a valid dataframe in the z] case. The generated dataframe is not equal to the expected dataframe. The error message is: )r  r  )r   r  r  outputs_defaultoutputs_dataframe_libis_supported_dataframecreate_dataframeassert_frame_equalr  feature_names_defaultdf_transfeature_names_dataframe_libexpected_indexexpected_dataframerd  s                  rn   _check_generated_dataframer    s    J &5"G",A)H)!!(+++++ #mmD11;UUtN))4N  8%788888    4 4 4 4014 4
 
 		s    A 
A5A00A5c               v   t          |          }|j        j        r|j        rdS t          j                            d          }t          |          }	|                    d          }
t          ||
          }
|
                    ddd          }t          ||          }t          |	           d t          |
j        d                   D             }d	 t          |
j        d                   D             } ||
||
          }t          |	                              d          }t!          || |
||          }|dk    r2t          |	                              |          }t#                      }nt          |	          }t%          |          }	 |5  t!          || |
||          }ddd           n# 1 swxY w Y   nP# t&          $ rC}|                                }t+          |          }| d|v sd|v s
J |            Y d}~dS d}~ww xY w|D ]$}t-          | ||||         ||         |||           %dS )a  Check that a transformer can output a DataFrame when requested.

    The DataFrame implementation is specified through the parameters of this function.

    Parameters
    ----------
    name : str
        The name of the transformer.
    transformer_orig : estimator
        The original transformer instance.
    dataframe_lib : str
        The name of the library implementing the DataFrame.
    is_supported_dataframe : callable
        A callable that takes a DataFrame instance as input and returns whether or
        not it is supported by the dataframe library.
        E.g. `lambda X: isintance(X, pd.DataFrame)`.
    create_dataframe : callable
        A callable taking as parameters `data`, `columns`, and `index` and returns
        a callable. Be aware that `index` can be ignored. For example, polars dataframes
        will ignore the index.
    assert_frame_equal : callable
        A callable taking 2 dataframes to compare if they are equal.
    context : {"local", "global"}
        Whether to use a local context by setting `set_output(...)` on the transformer
        or a global context by using the `with config_context(...)`
    Nr   r  r  r   rk  c                    g | ]}d | S r  rA  r{  s     rn   rk  z9_check_set_output_transform_dataframe.<locals>.<listcomp>%  r  rp   rB   c                    g | ]}d | S )r  rA  r{  s     rn   rk  z9_check_set_output_transform_dataframe.<locals>.<listcomp>&  s    444Q[Q[[444rp   r  r  r  local)transform_outputz% output does not support sparse data.z.The transformer outputs a scipy sparse matrix.)rM   r   r   r   r{  r  r  r   r  r  r  r  r\   r  r  r  r  r   r   r]  
capitalizer  r  )r   r  dataframe_libr  r  r  contextrl   r  r   ru  rv  r  r  r  transformer_defaultr  transformer_dfcontext_to_use
outputs_dfrd  capitalized_liberror_messager  s                           rn   %_check_set_output_transform_dataframer    s   J $%%D?& $*< 
)


"
"C())K!!A!"2A66AAqr""A!"2A66A[!!!==5+<+<===44%
"3"3444E		!%5U	C	C	CB,,77)7LL01DdArSTUUO'{++666OO${++'GGG 	T 	T3ND!RQRSSJ	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T   '2244AEEEVV?=PPP QPP   

 

"D!t"		
 		
 		
 		


 

s<   G F6*G 6F::G =F:>G 
H8H

Hc           	         	 dd l n# t          $ r t          d          w xY wt          | |dfdfdj        j        |           d S )Nr   z0pandas is not installed: not checking set outputr  c                .    t          | j                  S r;  rt   r   )ru  r#  s    rn   r{  z<_check_set_output_transform_pandas_context.<locals>.<lambda>W      Ar|)D)D rp   c                6                         | |d|          S )NF)r}  r  r  )r   )ru  r}  r  r#  s      rn   r{  z<_check_set_output_transform_pandas_context.<locals>.<lambda>X  s$    2<<wU% 4@ 4
 4
 rp   r  r  r  r  r  )r  r"  rQ   r  testingr  )r   r  r  r#  s      @rn   *_check_set_output_transform_pandas_contextr  M  s    K K K KIJJJK *DDDD
 
 
 
 :8
 
 
 
 
 
s    "c                (    t          | |d           d S Nr  r  r   r  s     rn   !check_set_output_transform_pandasr  `      .t5EwOOOOOrp   c                (    t          | |d           d S Nglobalr  r  s     rn   $check_global_output_transform_pandasr  d      .t5ExPPPPPrp   c           	         	 dd l ddlm} n# t          $ r t	          d          w xY wfd}t          | |dfd|||           d S )Nr   )r  z0polars is not installed: not checking set outputc                    t          |t          j                  r|                                }                    | |d          S )Nr  )schemaorient)rt   r{  r  r  r   )ru  r}  r  pls      rn   r  zD_check_set_output_transform_polars_context.<locals>.create_dataframeo  s>    grz** 	'nn&&G||Age|<<<rp   polarsc                .    t          | j                  S r;  r  )ru  r  s    rn   r{  z<_check_set_output_transform_polars_context.<locals>.<lambda>y  r  rp   r  )r  polars.testingr  r"  rQ   r  )r   r  r  r  r  r  s        @rn   *_check_set_output_transform_polars_contextr  h  s    K5555555 K K KIJJJK= = = = = *DDDD)-     s   
 (c                (    t          | |d           d S r  r  r  s     rn   !check_set_output_transform_polarsr    r  rp   c                (    t          | |d           d S r  r  r  s     rn   (check_global_set_output_transform_polarsr    r  rp   c                   t           j                            d          }t          |          }t	          |           d}t          |d|          \  }}t          ||          }| dv rt          j        |          }t          |d          rt           j	        |d<   t          |          r|                    |          }n|                    dd	|
          }t          ||          }|                                }|                    d           |                    ||           t          |d          r|                    |           |j        j        rJ t)          ||           dS )a  Check that estimators able to do inplace operations can work on read-only
    input data even if a copy is not explicitly requested by the user.

    Make sure that a copy is made and consequently that the input array and its
    writeability are not modified by the estimator.
    r   r$  r  )rm  rn  rr  )Lasso
ElasticNetMultiTaskElasticNetMultiTaskLassomissing_valuesrV  r  r   r[  F)writer   N)r{  r  r  r   r\   r"   r  r  r   r  r    r  r  r  r  setflagsr  r   flags	writeablerT   )	r   r  r  rj   rm  ru  rc  rv  X_copys	            rn   check_inplace_ensure_writeabler    sm    )


"
"Cn%%IYI	acJJJDAq!)Q//A OOOa   y*++ &$I 7JJIJ&&KKAAIK66!)Q//AVVXXF JJUJMM!Qy+&& Aw    Avrp   c                    t          |          }t          |          j        }dddt          j        ddg          dgi g g}|D ]%fd|D             } |d	i |} |j        d	i | &dS )
z3Check that init or set_param does not raise errors.r&  g      @
helloworldr  r+  rB   c                    i | ]}|S rA  rA  r  s     rn   r  zCcheck_do_not_raise_errors_in_init_or_set_params.<locals>.<dictcomp>  s    333Sc5333rp   NrA  )r4  r   r  r{  r  r  )r   r  r  r  smoke_test_valuesr  r=  r  s          @rn   r   r     s    ^$$Iy!!,FS,#s0D0Dqc2rR" % %3333F333
 i%%*%% 	$$$$$$% %rp   c                P   t          |          }t          |           t          ddddd          \  }}d                    |           }t	          j        |          }t          t          d|	          5  |                    ||           d
d
d
           d
S # 1 swxY w Y   d
S )zCheck that if the classifier has tags.classifier_tags.multi_class=False,
    then it should raise a ValueError when calling fit with a multiclass dataset.

    This test is not yielded if the tag is not False.
    r$  r  rB   r   )rm  r  ro  n_clusters_per_classrr  a          The estimator tag `tags.classifier_tags.multi_class` is False for {name}
        which means it does not support multiclass classification. However, it does
        not raise the right `ValueError` when calling fit with a multiclass dataset,
        including the error message 'Only binary classification is supported.' This
        can be achieved by the following pattern:

        y_type = type_of_target(y, input_name='y', raise_unknown=True)
        if y_type != 'binary':
            raise ValueError(
                'Only binary classification is supported. The type of the target '
                f'is {{y_type}}.'
        )
    r  z(Only binary classification is supported.r  N)	r   r\   r#   r  rg  rh  r[   r]  r  )r   r  rj   ru  rv  r  s         rn   r   r     s    n%%IY  DAq 	 	 	 	   og&&G	Dg
 
 
   	a                 s   7BB"B)r   r   )NNN)r  r  r  r  r;  )r  r  r.  r/  )r   r   r  r  r  r  )r   r   r  r8  )NF)
r   r   r  r  rN  rR  rO  rS  rP  r8  )Nr  F)Nr  )F)Fr  )T(  r  
__future__r   r  r  rg  ru   
contextlibr   r  r   	functoolsr   r   inspectr   numbersr	   r
   typingr   r   r  numpyr{  scipyr   scipy.statsr   sklearn.baser   r   r   r   r   r   r   r   r   r   r   rc   r   baser   r   r   r   r    datasetsr!   r"   r#   r$   r%   
exceptionsr&   r'   r(   r)   linear_model._baser*   metricsr+   r,   r-   metrics.pairwiser.   r/   r0   model_selectionr1   r2   r3   model_selection._validationr4   r  r5   preprocessingr6   r7   utilsr8   utils._array_apir9   r:   r;   r<   r>   r  utils._param_validationr?   r@   rA   rC   _missingrD   _param_validationrE   rF   rG   _tagsrH   rI   rJ   rK   rL   rM   _test_common.instance_generatorrN   rO   rP   r  rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   fixesr]   
validationr^   r_   r`   rs  ro   r   r   r   r   r   r   r   r   r  r  r-  r)  r7  rJ  r  rB  rf  rw  ry  r  r  r^  r   r   r  r   r  r   r   r   r   r   r   r   rL  r   r   r   rw   r   r   r  re  r   r  r  r  r  r  r  r  r   r   r   r   r  r   r   r}   r   r   r   r   r   r   r   r   r   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   r~   r|   r   r   r   r  rx   r{   r  r  r  r   r   r   r	  r
  r   r   r   r  r  r  r  r  r   rz   ry   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   rA  rp   rn   <module>r5     sS   W W # " " " " "  				   " " " " " "       $ $ $ $ $ $ $ $       " " " " " " " " $ $ $ $ $ $ $ $                                                                                            7 6 6 6 6 6 C C C C C C C C C C L L L L L L L L L L N N N N N N N N N N 5 5 5 5 5 5 $ $ $ $ $ $ 1 1 1 1 1 1 1 1 " " " " " "            6 5 5 5 5 5         
       # # # # # # D D D D D D D D D D                        
                            ( ' ' ' ' ' H H H H H H H H H H 	
 	
 	
- - -86- 6- 6-r,9 ,9 ,9^2 2 20' ' '>
6 
6 
62 2 2$
 
 
;% ;% ;% ;%|Q Q Q 59+/*" *" *" *" *"\ GK2 2 2 2 2F 48+/2 2 2 2 2 2p .2	^ ^ ^ ^ ^ ^B #+#',Jx(($/J01148t$  #(
 
 
 { 48&,/6 ${ { { { {
 
{|   W W W W W W W W*) ) )$' ' 'B -(((    )( L nI nI nI nIj    "5
 5
 5
p3; 3; 3;lO O OR R R
  , -(((+
 +
 )(+
\ =***/ / +*/: =***5 5 +*5 -(((!@ !@ )(!@H -(((CL CL )(CLLR R R	 	 	%P %P %PP =+6777' ' 87'T     (< < < -(((5 5 )(5p -(((1 1 )(1.< < <$ -(((!R !R )(!RH -((() ) )()X % % %P   <   $ -(((0 0 0 )(0" -(((B B )(B" -(((! ! )(!  -(((* * )(*X1 X1 X1v > > >@ % % %P   : 4 4 4,  D -(((" " )(". -(((-1 -1 )(-1`    2G 2G 2G 2Gj -(((, , )(,8 -(((:N :N )(:Nz -(((  )(2 -(((73 73 73 )(73v -(((- - )(- -(((X X )(X. -(((!
 !
 )(!
H :CGO GO GO GOT@ @ @,EP EP EP EPPL L L6 -(((&6 &6 )(&6R -(((* * )(*Z -(((Q
 Q
 )(Q
h -(((+ + )(+\ -(((* * )(* -(((	, 	, )(	, -(((, , )(,$ . . .: -(((7 7 )(7D 7 7 7t  M M MD -(((; ; )(;6 -(((*//, /, /, )(/,d 1 1 1  -((()/ )/ )()/X -(((  )(* -(((% % )(%P -(((
 
 )(
B -(((  )(@ -(((( ( )((D -(((Q Q )(Q0 -(((Q Q )(Q -(((+; +; )(+;\R R RO O O|K |K |K~  * 48 ) ) ) )X -(((1 1 )(1@ -(((  )(. -(((* * )(*< -(((O O )(O -(((50 50 )(50p -(((  )(& -((()G )G )()GX(P (P (PV  9 9 9x$ $ $N2 2 24  4 -(((_( _( )(_(D2P 2P 2Pj  ,J, J, J,Z-P -P -P`6X 6X 6Xro9 o9 o9d-J -J -J`* * *Z: : :zW
 W
 W
t  &P P PQ Q Q  0P P PQ Q Q -(((* * )(*Z% % % % % % % %rp   