
    Ug                    |   d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
 ddlmZmZ ddlmZmZ ddlZddlZddlmZ dd	lmZ d
dlmZ d
dlmZmZmZmZmZm Z  d
dl!m"Z"m#Z#m$Z$m%Z%m&Z& d
dl'm(Z(m)Z)m*Z* d
dl+m,Z,m-Z- d
dl.m/Z/m0Z0m1Z1m2Z2m3Z3 d
dl4m5Z5m6Z6m7Z7 d
dl8m9Z9m:Z:m;Z; d
dl<m=Z=m>Z> d
dl?m@Z@ d
dlAmBZB d
dlCmDZDmEZE d
dlFmGZG d
dlHmIZImJZJ d
dlKmLZLmMZMmNZNmOZO d
dlKmPZQ d
dlRmSZSmTZTmUZU ddlmVZV ddlWmXZX ddlYmZZZ dd l[m\Z\m]Z] dd!l^m_Z_m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZk dd"llmmZmmnZnmoZompZp dd#lqmrZrmsZsmtZt daug d$Zvd% Zwd& Zx eiey'          d(             Zzd) Z{d* Z|d+ Z}d, Z~d- Zd. Zd/ Zd0 Zd1 Zd2 Zd3 Zd4 Zdd6Zd7 Zd8 Z G d9 d:          Zd; Zd< Z	 	 	 dd>Z	 	 dd?Zd@ ZdA ZdB Z eiey'          dC             Z eiey'          dD             Z eiey'          dE             Z eiey'          dF             Z eiey'          ddH            ZdI Z eieyef'          dJ             ZdK ZeidL             ZdM Z eiey'          dN             Z eiey'          dO             ZdP Z eiey'          dQ             Z eiey'          dR             ZeidS             ZeidT             ZeidU             Z eiey'          ddV            Z eiey'          dW             Z eiey'          dX             Z eiey'          dY             ZdZ Zeid[             Zeid\             Zeid]             Zd^ Z eiey'          d_             Z eiey'          d`             Zeida             Zeiddb            Z eiey'          dc             Z eiey'          dd             Z eiey'          de             Z eiey'          ddf            Z eiey'          dg             Z eiey'          dh             Z eiey'          di             Zei	 ddj            Zdk ZddmZdn Z eiey'          do             Z eiey'          dp             Z eiey'          dq             Z eiey'          dr             Z eiey'          ds             Z eiey'          ddt            Zeidu             Z eiey'          dv             Zeidw             Zdx Zdy Z eiey'          dz             Z eiey'          d5ej        fd{            Zeid|             Z eiey'          d}             Z eiey'          d~             Z eiey'          d             Z eiey'          d             Z eiey'          d             Z eiey'          d             Z eiey'          d             Z eiey'          d             Z eiey'          d             Zd Zd Ze9fdZ eiey'          d             Z eiey'          d             Z eiey'          d             Z eiey'          d             Z eiey'          d             Z eiey'          d             Zd Zd Zd Zd Zd Zd Z eiey'          d             Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z eiey'          d             ZdS )zQVarious utilities to check the compatibility of estimators with scikit-learn API.    N)nullcontext)deepcopy)partialwraps)
isfunction	signature)IntegralReal)sparse)rankdata   )config_context)ClusterMixinRegressorMixincloneis_classifieris_outlier_detectoris_regressor)	load_iris
make_blobsmake_classificationmake_multilabel_classificationmake_regression)DataConversionWarningNotFittedErrorSkipTestWarning)SelectFromModelSelectKBest)LinearRegressionLogisticRegressionRANSACRegressorRidgeSGDRegressor)accuracy_scoreadjusted_rand_scoref1_score)linear_kernelpairwise_distances
rbf_kernel)ShuffleSplittrain_test_split)_safe_split)make_pipeline)StandardScalerscale)BaseRandomProjection)DecisionTreeClassifierDecisionTreeRegressor)_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)_DEFAULT_TAGS
_safe_tags)SkipTest_array_api_for_tests	_get_argsassert_allcloseassert_allclose_dense_sparseassert_array_almost_equalassert_array_equalassert_array_lessassert_raise_messagecreate_memmap_backed_dataignore_warningsraisesset_random_state)_IS_PYPYSPARSE_ARRAY_PRESENTparse_version
sp_version)_num_samplescheck_is_fittedhas_fit_parameter)PLSCanonicalPLSRegressionCCAPLSSVDc              #   \  K   | j         j        }t          |           }t          V  t          V  t
          V  t          | d          ret          V  t          V  t          V  |d         sBt          V  t          V  t          t          d          V  t          t          d          V  t          V  t          t          d          V  |d         st          V  t           V  t"          V  |t$          vr	t&          V  |d	         s|d         s	t(          V  |d         r	t*          V  t,          V  t/          | d
          r	t0          V  t2          V  t4          V  t6          V  t          t6          d          V  t8          V  |d         rt;          |           D ]}|V  d S d S )Nsample_weightpairwiseones)kindzerosTreadonly_memmapno_validation	allow_nansparsifyarray_api_support)	__class____name__rA   check_no_attributes_set_in_initcheck_estimators_dtypescheck_fit_score_takes_yrU   "check_sample_weights_pandas_series!check_sample_weights_not_an_arraycheck_sample_weights_listcheck_sample_weights_shape$check_sample_weights_not_overwrittenr   check_sample_weights_invariance!check_estimators_fit_returns_selfcheck_complex_datacheck_dtype_object$check_estimators_empty_data_messagesCROSS_DECOMPOSITIONcheck_pipeline_consistencycheck_estimators_nan_infcheck_nonsquare_error!check_estimators_overwrite_paramshasattrcheck_sparsify_coefficientscheck_estimator_sparse_arraycheck_estimator_sparse_matrixcheck_estimators_pickle%check_estimator_get_tags_default_keys_yield_array_api_checks	estimatornametagschecks       ]/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/sklearn/utils/estimator_checks.py_yield_checksr   [   s<     'Di  D
))))
!!!!
!!!!O44 	I0000////''''J 	I,,,,66669GGGGGG9HHHHHH
++++
3T
J
J
JJJJ   3        2222&&&(((( 'T/%: '&&&&J $####
++++y*%% *))))
&&&&
'''' "!!!
)4
@
@
@@@@
////  ,Y77 	 	EKKKK 	 	    c              #   n  K   t          |           }t          V  t          V  t          V  t          V  t
          V  |d         r	t          V  t          V  t          t          d          V  t          t          dd          V  t          V  |d         r$t          V  t          V  t          V  t          V  |d         st          V  |d         s	t          V  |d	         r	t           V  d
|                                                                 v r	t&          V  t(          V  t*          V  d S )NmultioutputTr`   float32ra   X_dtype
multilabelrb   multioutput_onlyrequires_fitclass_weight)rA   "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check_classifier_multioutputcheck_classifiers_trainr   #check_classifiers_regression_target6check_classifiers_multilabel_representation_invariance2check_classifiers_multilabel_output_format_predict8check_classifiers_multilabel_output_format_predict_proba<check_classifiers_multilabel_output_format_decision_functioncheck_supervised_y_no_nancheck_supervised_y_2dcheck_estimators_unfitted
get_paramskeyscheck_class_weight_classifiers'check_non_transformer_estimators_n_iter check_decision_proba_consistency)
classifierr   s     r   _yield_classifier_checksr      s     j!!D -,,,
%%%%
4444
####
1111M +****
!!!!
)4
@
@
@@@@
)4
S
S
SSSS
----L KDDDD@@@@FFFFJJJJ  (''''&' 	(''''N (''''..00557777,,,,
1111
******r   categoryc                 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  )
      sizer   sklearn.test__testingzJInput (y|Y) contains infinity or a value too large for dtype\('float64'\).zInput (y|Y) contains NaN.
Estimator z< should have raised error on fitting array y with inf value.matcherr_msg)r   nprandomRandomStatestandard_normalnaninffull_enforce_estimator_tags_y
__module__
startswithendswithisinfrM   
ValueErrorfit)
r   estimator_origr   rngXvalueymodule_namer   r   s
             r   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	c              #     K   t          |           }t          V  t          t          d          V  t          t          dd          V  t          V  t          V  |d         r	t
          V  t          V  |d         s|d         s	t          V  t          V  | j	        j
        }|dk    r	t          V  |d	         r	t          V  t          V  d S )
NTr`   r   r   r   rb   r   rX   r   )rA   check_regressors_trainr   !check_regressor_data_not_an_arrayr   check_regressor_multioutput%check_regressors_no_decision_functionr   r   rf   rg   check_regressors_intr   r   )	regressorr   r   s      r   _yield_regressor_checksr      s     i  D !   
($
?
?
????
($	
R
R
RRRR
++++
1111M *))))
////  $.@)A $####
####'Du}}""""N (''''
111111r   c              #   4  K   t          |           }|d         s	t          V  t          V  |d         r	t          V  t	          t          d          V  t          | d          s
t
          V  n	t          V  g d}| j        j        }||vrt          V  d S d S )Nrb   preserves_dtypeTr`   	statelesskey)Isomap	KernelPCALocallyLinearEmbeddingRandomizedLassoLogisticRegressionCVBisectingKMeans)
rA   #check_transformer_data_not_an_arraycheck_transformer_general!check_transformer_preserve_dtypesr   check_transformers_unfitted%check_transformers_unfitted_statelessrf   rg   check_transformer_n_iter)transformerr   external_solverr   s       r   _yield_transformer_checksr      s      k""D   21111
#### 0////
+T
B
B
BBBBk{333 4)))))3333  O  )D?""&&&&&& #"r   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_predictrf   rg   check_clusteringr   r   rz   r   )	clustererr   s     r   _yield_clustering_checksr     s      
0000'D@@@ &======55559k** 65555556 6r   c              #   (  K   t          | d          r	t          V  t          | d          r	t          V  t          | d          rDt          V  t	          t          d          V  t
          V  t          | d          r	t          V  t          V  d S )Ncontaminationfit_predictpredictTr`   r   r   )	rz   check_outlier_contaminationcheck_outliers_fit_predictcheck_outliers_trainr   r   rA   r   r   )r   s    r   _yield_outliers_checksr   !  s      y/** *)))) y-(( )(((( y)$$ ,""""*DAAAAAA0000i^444 	,++++
111111r   c              #   h   K   t                      D ] \  }}}t          t          |||          V  !d S )N)array_namespace
dtype_namer8   )r6   r   check_array_api_input)r   r   r8   r   s       r   r   r   6  se      
 
3	4	4	

 

 	!+!	
 
 
 	
 	
 	
 	


 

r   c              #   >  K   | j         j        }t          |           }d|d         vr6t          j        d                    ||d                   t                     d S |d         r/t          j        d                    |          t                     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  |d         st(          V  t*          V  t,          V  t.          V  t0          V  t2          V  t4          V  t6          V  t8          V  t:          V  |d         s,t<          V  t>          V  t@          V  |d	         r	tB          V  |d
         rtD          V  d S d S )N2darrayX_typesz8Can't test estimator {} which requires input  of type {}
_skip_testz2Explicit SKIP via _skip_test tag for estimator {}.r   non_deterministicrb   
requires_yrequires_positive_X)#rf   rg   rA   warningswarnformatr   r   r   r   r   r   rz   r   
isinstancer   r   r   r   &check_parameters_default_constructible%check_methods_sample_order_invariancecheck_methods_subset_invariancecheck_fit2d_1samplecheck_fit2d_1featurecheck_get_params_invariancecheck_set_paramscheck_dict_unchangedcheck_dont_overwrite_parameterscheck_fit_idempotentcheck_fit_check_is_fittedcheck_n_features_incheck_fit1dcheck_fit2d_predict1dcheck_requires_y_nonecheck_fit_non_negativer   s       r   _yield_all_checksr  D  s     'Di  DY''FMMd9o  		
 	
 	
 	L @GGMM	
 	
 	
 	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----


%%%%


))))

####  (!!!!#### 	(''''!" %$$$$$$% %r   c                    t          |           r| j        S t          | t                    ri| j        s| j        j        S d                    d | j                                        D                       }d                    | j        j        |          S t          | d          rMt          d          5  t          j        ddt          |                     cd	d	d	           S # 1 swxY w Y   d	S d	S )
a  Create pytest ids for checks.

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

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

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

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

    See Also
    --------
    check_estimator
    ,c                 @    g | ]\  }}d                      ||          S )z{}={})r  ).0kvs      r   
<listcomp>z,_get_check_estimator_ids.<locals>.<listcomp>  s*    SSSdaW^^Aq11SSSr   z{}({})r   T)print_changed_onlyz\s N)r   rg   r  r   keywordsfuncjoinitemsr  rz   r   resubstr)objkwstrings     r   _get_check_estimator_idsr(  }  s0   0 # |#w <| 	%8$$88SScl>P>P>R>RSSSTTsx0(;;;sL!! /t444 	/ 	/6%SXX..	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	// /s   5#C%%C),C)c                    t          | dg           }t          |          r`|dgdgfv rt          | t                    r | t	                                }n4t          | t
                    r | t                                }nt          | t                    r | t          d                    }n | t          d                    }n|dgfv rwt          | t
                    r1 | d	t          d
d          fdt          d
d          fg          }nq | d	t          d
d          fdt          d
d          fg          }n@d| j         d| }t          j        |t                     t!          |           |             }|S )z)Construct Estimator instance if possible._required_parametersr   base_estimatorr   random_stater<   )C
estimatorsest1   )	max_depthr-  est2)r/  zCan't instantiate estimator z parameters )getattrlen
issubclassr!   r   r   r"   r   r#   r    r2   r1   rg   r  r  r   rB   )	Estimatorrequired_parametersr   msgs       r   _construct_instancer:    s   !)-CRHH
 ( K=3C2D"EEE
 )_55 ?%I&6&8&899		I~66 ?%Iegg..		I77 ?%Il&B&B&BCC		%I&81&=&=&=>>		 l^$555)^44 %I!6QR!S!S!ST!6QR!S!S!ST   		 &I!7!RS!T!T!TU!7!RS!T!T!TU   		4y/A 4 414 4 
 M#///3--IKK	r   c                     t          | |          \  }}|s| |fS |                    | ||j                            |                    S )N)reason)marks)_should_be_skipped_or_markedparammarkxfail)r   r   pytestshould_be_markedr<  s        r   _maybe_mark_xfailrD    sX      <IuMMf V%||IuFK4E4EV4E4T4T|UUUr   c                      t           |          \  }|s|S t          |t                    r|j        j        n|j        t          |           fd            }|S )Nc                  H    t          d dj        j         d           )Nz	Skipping  for z: )rB   rf   rg   )argskwargs
check_namer   r<  s     r   wrappedz_maybe_skip.<locals>.wrapped  s6    Q
QQ)<)EQQQQ
 
 	
r   )r>  r  r   r   rg   r   )r   r   should_be_skippedrK  rJ  r<  s   `   @@r   _maybe_skiprM    s     !=Y N Nv (25'(B(BV$$J
5\\
 
 
 
 
 
 \

 Nr   c                     t          |t                    r|j        j        n|j        }t	          | d          pi }||v r
d||         fS dS )N_xfail_checksr   T)Fz*placeholder reason that will never be used)r  r   r   rg   rA   )r   r   rJ  xfail_checkss       r   r>  r>    s\     )35'(B(BV$$Ji_===CL\!!\*--->>r   c                      ddl t          d  D                       rd}t          |           fd}j                            d |            t
                    S )a  Pytest specific decorator for parametrizing estimator checks.

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

        pytest test_check_estimators.py -k check_estimators_fit_returns_self

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

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

        .. versionadded:: 0.24

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

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

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

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

    r   Nc              3   @   K   | ]}t          |t                    V  d S N)r  type)r  ests     r   	<genexpr>z*parametrize_with_checks.<locals>.<genexpr>,  s,      
7
7S:c4  
7
7
7
7
7
7r   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 ]K} t          |           j        }t          |           D ]%}t          ||          }t	          | |          V  &Ld S rS  )rT  rg   r  r   rD  )r   r   r   r/  rB  s      r   checks_generatorz1parametrize_with_checks.<locals>.checks_generator4  s{      # 	B 	BI	??+D*955 B Bt,,'	5&AAAAAAB	B 	Br   zestimator, check)ids)rB  any	TypeErrorr@  parametrizer(  )r/  r9  rY  rB  s   `  @r   parametrize_with_checksr^    s    P MMM

7
7J
7
7
777 / 	
 nnB B B B B B ;"",,..4L #   r   Fc                 V    t           t                    rd}t          |          t                     j         fd}|r
 |            S  |            D ]O\   }	  |            # t          $ r1}t          j        t          |          t                     Y d}~Hd}~ww xY wdS )a  Check if estimator adheres to scikit-learn conventions.

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

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

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

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

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

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

        .. versionadded:: 0.22

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

    See Also
    --------
    parametrize_with_checks : Pytest specific decorator for parametrizing estimator
        checks.

    Examples
    --------
    >>> from sklearn.utils.estimator_checks import check_estimator
    >>> from sklearn.linear_model import LogisticRegression
    >>> check_estimator(LogisticRegression(), generate_only=True)
    <generator object ...>
    rW  c               3   x   K   t                    D ]&} t          |           } t          |           fV  'd S rS  )r  rM  r   )r   r   r   s    r   rY  z)check_estimator.<locals>.checks_generator  sU      &y11 	2 	2E	511EWUD1111111	2 	2r   N)	r  rT  r\  rg   rB   r  r  r%  r   )r   generate_onlyr9  rY  r   	exceptionr   s   `     @r   check_estimatorrc  @  s    l )T"" / 	
 nn	??#D2 2 2 2 2 2
  "!!!,,.. ; ;	5	;E) 	; 	; 	; M#i../::::::::	;; ;s   A++
B&5'B!!B&c                      t           =t          dddddd          \  } }t                                          |           } | |fa t           S )N   r   r<         @   *   )	n_samples
n_featuresn_informativebiasnoiser-  )REGRESSION_DATASETr   r.   fit_transform)r   r   s     r   _regression_datasetrp    s]    !
 
 
1 **1--Tr   c                 R   |                                  }| j        j        }|dk    r|                     d           d|v r|dk    r|                     d           d|v r| j        )|                     t          d| j                             |d	v r|                     d
           |dk    r|                     d           |dk    r|                     d
d           | j        j        dk    r|                     d
d           |dv r|                     d           |dk    r|                     d           d|v r|                     d           d|v r)|                     t          d| j                             d|v r|                     d           d|v r|                     d           d|v r+|                    d           s|                     d!           |d"k    r|                     d#$           |d%k    rd&| _        |d'k    r|                     d#(           t          | d)          rt          | j
        d          | _
        t          | d*          rd&| _        |d+k    r|                     d,-           |d.k    rd| _        t          | t                    r|                     d/           t          | t                    r|                     d&0           |d1v r|                     d2           |d3k    r|                     d45           d6d7g}||vr&t          | d8          r|                     d9:           t          | d;          r|                     d9<           |d=k    r|                     d>?           |d@k    r2t           t#          dA          k    rdBndC}|                     |D           |t$          v r|                     d&/           |dEk    r|                     dFG           |dHk    r|                     d&I           d S d S )JNTSNEr   
perplexityn_iterr   ru  max_iterrw  )	LinearSVR	LinearSVCrg  NMFi  DictionaryLearning
lasso_lars)rw  transform_algorithmMiniBatchNMFT)rw  fresh_restarts)MLPClassifierMLPRegressord   MiniBatchDictionaryLearningn_resampling)r  n_estimators)r  
max_trialsr   )r  n_init)r  
batch_sizeMLP)r  	MeanShift      ?)	bandwidthTruncatedSVDr<   LassoLarsIC)noise_variance
n_clustersn_best	SelectFdr      ?alphaTheilSenRegressor)n_components)r  )HistGradientBoostingClassifierHistGradientBoostingRegressor)min_samples_leafDummyClassifier
stratified)strategyRidgeCVRidgeClassifierCVcvr1  r  n_splits)r  OneHotEncoderignore)handle_unknownQuantileRegressorz1.6.0highszinterior-point)solverSpectralEmbeddinggh㈵>)	eigen_tolHDBSCANmin_samples)r   rf   rg   
set_paramsrw  minr  r   r  rz   r  r  max_subpopulationr  r0   r   rR   rQ   ru   )r   paramsr   loo_cvr  s        r   _set_checking_parametersr    s    !!##F'Dv~~***6dfnnA&&&V)  #a1C*D*D EEE---  " ---5==  # ...'''  ", OOO'>99  "T BBB444  # ...000  ! ,,,!,,,#a1G*H*HIIIv+++6A&&&vdooe&<&<+++{ 	s+++~ "#	} 	C000y,'' <"9#7;;	y(## 	{3'''"""&)	#)122 -
 	!,,,)[)) " 	q!!!RRR 	a000    	l333 ,-F6gi66"""y*%% )a(((H555"""&-*@*@@@FVF+++"""!,,, """t,,,y+++++ r   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 rS  )r   asarraydata)selfr  s     r   __init__z_NotAnArray.__init__%  s    Jt$$			r   Nc                     | j         S rS  )r  )r  dtypecopys      r   	__array__z_NotAnArray.__array__(  s
    yr   c                 j    |j         dk    rdS t          d                    |j                             )Nmay_share_memoryTz%Don't want to call array_function {}!)rg   r\  r  )r  r   typesrH  rI  s        r   __array_function__z_NotAnArray.__array_function__+  s4    =...4?FFt}UUVVVr   )NN)rg   r   __qualname____doc__r  r  r   r   r   r  r    sU         % % %   W W W W Wr   r  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)r4  bool)r   r  s     r   _is_pairwise_metricr  1  s(     Y$//F-'(((r   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_coor   s       r   _generate_sparse_datar  C  s#      <5    

C ; ;U^^M::::::: NN5!!E	  ))EI	  ))EI
E/' ' 'NN=))I$$W--	8??7++e#Q&&&&&	' 'r   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}|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*t-          ||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                             n4t/          |d          r$|j        |j        k    sJ |j        |j        k    sJ |dk    rt/          |	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.
    rh  r,  Fr  r7   c                 N    i | ]"\  }}t          |t          j                  ||#S r  )r  r   ndarrayr  r   r   s      r   
<dictcomp>z)check_array_api_input.<locals>.<dictcomp>  s?       !sE*UBJ:W:WU  r   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   r  z)' output is in wrong namespace, expected z, 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)rC   r   r  _enforce_estimator_tags_Xr   r   r  r   varsr"  r   r5   rg   r4  array_devicer4   rE   r3   r  r  r  floatabsrz   r  )r   r   r   r8   r   check_valuesr  r   r   rU  X_xpy_xparray_attributesest_xpinput_nsr   	attributeest_xp_paramattribute_nsest_xp_param_npmethodsmethod_namemethodresult	result_xp	result_nsresult_xp_npinverse_resultinvese_result_xpinverse_result_nsinvese_result_xp_nps                                  r   r   r   d  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  @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sl   81D55D9<D99F  F$	'F$	J++J/	2J/	,MM	M	-NN	N	0SS	S	c                 ,    t          | ||||d          S )NT)r   r8   r   r  )r   )r   r   r   r8   r   s        r    check_array_api_input_and_valuesr    s-     !'   r   c                 Z   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          rQ|                    |          }
|d         r|
j        |j        d         dfk    sJ n|
j        |j        d         fk    sJ t'          |d          rI|                    |          }|d         r|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   )(   r1  r   g333333?   r   )Scalerr.   F)	with_mean64r   z doesn't seem to support z` matrix, and is not failing gracefully, e.g. by using check_array(X, accept_large_sparse=False).z doesn't seem to fail gracefully on sparse data: error message should state explicitly that sparse input is not supported if this is not the case, e.g. by using check_array(X, accept_sparse=False).r   SparseTr   may_passr   r   r   r<   r  binary_onlyr   )r   r   r   uniformr  r  r  int32rL   FutureWarningr   r   rA   r  r  rM   r\  r   r   rz   r   r  )r   r   sparse_typer   r   r   r   r   matrix_formatr   predprobsexpected_probs_shapes                r   !_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 ((++*+ 7:!'!*a88888:!'!*6666y/22 ;!//22& ;,-GAJ?((,-GAJ?({&:::::)	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;)(; (;s[   %CCC*EE	E	J*GJGJGB=JJ"	%J"	c                 <    t          | |t          j                   d S rS  )r#  r   
csr_matrixr   r   s     r   r}   r}   :  s    %dNF<MNNNNNr   c                 N    t           rt          | |t          j                   d S d S rS  )rP   r#  r   	csr_arrayr&  s     r   r|   r|   >  s2     R)$@PQQQQQR Rr   c                 d   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          |d
          r|                    |d          }	 |                    |||           d S # t          $ r# t          d
                    |                     w xY w# t          $ r t          d          w xY w)Nr   r<   r   r1  r  Fr  r<   r<   r<   r<   r   r   r   r   r<   r<   r   r      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  SeriesrA   r   r   r  ImportErrorrB   )r   r   r   pdr   r   weightss          r   rk   rk   C  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%%i%7888 	,QU++A	MM!QgM66666 	 	 	%%+VD\\  	  
 
 
;
 
 	

s   B9D C% %-DD D/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          |d          r(t          |j                            d	d                    }|                    |||
           d S )Nr<   r   r1  r  r*  r+  r   r   r,  )	r   r   r.  r  r  rA   r  reshaper   )r   r   r   r   r   r3  s         r   rl   rl   o  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)!3444 /r1--..MM!QgM.....r   c                 <   t          |          }t          j                            d          }d}t	          ||                    |df                    }t          j        |          dz  }t          ||          }dg|z  }|                    |||           d S )Nr      r1  r   r,  )	r   r   r   r   r  r  aranger   r   )r   r   r   rndri  r   r   r[   s           r   rm   rm     s     n%%I
)


"
"CI!.#++Iq>+2R2RSSA
	)q A!)Q//AC)OMMM!QmM44444r   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 )Nr<   r1  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]   r5  rM   r   )r   r   r   r   r   s        r   rn   rn     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r]   c                 D   t          |          }t          |          }t          |d           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
                    }|d	k    r-|}|}t          j        t          |          
          }	d|  d}
n|dk    rt          j        ||dz   g          }t          j	        |d|z
  g          }t          j        t          |          dz  
          }	d|	t          |          d <   t          |||	d          \  }}}	d|  d}
nt          t          ||          }t          ||          }|                    ||d            |                    |||	           dD ]V}t          ||          rD t          ||          |          } t          ||          |          }t!          |||
           Wd S )Nr   r,  r<   r1  r   r  r  r<  r]   )r  zFor z; sample_weight=None is not equivalent to sample_weight=onesr_   z?, a zero sample_weight is not equivalent to removing the sample)r   r[   )r   r  r  r   r   )r   rN   r   r.  r  intr]   r5  vstackhstackr=   r   r   r   rz   r4  rF   )r   r   r^   
estimator1
estimator2X1y1X2y2sw2r   r  X_pred1X_pred2s                 r   rp   rp     s    ~&&J~&&JZa0000Za0000	FFFFFFFFFFFFFFFF!	
$ j'
 
 
B* 
BBB#	N	N	NBv~~gCGG$$$T4TTT 	 
 YBF|$$YAF|$$gCGGaK(((CGGIIb"c:::B Y4XXX 	 	":r	2	2B	":r	2	2BNN24N000NN23N///P L L>6** 	L1gj&11"55G1gj&11"55G('7KKKK	L Lr   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,  r<   r1  r   r  r>  r<  g      $@r,  z8 overwrote the original `sample_weight` given during fitr?  )r   rN   r   r.  r  r@  r   r]   r  r  r   rE   )r   r   r   r   r   sample_weight_originalsample_weight_fitr   s           r   ro   ro     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Or   c                    t           j                            d          }t          ||                    d                    }|                    t                    }t          |          }|d d df         dz                      t                    }t          |          }t          ||          }|                    ||           t          |d          r|                    |           t          |d          r|                    |           t          t           dd	          5  |                    ||                    t                               d d d            n# 1 swxY w Y   d
|d         vrPd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  r   r   r  r   r   zUnknown label typeTr   r  stringr   foobarr   r   z#argument must be .* string.* numberr   )r   r   r   r  r  r  objectrA   r@  r   r   r   rz   r   r   rM   	Exceptionr\  )r   r   r   r   r   r   r   r9  s           r   rs   rs   -  sJ    )


"
"C!.#++8+2L2LMMA	An%%D	
111a41S!!An%%I!)Q//AMM!Qy)$$ !y+&& A		!5	E	E	E + +a&))***+ + + + + + + + + + + + + + + tI&&%.$ 4IS))) 	  	 MM!Q	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	as$   */E%%E),E)F==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 )Nrh  r   r   y              ?r5  r<   r   r   lowhighr   r,  zComplex data not supportedrU  )r   r   r   r  r6  randintr   rN   rM   r   r   )r   r   r   r   r   r   s         r   rr   rr   R  s   
)


#
#CrCKKRK$8$888A			"aA 	++b0An%%IYQ////	
">	?	?	?  a                 s   7CC"Cc                    | dv rd S t           j                            d          }| dv rd|                    d          z  }nd|                    d          z  }t	          ||          }|d d df                             t                    }t          |          }t          ||          }t          |d          rd	|_
        t          |d
          rd	|_        t          |d          rd	|_        t          |d	           |                    ||           dD ]\}t          ||          rJ|j                                        } t#          ||          |           |j        |k    sJ d|z              ]d S )N)SpectralCoclusteringr   )r!   r1  rg  r1  r   r   r  r<   r  r  r   r   r  r  z$Estimator changes __dict__ during %s)r   r   r   r  r  r  r@  r   r   rz   r  r  r  rN   r   __dict__r  r4  )r   r   r:  r   r   r   r  dict_befores           r   r  r  `  s    '''
)


"
"C"""))))))!.!44A	!!!Q$sAn%%I!)Q//Ay.)) #!"	y,'' ! 	y(## 	Y"""MM!QP  9f%% 	#,1133K&GIv&&q)))%4446? 544	 r   c                 X    |                      d          p|                     d           S )N_)r   r   )attrs    r   _is_public_parameterrf    s(    $$:c(:(:;;r   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   r1  r_  r   r  r<   r  c                 0    g | ]}t          |          |S r  )rf  )r  r   s     r   r  z3check_dont_overwrite_parameters.<locals>.<listcomp>  s6       0DS0I0I  r   c                 @    g | ]}|                                 v|S r  )r   )r  r   dict_before_fits     r   r  z3check_dont_overwrite_parameters.<locals>.<listcomp>  s6       ?;O;O;Q;Q0Q0Q0Q0Q0Qr   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 r  r  )r  r   dict_after_fitrk  s     r   r  z3check_dont_overwrite_parameters.<locals>.<listcomp>  s8       C s(;;; 	;;;r   zEstimator changes public attribute(s) during the fit method. Estimators are only allowed to change attributes started or ended with _, but %s changed)rz   r  r   r   r   r   r  r  r  r@  r   r  r  rN   ra  r  r   r   r!  )r   r   r   r:  r   r   public_keys_after_fitattrs_added_by_fitattrs_changed_by_fitrn  rk  s            @@r   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    r   c           	      D   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          ||          r+t          t          d	t!          ||          |d                    >d S )
Nr   r1  r_  r   r  r<   r  r`  zReshape your data)r   r   r   r  r  r  r@  r   r   rz   r  r  rN   r   rJ   r   r4  )r   r   r:  r   r   r   r  s          r   r  r    s'    )


"
"C	CKKWK%%%A!.!44A	!!!Q$sAn%%I!)Q//Ay.)) #!"	y,'' ! 	Y"""MM!QP  9f%% 	 /F1K1KQqT   r   c                       |          }|j         d          fd|D             }t          |t                    r&|d         }t          t	          d |                    }t          j        |          r |                                }d |D             }t          j	        |          t          j	        |          fS )Nr<   c                 N    g | ]!} |                     d                     "S )r<   )r6  )r  batchr   rj  s     r   r  z%_apply_on_subsets.<locals>.<listcomp>  s1    IIIettEMM!Z8899IIIr   r   c                     | d         S )Nr   r  )xs    r   <lambda>z#_apply_on_subsets.<locals>.<lambda>  s
    QqT r   c                 6    g | ]}|                                 S r  )toarray)r  rw  s     r   r  z%_apply_on_subsets.<locals>.<listcomp>  s     @@@1199;;@@@r   )
r  r  tuplelistmapr   issparserz  r   ravel)r   r   result_fullresult_by_batchrj  s   `   @r   _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  "(?";";;;r   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   r1  r_  r   r  r<   r  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   rz   r  r  rN   r   r  r  r4  rE   )
r   r   r:  r   r   r   r  r9  r  r  s
             r   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r   c           	      H   t           j                            d          }d|                    d          z  }t	          ||          }|d d df                             t           j                  }t          |d          r	d||dk    <   t          |          }t          ||          }t          |d	          rd|_        t          |d
          rd|_        t          |d           |                    ||           t           j                            |j        d                   }dD ]v}d                    ||           }t          ||          rMt%           t'          ||          |          |          t'          ||          ||                   d|           wd S )Nr   r1  r_  r   r  r   r<   r   r  r  r  zY{method} of {name} is not invariant when applied to a datasetwith different sample order.r  &.>r  )r   r   r   r  r  r  r  rA   r   r   rz   r  r  rN   r   permutationr  r  rF   r4  )	r   r   r:  r   r   r   idxr  r9  s	            r   r  r    s    )


"
"C	CKKWK%%%A!.!44A	!!!Q$rx  A.m444 !q&	n%%I!)Q//Ay.)) #!"	y,'' ! 	Y"""MM!Q
)



+
+C  +
&T&
*
* 	
 9f%% 	(*	6**1--c2*	6**1S622	    r   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   r1  )r<   r   r   r  r<   r  OPTICSr  r  rr  r  rs  )z1 samplezn_samples = 1zn_samples=1z
one samplez1 classz	one classTrP  )r   r   r   r  r  r  r@  r   r   rz   r  r  rN   r  rM   r   r   r   r   r:  r   r   r   msgss          r   r  r  A  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   r1  )r   r<   r   r  r<   r  RandomizedLogisticRegressionr!   r  )z1 feature\(s\)zn_features = 1zn_features=1TrP  )r   r   r   r  r  r  r@  r   r   rz   r  r  sample_fractionresidual_thresholdrN   rM   r   r   r  s          r   r	  r	  j  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   r1  rg  r   r  r<   r  )r   r   r   r  r  r@  r   r   rz   r  r  rN   rM   r   r   )r   r   r:  r   r   r   s         r   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 Nr8  r   r   r   r<   r<   r<   r   r   皙?ri  centersr-  rj  cluster_std)r   r.   ro  r  rK   _check_transformer)r   r   ra   r   r   s        r   r   r     s    III&  DAq 	&&q))A!+q11A 1(!Q001t[!Q/////r   c                    t          dg dg dgddd          \  }}t                                          |          }t          ||          }t	          |          }t	          t          j        |                    }t          | |||           t          | ||                                |                                           d S r  )	r   r.   ro  r  r  r   r  r  tolist)r   r   r   r   this_Xthis_ys         r   r   r     s    III&  DAq 	&&q))A!+q11A^^FA''Ft[&&999t[!((**ahhjjAAAAAr   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.r?  )rp  r   rM   AttributeErrorr   r   )r   r   r   r   s       r   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   rg  r   r   N)r   r   r   r  r  r   r   r  )r   r   r   r   X_transs        r   r   r     s    
 )


"
"C!!A!+q11A$$K##A&&G=qwqz))))))r   c                 `   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          |d          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          |d          sv|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   r<   r   r   r   r   r    is non deterministic{Gz?z9fit_transform and transform outcomes not consistent in %sr  z7consecutive fit_transform outcomes not consistent in %sr  r  r   zThe transformer zr does not raise an error when the number of features in transform is different from the number of features in fit.r?  r5  )r   r  r  r   rN   ru   c_r  r  r   ro  r{  rz   r   rA   rB   ziprF   rS   ndimrM   r   )r   transformer_origr   r   ri  rj  r   y_transformer_cloneX_predx_predrK  X_pred3r9  x_pred2x_pred3s                   r   r  r    s=   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&,?@@@ 	 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{<<<	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   *"LL Lc                 2   t          |d          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  r8  r  r  r   r   r  r  kernelr  ro  )rA   rB   r   r  r)   r   r   rN   r-   r   r4  rF   )r   r   r9  r   r   r   pipelinefuncs	func_namer   func_pipeliner  result_pipes                r   rv   rv   ;  sT   .&9::: ,,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(===> >r   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   r8  r1  r   )r   r  partial_fitr   ro  c                     g | ]	}|j         
S r  )r   )r  ps     r   r  z+check_fit_score_takes_y.<locals>.<listcomp>n  s    HHHqAFHHHr   r  r<   )r   Yz.Expected y or Y as second argument for method  of z. Got arguments: r  )r   r   r   r  r  r9  r   r   rN   r4  r   
parametersvaluesrT  rg   )r   r   r:  ri  r   r   r   r  r  r   rH  s              r   rj   rj   \  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> )(( r   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   r1  r  r   r<   r   r   r>  r`  )r   r   r   r  r  r   r  r  r  r  r.  r   r   rN   r   rz   r4  )r   r   r:  
X_train_32
X_train_64X_train_int_64X_train_int_32r   r  X_trainr   r  s               r   ri   ri   z  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 4r   c                 p   t          dg dg dgdd          \  }}t                                          |          }t          ||          }t	          |d          D ]}|                    |          }t          |          }t          |           |                    ||          }|                    ||          	                    |          }t          ||gd	d
g          D ]M\  }	}
t          |	t                    r|	d         }	|	j        |k    s J |  d|
 d|j         d|	j         d            Nd S )Nr8  r  r  r   r  )ri  r  r-  r  r   r   ro  r   z	 (method=z3) does not preserve dtype. Original/Expected dtype=z, got dtype=r  )r   r.   ro  r  rA   r  r   rN   r   r   r  r  r{  r  rg   )r   r  r   r   r  X_castr   X_trans1X_trans2Xtr  s              r   r   r     s    III&	  DAq 	&&q))A!"2A66A,2CDDD  %,--%%%,,VQ77??61--77??x2_k4RSS 
	 
	JB"e$$  U 8u$$$ S S& S S+0>S SGIxS S S %$$$
	 r   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 )Nr<   r   r1  The estimator zc does not raise a ValueError when an empty data is used to train. Perhaps use check_array in train.r?  r+  )r<   r   r<   r   r<   r   r<   r   r<   r   r<   r   zG0 feature\(s\) \(shape=\(\d*, 0\)\) while a minimum of \d* is required.rU  )
r   rN   r   emptyr6  rM   r   r   r   r.  )r   r   eX_zero_samplesr   X_zero_featuresr   r9  s           r   rt   rt     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   r   r1  r   rT  r   r   r   z& doesn't check for NaN and inf in fit.z* doesn't check for NaN and inf in predict.z, doesn't check for NaN and inf in transform.r   r<   r   NaNr   r   r   )r   r   r   r  r  r   r   r]   r   rL   r  r   rN   rM   r   r   rz   r   r   )r   r   r:  X_train_finiteX_train_nanX_train_infr   error_string_fiterror_string_predicterror_string_transformr  r   s               r   rw   rw     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.rg  r   )ri  rj  zThe pairwise estimator z+ does not raise an error on non-square datar?  N)r   r   rM   r   r   r   r   r   r   r   s        r   rx   rx     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          |          }|d
         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        |          }
t-                      }|D ].}t/          |	|          r t1          |	|          |          ||<   /|D ]1} t1          |
|          |          }t3          ||         |           2dS )z'Test that we can pickle all estimators.r`  r8  r  r  r   r   r  r  r  rc   rh  r   F)replacer5  r   r   r   s   _sklearn_versionN)r   r  r)   rA   r   r   r   choicer   r   r6  r   r   rN   r   rK   pickledumpsr   r   r   loadsdictrz   r4  rF   )r   r   ra   check_methodsr   r   r   r   maskr   unpickled_estimatorpickled_estimatorr   r  r  unpickled_results                   r   r~   r~   
  s    SRRMIII&  DAq 	".!JGGGAn%%DK %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r   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   r<   ri  r-  classesr  zZ does not raise an error when the number of features changes between calls to partial_fit.r?  r5  )rz   r   r   r  r   r   r   uniquer  NotImplementedErrorrM   r   )r   r   r   r   r   r  s         r   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|||          \  }}|                    ||           |                    |          }|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	          rC|                    |          }t          |t&                    r|d
         st)          |          D ]}||         j        |dfk    s+J d                    |df||         j                              t#          t          j        ||         d                              t                    |d d |f                    nt|d
         sl|j        ||fk    s%J d                    ||f|j                              t#          |                                                    t                    |           t          |d          rt          |d	          r|t)          |          D ]n}|                    |          d d |f         }|
                    |          }t#          t/          |          t/          |d d |f                              kd S d S d S )N)rh  r   r1  rh  )r-  ri  n_labels	n_classesSThe shape of the prediction for multioutput data is incorrect. Expected {}, got {}.ir  zaThe shape of the decision function output for multioutput data is incorrect. Expected {}, got {}.r   r  
poor_scorer   zTThe shape of the probability for multioutput data is incorrect. Expected {}, got {}.r<   axis)rA   r   r   r   r   r  r  r  r^   rz   r  r  r   r  r  r@  classes_rH   r  r|  rangeargmaxroundr   )r   r   ri  r  r  r   r   r   y_preddecisiondec_preddec_expy_probr  y_proba
y_decisions                   r   r   r   ]  s   %-"Ixi  Di  I)9x9  DAq 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,> 	C9%% 	 	ay9a.88877=v"Aq	8 8 988 #IfQia00077<<fQQQTl   	 l# 	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r   c                    t          |          }dx}}t          |          s|dz   }t          dd||          \  }}t          ||          }|                    ||           |                    |          }|j        t          j        d          k    s"J d                    |j                              |j	        |j	        k    s
J d            d S )	Nr   r<   rh  r   )r-  	n_targetsri  rj  r  zbMultioutput predictions by a regressor are expected to be floating-point precision. Got {} insteadr  )
r   r  r   r  r   r   r  r   r  r  )r   r   ri  rj  r   r   r  s          r   r   r     s    i  II
y)) "M	1	j  DAq 	")Q//AMM!Qq!!F<28I.....	44:F6<4H4H /.. <17"""	  #""""r   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'          |d          rd S t          |           t)          j        d          5  |                    |          }d d d            n# 1 swxY w Y   t/          |
|           |
j        t          j        d          t          j        d          fv sJ |j        t          j        d          t          j        d          fv sJ |                    |          }t          j        |          }t/          |t          j        |d         |d         dz                        |d         dv sJ t          |d
          r!t7          |d
          }|dz
  |d         k    sJ d S d S )Nr  r<   r     r,  r1  )r   r   rY  r  )r  AffinityPropagationi)
preferencer  rx  g?r   r   Trecordr  r  r   r5  )r   r5  )r   r   r=   r.   ro  r   r   r   concatenater  rK   r  rz   r  rN   r   r  labels_r%   rA   r  catch_warningsr   rH   r  r  r9  r4  )r   clusterer_origra   r   r   r   r   X_noiseri  rj  r   pred2labelslabels_sortedr  s                  r   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''#----)!4555 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   G..G25G2c                 z   t          dd          \  }}t          |          }t          |           t          |d          rx|                    |                              |          }|                    d           |                    |                              |          }t          ||           dS dS )z2Check that predict is invariant of compute_labels.rg  r   r  compute_labelsF)r  N)r   r   rN   rz   r   r   r  rH   )r   r  r   r   r   rJ  rK  s          r   r   r     s     333DAqn%%IYy*++ ---""**1--E222--""**1--7G,,,,,- -r   c                 F   d}d}t           j                            d          }|                    d          }|                    d          }t          j        d          }t          t                    5  t          |          }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   r   r   classTr  r?  )r   r   r   r  r]   rL   r  r   rM   r   r   raised_and_matchedrH   r   )
r   classifier_origr  r  r:  r  X_testr   r   cms
             r   r   r     s   OU
)


"
"Ckkwk''G[[g[&&F
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<   9(D!C8DC	DC	D$%DD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   )r   r   r   r   r   r[   z\bclass(es)?\bz\bsample_weight\bNTr  r,  r?  )r   r   r   r  r9  r  r   rU   AssertionErrorr   r\  rM   r   r  rH   r   r]   )r   r  	error_fiterror_predictr:  r  r  r   r[   r   r   err_typer   r   s                 r   r   r   	  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          |          }	|	d         s|                    ||f           |D ]\  }
}t          j
        |          }t          |          }|
j        \  }}t          |          }t          ||
          }
t          ||          }t!          |           |	d	         sPt#          t$          d
|  d          5  |                    |
|d d                    d d d            n# 1 swxY w Y   |                    |
|           |                    |
                                |                                           t+          |d          sJ |                    |
          }|j        |fk    sJ |	d         st/          ||          dk    sJ d}d}|	d	         s|	d         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   t+          |d          r	 |                    |
          }|dk    rg|	d         s|j        |fk    sJ n|j        |dfk    sJ |                                dk                        t:                    }t=          ||           n3|j        ||fk    sJ t=          t          j        |d          |           |	d	         s|	d         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# t@          $ r Y nw xY wt+          |d          r|!                    |
          }|j        ||fk    sJ t=          t          j        |d          |           tE          t          j#        |d          t          j$        |                     |	d	         s|	d         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   t+          |d          rn|%                    |
          }tM          |t          j'        |          dd           t=          t          j(        |          t          j(        |                     d S )N,  r   r  r  r,  r   )BernoulliNBMultinomialNBComplementNBCategoricalNBr  rb   The classifier  does not raise an error when incorrect/malformed input data for fit is passed. The number of training examples is not the same as the number of labels. Perhaps use check_X_y in fit.r?  r5  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\   r   r<   r  r   r  r  r     r  )r  ))r   r  r=   r.   ro  r  rK   rA   appendr   r  r5  r  r   r  r   rN   rM   r   r   r  rz   r   r$   r  r6  Tr  r  r@  rH   r  r  r  rG   sumr]   r  rE   logargsort)r   r  ra   r   X_my_my_bX_bproblemsr   r   r   r  r  ri  rj  r   r  msg_pairwiser9  r  r  r  
y_log_probs                           r   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$$$O$ 
	*<d < < <   	* 	* q!CRC&)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	q!qxxzz188::...z:.....##A&&|	|++++L! 	4!!V,,t3333G 	
 	 O$ 		,J ,(//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::>> 23 @'~)====='~)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 O, >J' >#&$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   F77F;	>F;	#*KK	 K	L66L:	=L:	C/S!*Q8,S!8Q<	<S!?Q<	 .S!.S	S!S	S!S	S!!
S.-S.:*W00W4	7W4	&YY	Y	c                     | |k     r| }|dz   }n|}| dz   }t          j        |          }d}t          t          j        |||                             dk    s
J |            d S )Nr<   zThe number of predicted outliers is not equal to the expected number of outliers and this difference is not explained by the number of ties in the decision_function values)r   sortr5  r  )num_outliersexpected_outliersr  startendsorted_decisionr9  s          r   check_outlier_corruptionrB  	  s     '''!#!Q
 gh''O	9 
 rys34455:::C:::::r   Tc                 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  r5  r<   r  r   noveltyr8  r   )r   r=   rK   r  r   rN   r   r  r   r  r^   rH   r   r  r.  r  r  rM   r   r0  r  r@  offset_rE   rz   r  r1  rB  )r   r   ra   ri  r   rd  rj  r   r  r  scoresoutputr  y_decr>  r   r=  s                    r   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 r  )r  r?   )r  cs     r   r  z/check_outlier_contamination.<locals>.<listcomp>0
  s"    KKKA
1h''KKKr   zDcontamination constraints should contain a Real Interval constraint.        r  r   >   rightneitherz:contamination constraint should be an interval in (0, 0.5])rz   rK  r[  r"  r  r?   rT  r
   leftrO  closed)r   r   contamination_constraints
constraints       r   r   r   $
  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r   c           	         t          ddddddd          \  }}t          |          }|d d	         |d d	         }}|d	d          }|                                }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   r1  r  Tr   ri  rj  r  r  lengthallow_unlabeledr-  P   )r   r/   r  r|  r   rN   r   r   rH   r  rT  )r   r  r   r   r  y_trainr  y_train_list_of_listsy_train_list_of_arraysr   r  y_pred_list_of_listsy_pred_list_of_arrayss                r   r   r   ?
  s   )  DAq 	aA"vq"vWGrssVF#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5r   c           	         t          |          }t          |           d\  }}}t          |d|dddd          \  }}t          |          }|d|          || d         }	}|d|          || d         }}
|                    ||
           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   r1  r  Tr   rV  Nr    does not have a  method.z2.predict is expected to output a NumPy array. Got 	 instead.z(.predict outputs a NumPy array of shape  instead of r  z>.predict does not output the same dtype than the targets. Got )r   rN   r   r/   r   r4  rB   r  r   r  rT  r  r  )r   r  r   ri  	test_size	n_outputsr   r   r  r  rZ  y_testresponse_method_namepredict_methodr  s                  r   r   r   h
  s    ''JZ   &0#Iy))  DAq 	aA)na
nVG)na
nVG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 (''''r   c           	      t   t          |          }t          |           d\  }}}t          |d|dddd          \  }}t          |          }|d|          || d         }	}|d|          }
|                    ||
           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.r`  r   r1  r  Tr   rV  Nr  rb  rc  zWhen zn.predict_proba returns a list, the list should be of length n_outputs and contain NumPy arrays. Got length of re  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 rd  z.predict_proba returns a list, each NumPy array should contain probabilities for each class and thus each row should sum to 1 (or close to 1 due to numerical errors).r<   r  r?  zX.predict_proba returns a NumPy array, the expected shape is (n_samples, n_outputs). Got zN.predict_proba returns a NumPy array, the expected data type is floating. Got z.predict_proba returns a NumPy array, this array is expected to provide probabilities of the positive class and should therefore contain values between 0 and 1.zUnknown returned type z by z4.predict_proba. A list or a Numpy array is expected.)r   rN   r   r/   r   r4  rB   r  r|  r5  r  r  r^   rE   r1  r   r  rI   r   rT  )r   r  r   ri  rf  rg  r   r   r  r  rZ  ri  predict_proba_methodr  r   r   s                   r   r   r   
  s    ''JZ   &0#Iy))  DAq 	aA)na
nVG)nG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
 
 	
r   c           	      |   t          |          }t          |           d\  }}}t          |d|dddd          \  }}t          |          }|d|          || d         }	}|d|          }
|                    ||
           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.r`  r   r1  r  Tr   rV  Nr  rb  rc  z<.decision_function is expected to output a NumPy array. Got rd  z].decision_function is expected to provide a NumPy array of shape (n_samples, n_outputs). Got re  r  rl  z?.decision_function is expected to output a floating dtype. Got )r   rN   r   r/   r   r4  rB   r  r   r  rT  r  r  r^   )r   r  r   ri  rf  rg  r   r   r  r  rZ  ri  decision_function_methodr  s                 r   r   r   
  s    ''JZ   &0#Iy))  DAq 	aA)na
nVG)nG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
 <### 	( 	(	( 	( 	( $####r   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.
    r   zU should have raised a NotFitted error when fit is called before get_feature_names_outr?  N)r   rM   r   get_feature_names_out)r   r   r   r   s       r   !check_get_feature_names_out_errorrr    s     n%%I	(T 	( 	( 	(  
	0	0	0 * *'')))* * * * * * * * * * * * * * * * * *s   AAAc                 
   t          dd          \  }}t          ||          }t          |          }t          ||          }|rt	          ||g          \  }}t          |           |                    ||          |u sJ dS )z+Check if self is returned when calling fit.r      r-  ri  N)r   r  r   r   rK   rN   r   )r   r   ra   r   r   r   s         r   rq   rq   '  s     1333DAq!.!44An%%I!)Q//A 1(!Q001Y==A)++++++r   c                     t                      \  }}t          |          }dD ]W}t          ||          rEt          t                    5   t          ||          |           ddd           n# 1 swxY w Y   XdS )z}Check that predict raises an exception in an unfitted estimator.

    Unfitted estimators should raise a NotFittedError.
    )r  r   r  r  N)rp  r   rz   rM   r   r4  )r   r   r   r   r   r  s         r   r   r   7  s       DAqn%%I . . 9f%% 	.'' . .*	6**1---. . . . . . . . . . . . . . .. .s   	A//A3	6A3	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  }|d         s#t'          |	          dk    s
J |            d|v sJ t)          |                                |
                                           d S )Nr   r8  r1  r   Tr  alwaysr  z)expected 1 DataConversionWarning, got: %srl  c                 ,    g | ]}t          |          S r  r%  )r  w_xs     r   r  z)check_supervised_y_2d.<locals>.<listcomp>c  s    cSr   r   zPDataConversionWarning('A column-vector y was passed when a 1d array was expected)rA   r   r   r   r  r  r9  r   r   rN   r   r   r  r  simplefilterr   RuntimeWarningnewaxisr!  r5  rE   r  )r   r   r   r:  ri  r   r   r   r  w	y_pred_2dr9  s               r   r   r   L  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                    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	
           |dk    r4t!          t          j        |          t          j        |                     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 'rl  z', got 'r  r?  decision_function_shapeovrr<   r  r*  z"Unexpected classes_ attribute for )r   r  r   meanrN   r   r   rz   r  r  r  r5  r  r  r@  r  rH   r!  r}  r%  r4  r  )r   r   r   r  r  r   r  r  r  r  
decision_yy_exps               r   check_classifiers_predictionsr  o  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..////    ~ 	29Q<<6):):;;; JJIIc#w''((((IIc#z2334444	
	 	 	 	 	 	r   c                     | dv r|n|S )N)LabelPropagationLabelSpreadingSelfTrainingClassifierr  )r   r   y_namess      r    _choose_check_classifiers_labelsr    s    
 SSS 	
r   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          |d          s|
                    |||f           |
D ]C\  }}}||	                    d          fD ]%}t          | ||          }t          ||| |           &Dddg}t          j        ||          }	t          | ||	          }t          ||| |           d S )Nr8  r   r  )ri  r-  r  r  r,  r   )onetwothreer  r  r  r   Or5  r<   )r   r=   r.   ro  r  r   takerA   r/  r  r  r  )r   r  X_multiclassy_multiclassX_binaryy_binarylabels_multiclasslabels_binaryy_names_multiclassy_names_binaryr8  r   r   r  	y_names_ir  s                   r   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o=999 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Lr   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   r1  r   r   r  r  )rp  r  r   r   r   r\  r  r   r   rN   ru   rA  r5  r0  r   r   r  r  rE   )r   regressor_origr   rd  r:  r   regressor_1regressor_2r  pred1r  s              r   r   r     sx     DAq!.!CRC&99A
)


"
"CAAGAJ''A!.!44A
)


"
"C''K''K[!!![!!!"""Y1q53;;qs1vv;#>#>>?@@T OOAr""EOOAryy''(((""EE5tT::::::r   c           
      P   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          |d          s|                    ||          dk    sJ d S d S )Nr   r   r   alphasr  r  PassiveAggressiveRegressorr,  r-  r?  r5  r  r   r  )rp  r  r/   r   r  r   ru   r   r   r   rA  r\  r5  r0  rK   rz   r  r.  rM   r   r   rN   r  r   r  rA   r  )
r   r  ra   r   r   r   r   r:  r  r  s
             r   r   r     ss      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\222 ,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   )r   r  r   )r  r  r  )	r   r   r   r   normalr  r   r   rz   )r   r  r   r   r   r   r  r  s           r   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 1r   c                    t          |d          rdg}nddg}|D ]}t          |dd          \  }}t          ||dd	          \  }}}}	t          |d
          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          |d          st          j        |dk              dk    sJ d S )Nr  r   r   r1  r   rg  )r  r-  r  r  rf  r-  r\     g-C6?)r   r<   )r   r<   r   r   ru  r  rv  rw  rx  min_weight_fraction_leafr  )r  n_iter_no_change)r  r  gףp=
?)rA   r   r+   r)   r5  r   r  r   r  rz   rN   r   r   r  )r   r  r8  	n_centersr   r   r  r  rZ  rh  r   r   r  s                r   r   r   <  s%   /}555 3q6 #/ #/	)!LLL1+;qCa,
 ,
 ,
(&
 o:666 	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++ /|<<< 	/76Q;''$....G#/ #/r   c                    t          |          }t          |d          r|                    d           t          |d          r|                    d           t          |           |                    ||           |                    |          }|                    d           |                    ||           |                    |          }	t          ||	d	
          t          ||d	
          k    sJ d S )Nru  r  rv  rw  r  rx  balancedr  weighted)average)r   rz   r  rN   r   r   r&   )
r   r  r  rZ  r  rh  r3  r   r  y_pred_balanceds
             r   'check_class_weight_balanced_classifiersr  i  s!    ''Jz8$$ *S)))z:&& -t,,,Z   NN7G$$$''Fz222NN7G$$$ ((00OFOZ@@@8
D D D      r   c                    t          j        ddgddgddgddgddgg          }t          j        g d          } |            }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  rN  )r<   r<   r<   r5  r5  ru  r  rv  rw  rx  r  r1  r  r  r  r<   r5  )r<   r5  z>Classifier %s is not computing class_weight=balanced properly.r?  N)r   r.  rz   r  rN   r   coef_r  r5  r  r  r1  rE   )
r   
Classifierr   r   r   coef_balancedri  r  r   coef_manuals
             r   -check_class_weight_balanced_linear_classifierr    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     r   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   rt  ru  r  r   z, should not change or mutate  the parameter z from z to z during fit.)r   r  r)   r   r   rN   r   r   r   r"  joblibhash)r   r   r   r   r   r  original_params
new_params
param_nameoriginal_value	new_values              r   ry   ry     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
 
r   c                 x   	 t          |          }n!# t          $ r t          d|  d          w xY wt          t          |          j        d          rdS t          t          |          j                  }t          rdD ]}||v r|                    |           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.r   z9 should store all parameters as an attribute during init.rh  N)r&  c                     g | ]	}|D ]}|
S r  r  )r  params_parentr?  s      r   r  z3check_no_attributes_set_in_init.<locals>.<listcomp>  s?       "   	   r   c              3   4   K   | ]}t          |          V  d S rS  )rD   )r  parents     r   rV  z2check_no_attributes_set_in_init.<locals>.<genexpr>  s*      VVFi//VVVVVVr   c                 <    g | ]}|                     d           |S )rd  )r   )r  re  s     r   r  z3check_no_attributes_set_in_init.<locals>.<listcomp>  s)    RRRT__S=Q=QRRRRr   zR should not set any attribute apart from parameters during init. Found attributes r  )r   r  rz   rT  r  rD   rO   remove__mro__setr  sorted)r   r   r   init_paramsr   parents_init_paramsinvalid_attrs          r   rh   rh     s   
 .))		 
 
 
XXXX
 
 	


 tI')>?? DOO455K ( 	( 	(Ck!!""3''' 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 )Nr5  r<   r   )	r<   r<   r<   r   r   r   r1  r1  r1  )r   r.  r   r   r   r   rd   r   r~  r  rH   r  r  r  )r   r   r   r   rU  	pred_origr   s          r   r{   r{     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'''''r   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 )Nr1  r   r<   r   r  )r<   r<   r<   r   r   r   r<   r<   r<   r   r   r   
NotAnArrayPandasDataframe)r   r.  r  r   "check_estimators_data_not_an_arrayr   r   r   r   obj_types        r   r   r     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r   c                     t                      \  }}t          ||          }t          ||          }dD ]}t          | ||||           d S )Nr  )rp  r  r   r  r  s        r   r   r   ,  se      DAq!.!44A!.!44A5 Q Q*4AxPPPPQ Qr   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   r<   Fr  zDpandas is not installed: not checking estimators for pandas objects.r  r  )ru   rB   r   rN   r   r  r  r   r  r-  r  r0  r/  r1  r   r   rE   )r   r   r   r   r  estimator_1estimator_2r  X_r2  r  r  s               r   r  r  5  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                 ,   |j         }t          t                    5  t          |          }t	          |           t          |           |                                |u sJ t          |j        d|j                  }	 d fdt          |          j
                                        D             }n## t          t          f$ r Y d d d            d S w xY w|                                }|t          t          |dg                     d          }|D ]}|j        |j        k    s(J d|j        dt'          |          j        d            t*          t,          t.          t0          t2          t'          d           t&          h}|                    t6          j                                                   t'          |j                  |v pt;          |j                  }|sWJ d	|j         d
|j         dt'          |j                  j         d|j         dt=          d |D                        d            |j        |                                vr$|j        J d|j         d
|j         d            b||j                 }	tA          |	t6          j!                  rtE          |	|j                   d|j         d}
tG          |	          r|	|j        u s
J |
            |	|j        k    s
J |
            	 d d d            d S # 1 swxY w Y   d S )Nr   rh  c                 X    | j         dk    o| j        | j        k    o| j        | j        k    S )z*Identify hyper parameters of an estimator.r  )r   r^   VAR_KEYWORDVAR_POSITIONAL)r  s    r   param_filterz<check_parameters_default_constructible.<locals>.param_filter}  s6     Ff$ 3!-/3!"22r   c                 *    g | ]} |          |S r  r  )r  r  r  s     r   r  z:check_parameters_default_constructible.<locals>.<listcomp>  s6       ,,q//  r   r*  z
parameter rG  z has no default valuez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 rS  )rg   )r  rT  s     r   rV  z9check_parameters_default_constructible.<locals>.<genexpr>  s$      ??t}??????r   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.)$rf   rL   r  r:  r   reprr  r4  r  r   r  r  r\  r   r   r5  defaultr  r   rT  rg   r%  r@  r  r  r{  updater   
sctypeDictcallabler  r   r  r  rH   r>   )r   r7  r   initr  r  
init_paramallowed_typesallowed_valueparam_valuefailure_textr  s              @r   r  r  d  so    #I	-	0	0	0 `K `K'	22	iY##%%2222 y)+@)BTUU	     $T??5<<>>  KK :& 	 	 	 E`K `K `K `K `K `K `K `K>	 %%''!#gi9OQS&T&T"U"U"W"WX% 9	K 9	KJ"j&66666Y((( 766 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<<<<s9	KO`K `K `K `K `K `K `K `K `K `K `K `K `K `K `K `K `K `Ks7   A!L	 5B65L	6CL	CH%L		LLc                 `   t          | d          r'|dt          |                                          z   z  }t          | d          r>|j        dk    r3t	          j        ||j        d         k    ||j        d         dz             }t          | d          rt	          j        |d          S |S )Nrequires_positive_yr   r<   r  r   r   )r5  r<   )rA   r  r  r   r   whereflatr6  )r   r   s     r   r   r     s     )!6777  	
QQUUWW)/// 7AFQJJHQ!&)^Qq	A66 )!3444 &z!W%%%Hr   c                 N   dt          | d          v r|d d df         }t          | d          r||                                z
  }dt          | d          v ret          | d          rt          j        nt          j        }t          j        ||                                z
                                |          }| j        j        dk    r||                                z
  }t          |           rt          |d	
          }nt          | d          r |||          }|S )N1darrayr   r   r   r   categoricalrc   SkewedChi2Sampler	euclidean)r  r\   )rA   r  r   r  r  r   r  rf   rg   r  r(   )r   r   r  r  s       r   r  r    s(    Jyi88888aaadG )!6777 K
9)<<<<<(DDDR

"(Ha!%%''k##**511#':::K 9%% q555	I:	.	.	. F1aLLHr   c                    g d}|t           z  }| |v rd S | dk    r$t          |                              d          }nt          |          }t          |d          rt	                      }|j        |j        }}t          ||          }t          |d           t          ||          }|
                    ||           t          j        |j        dk              sJ d S d S )N)r"   RidgeClassifierr   r   rz  r    r  	LassoLarsrN  r  rw  r   r<   )ru   r   r  rz   r   r  targetr   rN   r  r   r   alln_iter_)r   r   not_run_check_n_iterr   irisr   r  s          r   r   r     s      //### {.))4434??		.))	y*%% .{{	4;2&y"55A&&&%na88avi'1,-----. . 	.-r   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 )Nrw  )rN  rN  r  )r  rN  rN  )       @r  r  )r  rf  g      @r  gɿg?g?g      g333333?r8  r  r  r   r   r  r<   )r   rz   ru   r   r  rN   r   r  )r   r   r   r   r  iter_s         r   r   r   "  s9    n%%Iy*%% *&&& ///???OOOTA+SzC;dDBB "III.  EAr *.!<<AA&&&a &&&"* " "zzzzz" " $))))/* *. *)r   c                     t          |          }|                    d          }|                    d          t          fd|                                D                       sJ d S )NFdeepTc              3   D   K   | ]}|                                 v V  d S rS  )r"  )r  itemdeep_paramss     r   rV  z.check_get_params_invariance.<locals>.<genexpr>I  s4      NNtt{((***NNNNNNr   )r   r   r  r"  )r   r   r  shallow_paramsr
  s       @r   r
  r
  A  ss     	nA\\u\--N,,D,))KNNNN~7K7K7M7MNNNNNNNNNNr   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 {}r  )r   r   r  r  r   r"  r   r   r   r\  r   rf   rg   r  r  r  r"  )r   r   r   orig_paramsr9  curr_paramsr  r  test_valuestest_paramsr  default_valuer   r  e_typechange_warning_msgparams_before_exceptions                    r   r  r  L  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}t          |d          sGt	          t
          |          5  |                    ||           d d d            d S # 1 swxY w Y   d S d S )NzUnknown label type: rb   r   rU  )rp  r  r   rA   rM   r   r   )r   r   r   r   r  r9  s         r   r   r     s       DAq!.!44AnA
 Ca_--- Jc*** 	 	EE!QKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 s   A>>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)ri  r-  rj  r  r  r=   皙?r  r  r  r<   r   )decimalsc                 L    g | ] }|k                                              !S r  )r  )r  groupb
rank_probas     r   r  z4check_decision_proba_consistency.<locals>.<listcomp>  s/    RRR5:&',,..RRRr   )r   r+   r   rz   r   r  r   r  r   rG   r"  r   r.  r  r3  rH   r9  r5  )r   r   r  r   r   r  r  rZ  rh  r   a
rank_scoregrouped_y_score
sorted_idxr  r  s                 @@r   r   r     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  r5  r<   r   r   r8  rE  r  )r   r=   r  r   rN   r   r  r^   rH   r   r  r.  rz   r   r   r  r  r1  r  rB  )r   r   ri  r   rd  rj  r   r  y_pred_2r>  r   r=  r  s                r   r   r     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 -,,,r   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  r<   r   )r   r.  r   rM   r   r   r  s        r   r  r    s     	4)dAY'((A
!QAn%%I	
		  a                 s   A88A<?A<c           
         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          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r%  r  r   locr   r   rY  r  r  c                 d    i | ],}t          |          | t          |                    -S r  )rz   r4  )r  r  r  r   s     r   r  z(check_fit_idempotent.<locals>.<dictcomp>  sP       9f%%*	6**622  r   r  r  z&Idempotency check failed for method {})r  rtolr   )r   r   r   r   rN   r   r   r  r  r  r   r\  r   nextr*   splitr,   r   rz   r4  
issubdtyper  floatingfinfoepsr  rF   maxr  )r   r   r  r   ri  r   r   traintestr  rZ  rh  r  r  
new_resulttolr  r   s                   @@r   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}Z-r{;; 3"(:#34488"(2:..22(vd^^d^^@GGOO    r   c                    t           j                            d          }t          |          }t	          |           d|                                v r|                    d           d}|                    d|df          }t          ||          }t          |          r|                    |          }n|
                    d	d|
          }t          ||          }t          |                              dd          s<	 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)Nrh  r%  Fr&  r  r   r'  r   r   rY  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   rN   r   r  r  r  r   r\  r   rA   getrT   r"  rf   rg   r   r   )r   r   r   r   ri  r   r   r  s           r   r  r  /  s    )


#
#Cn%%IYy++----...I

s)Q
00A!)Q//AN## 7JJIJ&&KKAAIK66!)Q//Ai  $$[%88 		I&&& &/       	 	 	D	MM!Q	"""""   T
 
	s*   +D2 2
D?>D?E* *
F	4FF	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   r%  Fr&  r  r   r'  r   rY  n_features_in_r<   )r   r   r   r   rN   r   r  r  r  r   r\  r   rz   r   r9  r  )r   r   r   r   ri  r   r   s          r   r  r  V  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1r   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   r'  )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 rS  rz  )r  r9  ves     r   rV  z(check_requires_y_none.<locals>.<genexpr>  s-      ??c3#b''>??????r   )
r   r   r   r   rN   r  r  r   r   r[  )r   r   r   r   ri  r   expected_err_msgsr<  s          @r   r  r  p  s     )


"
"Cn%%IYI

s)Q
00A!)Q//Aa   ????->????? 	H	 	 	 	 	 	s   -B 
B7B22B7c                 N   t          |          }d|d         v p	d|d         v }|r|d         rd S t          j                            d          }t	          |          }t          |           d|                                v r|                    d           d	}|                    |d
f          }t          ||          }t          |          r|                    |          }n|                    dd|          }t          ||          }|                    ||           |j        |j        d         k    sJ g d}	|d d dgf         }
d|j        d          d}|	D ]s}t!          ||          st#          ||          }|dk    rt%          ||          }t'          t(          |          5   ||
           d d d            n# 1 swxY w Y   tt!          |d          sd S t	          |          }t+          |          r+|                    ||t          j        |                     n|                    ||           |j        |j        d         k    sJ t'          t(          |          5  |                    |
|           d d d            d S # 1 swxY w Y   d S )Nr   r   r  rb   r   r%  Fr&  r   r  r   r   rY  r<   )r   r   r  r  r  z'X has 1 features, but \w+ is expecting z features as inputr  r  rU  r  r  )rA   r   r   r   r   rN   r   r  r  r  r   r\  r   r   r9  r  rz   r4  r   rM   r   r   r  r  )r   r   r   is_supported_X_typesr   r   ri  r   r   r  X_badr9  r  callable_methods                 r   !check_n_features_in_after_fittingrB    sm    n%%D 	T)_$Hi(H    4#8 
)


"
"Cn%%IYy++----...I

A
''A!)Q//AI 7JJIJ&&KKAAIK66!)Q//AMM!Q#qwqz1111  M aaa!fIE
SQWQZ
S
S
SC 	# 	#y&)) 	!)V44W%o;;;OJc*** 	# 	#OE"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 9m,, n%%IY $aBIaLL9999a####qwqz1111	
#	&	&	& ( (eQ'''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s$   3GG	G	6JJ!Jc                 j   t          |          }t          |d          sd S t          |                                                                          }t          t          j                              }|                    |          |k    s%J |  d||                    |          z
               d S )N	_get_tagsz@._get_tags() is missing entries for the following default tags: )r   rz   r  rD  r   r@   intersection)r   r   r   	tags_keysdefault_tags_keyss        r   r   r     s     n%%I9k** I''))..0011IM.0011!!"3448IIII 	M 	M!7!78I!J!JJ	M 	M JIIIIr   c           	      	   	 dd l }n# t          $ r t          d          w xY wt          |          }d|d         v p	d|d         v }|r|d         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t*          d           |                    ||           d d d            n# 1 swxY w Y   t/          |d          st1          d          t3          |j        t          j                  sJ |j        j        t:          k    sJ t=          |j        |
           |j        }|                     d          r5d|v s1|!                    d          sd|j"        vrt1          d|  d          g }dD ]Q}t/          ||          stG          ||          }|dk    rtI          ||          }|%                    ||f           R|D ]X\  }}t%          j                    5  t%          j        ddt*          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!tM          |
d d                     d"fg}d# |'                                (                                D             }tS          d$ |*                                D                       }|D ]2\  }}|                    ||d
          }tW          j,        d%|           }|D ]B\  } }t[          t0          ||  d&'          5   ||           d d d            n# 1 swxY w Y   Ct/          |d(          r|rt          |          }t]          |          r-t	          j/        |          }|0                    |||)           n|0                    ||           t[          t0          |*          5  |0                    ||           d d d            n# 1 swxY w Y   4d S )+Nr   Hpandas is not installed: not checking column name consistency for pandasr   r   r  rb   )   r.  r   c                     g | ]}d | S )col_r  r  r  s     r   r  z<check_dataframe_column_names_consistency.<locals>.<listcomp>  s    <<<QjQjj<<<r   Fcolumnsr  r   rY  errorz#X does not have valid feature namessklearn)messager   modulefeature_names_in_zTEstimator does not have a feature_names_in_ attribute after fitting with a dataframer   r   r   r   z2 does not document its feature_names_in_ attribute)r   r   r  r  r  r  r  r  r  r5  z<Feature names must be in the same order as they were in fit.c                     g | ]}d | S )another_prefix_r  rM  s     r   r  z<check_dataframe_column_names_consistency.<locals>.<listcomp>>  s!    >>>q"q"">>>r   zHFeature names unseen at fit time:
- another_prefix_0
- another_prefix_1
r1  z3Feature names seen at fit time, yet now missing:
- 
c                 "    i | ]\  }}d |v 	||S )early_stoppingr  r  s      r   r  z<check_dataframe_column_names_consistency.<locals>.<dictcomp>I  s3       Cs"" 	U"""r   c              3      K   | ]}|d u V  	dS )TNr  )r  r   s     r   rV  z;check_dataframe_column_names_consistency.<locals>.<genexpr>N  s&       L L5$ L L L L L Lr   zBThe feature names should match those that were passed during fit.
z did not raiser   r  r  rU  )1r-  r1  rB   rA   r   r   r   r   rN   r  r  r  r.  r  r/  r   r\  r   r  r  filterwarningsUserWarningr   rz   r   r  rT  r  r  rV  rH   r   r   r   r  r4  r   r/  r  r   r"  r[  r  r#  escaperM   r   r  r  )r   r   r2  r   r?  r   r   X_origri  rj  namesr   r   r   r  r  rA  rd  invalid_namesr  early_stopping_enabledinvalid_nameadditional_messager@  expected_msgr  s                             r   (check_dataframe_column_names_consistencyre    s   
 
 
 
V
 
 	


 n%%DT)_$Hi(H    4#8 
)


"
"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	P44P8;P8
S--S1	4S1	c                    |                                 }d|d         vs|d         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!          |t*                    r|d         j        d         }n|j        d         }t-          |
          |k    sJ d| dt-          |
                       d S )Nr   r   rb   r8  r  r  r   r   r  r  r<   r  c                     g | ]}d | S )featurer  rM  s     r   r  z;check_transformer_get_feature_names_out.<locals>.<listcomp>  s    ???mmm???r   z'input_features should have length equalrU  c              3   @   K   | ]}t          |t                    V  d S rS  )r  r%  )r  r   s     r   rV  z:check_transformer_get_feature_names_out.<locals>.<genexpr>  s,      CCz$$$CCCCCCr   	Expected  feature names, got )rD  r   r.   ro  r   r  r  rN   ru   r   r  r  r  rM   r   rq  r  r  r  rV  r  r{  r5  )r   r  r   r   r   r   rj  r  X_transforminput_featuresfeature_names_outn_features_outs               r   'check_transformer_get_feature_names_outrp  m  s   %%''DY''4+@'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/2E/c                    	 dd l }n# t          $ r t          d          w xY w|                                }d|d         vs|d         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)          ||           t+          |t,                    r|d         j	        d         }n|j	        d         }t/          |          |k    sJ d| dt/          |                       d S )Nr   rI  r   r   rb   r8  r  r  r   r  r  r<   c                     g | ]}d | S r  r  rM  s     r   r  zBcheck_transformer_get_feature_names_out_pandas.<locals>.<listcomp>      ===a	a		===r   FrN  r  c                     g | ]}d | S )badr  rM  s     r   r  zBcheck_transformer_get_feature_names_out_pandas.<locals>.<listcomp>  s    BBB1Y1YYBBBr   z0input_features is not equal to feature_names_in_rU  rj  rk  )r-  r1  rB   rD  r   r.   ro  r   r  r  rN   ru   r   r  r  r  r/  rM   r   rq  rH   r  r{  r5  )r   r  r2  r   r   r   r   rj  r  feature_names_indfrl  invalid_feature_namesfeature_names_out_defaultfeature_names_in_explicit_namesro  s                   r   .check_transformer_get_feature_names_out_pandasr|    s    
 
 
 
V
 
 	


 %%''DY''4+@'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    !F66F:=F:c                 |   t           j                            d          }|                    d          }|                    ddd          }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  t          d t%          |d          D                       r t'          ||          |           n t'          ||          ||           d d d            n# 1 swxY w Y   d |D             }|D ]}	 t)          |          }n# t*          $ r Y w xY w |j        di ||i |D ]}t          ||          s|  d| d}	t!          t"          ||	          5  t          d  t%          |d          D                       r t'          ||          |           n t'          ||          ||           d d d            n# 1 swxY w Y   ܐ#d S )!Nr   r  r   r   rg  Fr  z>Mismatch between _parameter_constraints and the parameters of z%.
Consider the unexpected parameters z% and expected but missing parameters BadTyper  )r   r  ro  r   rb   c              3   `   K   | ])}t          |t                    o|j        t          k    V  *d S rS  )r  r?   rT  r	   r  rT  s     r   rV  z)check_param_validation.<locals>.<genexpr>  sL       
 
 z8,,LH1L
 
 
 
 
 
r   c              3   `   K   | ])}t          |t                    o|j        t          k    V  *d S rS  )r  r?   rT  r
   r  s     r   rV  z)check_param_validation.<locals>.<genexpr>  sL       
 
 z8,,HD1H
 
 
 
 
 
r   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              3   j   K   | ].}t          |t                    o|                    d           V  /dS r  N)r  r%  r   r  X_types     r   rV  z)check_param_validation.<locals>.<genexpr>  sQ         vs++I0I0I     r   r   r   c                 ,    g | ]}t          |          S r  )r;   r  s     r   r  z*check_param_validation.<locals>.<listcomp>)  s     QQQzz22QQQr   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.c              3   @   K   | ]}|                     d           V  dS r  )r   r  s     r   rV  z)check_param_validation.<locals>.<genexpr>C  sB        " 11     r   )r   r   r   r  r\  r   r   r   rK  r  rT  r[  r   r   r  rz   rM   r9   rA   r4  r:   r  )r   r   r   r   r   estimator_paramsvalidation_paramsunexpected_paramsmissing_paramsr   param_with_bad_typefit_methodsr  constraintsr   r   r  rT  	bad_values                      r   check_param_validationr    sg    )


"
"C!!AAqr""A!.!44A%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& Y9 Y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  ",YI"F"F"F     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  &0	&J&J&J     9
 3	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	9uY9 Y9s8   AIII!I11
I>=I>AL-	-L14L1c                     |                                 }d|d         vs|d         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   rb   r   r  r   r   rg  c                     t           v r*|                                                             S |                                                             S rS  )ru   r   r   )rU  r   r   r   s    r   fit_then_transformz6check_set_output_transform.<locals>.fit_then_transform]  sQ    &&&771a==**1a000wwq!}}&&q)))r   c                 0    |                                S rS  )ro  )rU  r   r   s    r   ro  z1check_set_output_transform.<locals>.fit_transformb  s      A&&&r   )r   ro  r  r   )rD  r   r   r   r   r  r  r\  r   rN   r"  rz   ru   
set_outputrF   )r   r  r   r   r   r  ro  transform_methodstransform_methodX_trans_no_settingX_trans_defaultr   r   s   `          @@r   check_set_output_transformr  M  s    %%''DY''4+@'
)


"
"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r   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 rS  )rz   )r  methr   s     r   rV  z-_output_from_fit_transform.<locals>.<genexpr>  s-      
G
G$7;%%
G
G
G
G
G
Gr   )r   r   zfit_transform/dfzfit_transform/arrayro  )r  r   ru   r   rq  rz   ro  )r   r   r   rx  r   outputscasescasedata_fitdata_transformr  rd  r  s   `            r   _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Nr   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.
    rx  NrO  indexz, 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_dataframer  s                  r   _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                ~   |                                 }d|d         vs|d         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(...)`
    r   r   rb   Nr   r  r   r   rg  c                     g | ]}d | S rs  r  rM  s     r   r  z9_check_set_output_transform_dataframe.<locals>.<listcomp>  rt  r   r<   c                     g | ]}d | S )r  r  rM  s     r   r  z9_check_set_output_transform_dataframe.<locals>.<listcomp>  s    444Q[Q[[444r   r  r  r  local)transform_outputz% output does not support sparse data.z.The transformer outputs a scipy sparse matrix.)rD  r   r   r   r   r  r  r\  r   rN   r  r  r  r  r   r   r   
capitalizer%  r  )r   r  dataframe_libr  r  r  contextr   r   r   r   r   rw  r  rx  transformer_defaultr  transformer_dfcontext_to_use
outputs_dfr  capitalized_liberror_messager  s                           r   %_check_set_output_transform_dataframer    s   J %%''DY''4+@'
)


"
"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 F:.G :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 rS  r  r/  )r   r2  s    r   rx  z<_check_set_output_transform_pandas_context.<locals>.<lambda>K      Ar|)D)D r   c                 6                         | |d|          S )NF)rO  r  r  )r/  )r   rO  r  r2  s      r   rx  z<_check_set_output_transform_pandas_context.<locals>.<lambda>L  s$    2<<wU% 4@ 4
 4
 r   r  r  r  r  r  )r-  r1  rB   r  testingr  )r   r  r  r2  s      @r   *_check_set_output_transform_pandas_contextr  A  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     r   !check_set_output_transform_pandasr  T      .t5EwOOOOOr   c                 (    t          | |d           d S Nglobalr  r  s     r   $check_global_output_transform_pandasr  X      .t5ExPPPPPr   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)r  r   r  r  r/  )r   rO  r  pls      r   r  zD_check_set_output_transform_polars_context.<locals>.create_dataframec  s>    grz** 	'nn&&G||Age|<<<r   polarsc                 .    t          | j                  S rS  r  )r   r  s    r   rx  z<_check_set_output_transform_polars_context.<locals>.<lambda>m  r  r   r  )r  polars.testingr  r1  rB   r  )r   r  r  r  r  r  s        @r   *_check_set_output_transform_polars_contextr  \  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     r   !check_set_output_transform_polarsr  t  r  r   c                 (    t          | |d           d S r  r  r  s     r   (check_global_set_output_transform_polarsr  x  r  r   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  r1  )ri  rj  r-  )Lasso
ElasticNetMultiTaskElasticNetMultiTaskLassomissing_valuesrT  r   r   rY  F)writer   N)r   r   r   r   rN   r   r  asfortranarrayrz   r   r   r  r\  r   r  setflagsr   r   flags	writeablerE   )	r   r   r   r   ri  r   rd  r   X_copys	            r   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r   )NF)Nr  F)Nr  )r]   )F)Fr  )T)r  r  r#  r  
contextlibr   r  r   	functoolsr   r   inspectr   r   numbersr	   r
   r  numpyr   scipyr   scipy.statsr   r  r   baser   r   r   r   r   r   datasetsr   r   r   r   r   
exceptionsr   r   r   feature_selectionr   r   linear_modelr   r    r!   r"   r#   metricsr$   r%   r&   metrics.pairwiser'   r(   r)   model_selectionr*   r+   model_selection._validationr,   r  r-   preprocessingr.   r/   random_projectionr0   treer1   r2   utils._array_apir3   r4   r5   r6   r8   r  utils._param_validationr9   r:   r;   r=   _missingr>   _param_validationr?   _tagsr@   rA   r   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   fixesrO   rP   rQ   rR   
validationrS   rT   rU   rn  ru   r   r   r  r   r   r   r   r   r   r  r(  r:  rD  rM  r>  r^  rc  rp  r  r  r  r  r   r  r#  r}   r|   rk   rl   rm   rn   rp   ro   r\  rs   rr   r  rf  r  r  r  r  r  r  r	  r  r   r   r   r   r  rv   rj   ri   r   rt   rw   rx   r~   r   r   r   r   r   r   r   r   rB  r   r   r   r   r   r   rr  rq   r   r   r  r  r   r   r  r   r   r   r  r  ry   rh   r{   r   r   r  r  r   r  r   r   r
  r  r   r   r   r  r  r  r  r  rB  r   re  rp  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   <module>r
     s   W W  				  " " " " " "       $ $ $ $ $ $ $ $ ) ) ) ) ) ) ) ) " " " " " " " "                                                          P O O O O O O O O O < < < < < < < <              D C C C C C C C C C L L L L L L L L L L < < < < < < < < 5 5 5 5 5 5 $ $ $ $ $ $ 1 1 1 1 1 1 1 1 4 4 4 4 4 4 @ @ @ @ @ @ @ @            6 5 5 5 5 5         
       # # # # # # ' ' ' ' ' '                                     M L L L L L L L L L L L H H H H H H H H H H HHH 7 7 7t!+ !+ !+H -(((    )( D2 2 22' ' '>
6 
6 
62 2 2*
 
 
6% 6% 6%r!/ !/ !/H, , ,^
V 
V 
V  *? ? ? ; ; ;|N; N; N; N;b   x, x, x,vW W W W W W W W*) ) )$' ' 'J LI LI LI LIf    "3; 3; 3;lO O OR R R
 -((((
 (
 )((
V =***/ / +*/8 =***5 5 +*5 -(((!@ !@ )(!@H -(((AL AL AL )(ALH%P %P %PP =+6777! ! 87!H   $ $ $N< < < -(((5 5 )(5p -(((  )(0< < <$ -(((!R !R )(!RH -(((( ( )((V % % %P   <   $ -(((0 0 0 )(0" -(((B B )(B" -(((! ! )(!  -(((* * )(*X1 X1 X1v > > >@   : 4 4 4,  @ -(((" " )(". -(((-1 -1 )(-1`    2G 2G 2G 2Gj -(((, , )(,8 -(((9N 9N )(9Nx -(((  )(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 )(%6P -((() ) )()X -(((P
 P
 )(P
f -(((* * )(*Z -(((* * )(* -(((, , , )(, . . .( -(((7 7 )(7D = = =@  M M MD -(((; ; )(;6 -(((*//, /, /, )(/,d 1 1 1  -((()/ )/ )()/X -(((  )(* -(((% % )(%P -(((
 
 )(
B -(((" " )("J -(((( ( )((D -(((Q Q )(Q0 -(((Q Q )(Q -(((+; +; )(+;\fK fK fKR    4A    4 -((('. '. )('.T -(((* * )(*< -(((O O )(O -(((50 50 )(50p -(((
 
 )(
 -((()G )G )()GX(P (P (PV  7 7 7t$ $ $N2 2 24  4 -(((A( A( )(A(H  L, L, L,^-P -P -P`6X 6X 6Xrt9 t9 t9n-J -J -J`* * *Z: : :zW
 W
 W
t  &P P PQ Q Q  0P P PQ Q Q -(((* * )(* * *r   