
    {Kg                    
   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? Zd@ ZdA Z eiey'      dB        Z eiey'      dC        Z eiey'      dD        Z eiey'      dE        Z eiey'      ddF       ZdG Z eieyef'      dH        ZdI ZeidJ        ZdK Z eiey'      dL        Z eiey'      dM        ZdN Z eiey'      dO        Z eiey'      dP        ZeidQ        ZeidR        ZeidS        Z eiey'      ddT       Z eiey'      dU        Z eiey'      dV        Z eiey'      dW        ZdX ZeidY        ZeidZ        Zeid[        Zd\ Z eiey'      d]        Z eiey'      d^        Zeid_        Zeidd`       Z eiey'      da        Z eiey'      db        Z eiey'      dc        Z eiey'      ddd       Z eiey'      de        Z eiey'      df        Z eiey'      dg        Zei	 ddh       Zdi ZddjZdk Z eiey'      dl        Z eiey'      dm        Z eiey'      dn        Z eiey'      do        Z eiey'      dp        Z eiey'      ddq       Zeidr        Z eiey'      ds        Zeidt        Zdu Zdv Z eiey'      dw        Z eiey'      d5ej                  fdx       Zeidy        Z eiey'      dz        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        Zy)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         t         t
         t        | d      rSt         t         t         |d   s6t         t         t        t        d       t        t        d       t         t        t        d       |d   st         t          t"         |t$        vrt&         |d	   s|d   st(         |d   rt*         t,         t/        | d
      rt0         t2         t4         t6         t        t6        d       t8         |d   rt;        |       D ]  }|  y y w)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       b/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/sklearn/utils/estimator_checks.py_yield_checksr   [   sA    ''Di D
))
!!
!!O400//''J,,669GG9HH
++
3T
JJ      22&&((T/%:&&J##
++y*%))
&&
'' "!
)4
@@
// ,Y7EK 8 !s   E*E,c              #     K   t        |       }t         t         t         t         t
         |d   rt         t         t        t        d       t        t        dd       t         |d   r t         t         t         t         |d   st         |d   st         |d	   rt          d
| j#                         j%                         v rt&         t(         t*         y w)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
##
11M**
!!
)4
@@
)4
SS
--LDD@@FFJJ ''&'''N''..05577,,
11
**s   C=C?categoryc                 &   t        |      }t        j                  j                  d      }|j	                  d      }t        j
                  t        j                  fD ]  }t        j                  d|      }t        ||      }|j                  }|j                  d      r0d|v s,|j                  d      st        j                  |      rd}nd	}nd }d
|  d}	t        t        ||	      5  |j                  ||       d d d         y # 1 sw Y   xY w)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&&"&&!GGB%i3**!!*-{"k&:&::&F xx, 
 5 E   	 JeW=MM!Q >=1 "0 >=s   )DD	c              #   n  K   t        |       }t         t        t        d       t        t        dd       t         t         |d   rt
         t         |d   s|d   st         t         | j                  j                  }|dk7  rt         |d	   rt         t         y w)
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
++
11M))
// .@)A##
##''Du}""N''
11s   B3B5c              #     K   t        |       }|d   st         t         |d   rt         t	        t        d       t        | d      s	t
         nt         g d}| j                  j                  }||vr	t         y y w)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  11
##//
+T
BBk{3))33O   ))D?"&& #s   BB	c              #      K   t          | j                  j                  }|dvr#t         t	        t        d       t
         t        | d      s	t         y y w)N)WardAgglomerationFeatureAgglomerationTr`   	transform)&check_clusterer_compute_labels_predictrf   rg   check_clusteringr   r   rz   r   )	clustererr   s     r   _yield_clustering_checksr     sW     
00''D@@ &==559k*55 +s   AAc              #      K   t        | d      rt         t        | d      rt         t        | d      r8t         t	        t        d       t
         t        | d      rt         t         y w)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   !  sd     y/*)) y-((( y)$""*DAA00i^4++
11s   A6A8c              #   \   K   t               D ]  \  }}}t        t        |||        y w)N)array_namespace
dtype_namer8   )r6   r   check_array_api_input)r   r   r8   r   s       r   r   r   6  s:     
 
3	4		!+!	
 	
 
5s   *,c              #     K   | j                   j                  }t        |       }d|d   vr.t        j                  dj                  ||d         t               y |d   r*t        j                  dj                  |      t               y t        |       D ]  }|  t        |       rt        |       D ]  }|  t        |       rt        |       D ]  }|  t        | d      rt        |       D ]  }|  t        | t              rt!        |       D ]  }|  t#        |       rt%        |       D ]  }|  t&         |d   st(         t*         t,         t.         t0         t2         t4         t6         t8         t:         |d   s%t<         t>         t@         |d	   rtB         |d
   r	tD         y y w)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	
 	y) *Y-i8EK 9I,Y7EK 8y+&.y9EK :)\*-i8EK 99%+I6EK 7
00#$33--


%%


))

## !!##''!"$$ #s   GGc           
      "   t        |       r| j                  S t        | t              r| j                  s| j
                  j                  S dj                  | j                  j                         D cg c]  \  }}dj                  ||       c}}      }dj                  | j
                  j                  |      S t        | d      r6t        d      5  t        j                  ddt        |             cd	d	d	       S y	c c}}w # 1 sw Y   y	xY w)
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
    ,z{}={}z{}({})r   T)print_changed_onlyz\s N)r   rg   r  r   keywordsfuncjoinitemsr  rz   r   resubstr)objkvkwstrings       r   _get_check_estimator_idsr$  }  s    0 #||#w||88$$$88cll>P>P>RS>RdaW^^Aq1>RSTsxx00(;;sL!t466%SX. 54 " T 54s   2C?
 DDc                    t        | dg       }t        |      r|dgdgfv r|t        | t              r | t	                     }|S t        | t
              r | t                     }|S t        | t              r | t        d            }|S  | t        d            }|S |dgfv r^t        | t
              r' | d	t        d
d      fdt        d
d      fg      }|S  | d	t        d
d      fdt        d
d      fg      }|S 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_instancer6    s   !)-CRH
K=3C2D"EE
 )_5%&6&89	D C I~6%eg.	@ ? I7%l&BC	: 7 &&81&=>	6 5 !l^$55)^4%!6QR!ST!6QR!ST 	. ! &!7!RS!TU!7!RS!TU 	   /y/A/A.B C124 
 MM#/3-K	    c                     t        | |      \  }}|s| |fS |j                  | ||j                  j                  |            S )N)reason)marks)_should_be_skipped_or_markedparammarkxfail)r   r   pytestshould_be_markedr9  s        r   _maybe_mark_xfailrA    sK      <IuMf%||IuFKK4E4EV4E4T|UUr7  c                      t         |      \  }|s|S t        |t              r|j                  j                  n|j                  t        |       fd       }|S )Nc                  T    t        d dj                  j                   d       )Nz	Skipping  for z: )rB   rf   rg   )argskwargs
check_namer   r9  s     r   wrappedz_maybe_skip.<locals>.wrapped  s3    
|5)<)<)E)E(FbQ
 	
r7  )r;  r  r   r  rg   r   )r   r   should_be_skippedrH  rG  r9  s   `   @@r   _maybe_skiprJ    sZ     !=Y Nv(25'(B$$J
5\
 

 Nr7  c                     t        |t              r|j                  j                  n|j                  }t	        | d      xs i }||v rd||   fS y)N_xfail_checksr   T)Fz*placeholder reason that will never be used)r  r   r  rg   rA   )r   r   rG  xfail_checkss       r   r;  r;    sN     )35'(B$$Ji_=CL\!\*--->r7  c                      ddl t        d  D              rd}t        |       fd}j                  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                y wN)r  type).0ests     r   	<genexpr>z*parametrize_with_checks.<locals>.<genexpr>,  s     
7JS:c4 J   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 ]B  } t        |       j                  }t        |       D ]  }t        ||      }t	        | |        D y wrP  )rQ  rg   r  r   rA  )r   r   r   r+  r?  s      r   checks_generatorz1parametrize_with_checks.<locals>.checks_generator4  sJ     #I	?++D*95t,'	5&AA 6 $s   A	Azestimator, check)ids)r?  any	TypeErrorr=  parametrizer$  )r+  r5  rX  r?  s   `  @r   parametrize_with_checksr]    s]    P 

7J
77/ 	
 nB ;;"",.4L #  r7  Fc                 ,    t         t              rd}t        |      t               j                   fd}|r |       S  |       D ]  \   }	  |         y# t        $ r-}t        j                  t        |      t               Y d}~Cd}~ww xY w)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 ...>
    rV  c               3   f   K   t              D ]  } t        |       } t        |       f   y wrP  )r  rJ  r   )r   r   r   s    r   rX  z)check_estimator.<locals>.checks_generator  s4     &y1E	51EWUD111 2s   .1N)	r  rQ  r[  rg   rB   r   r  r  r   )r   generate_onlyr5  rX  r   	exceptionr   s   `     @r   check_estimatorrb  @  s    l )T"/ 	
 n	?##D2
 !!,.	5	;) /  	; MM#i./::	;s   A	B&#BBc                  |    t         1t        dddddd      \  } }t               j                  |       } | |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_datasetro    sM    !
1 **1-Tr7  c                 4   | j                         }| j                  j                  }|dk(  r| j                  d       d|v r|dk7  r| j                  d       d|v r| j                  &| j                  t        d| j                               |d	v r| j                  d
       |dk(  r| j                  d       |dk(  r| j                  d
d       | j                  j                  dk(  r| j                  d
d       |dv r| j                  d       |dk(  r| j                  d       d|v r| j                  d       d|v r&| j                  t        d| j                               d|v r| j                  d       d|v r| j                  d       d|v r#|j                  d       s| j                  d!       |d"k(  r| j                  d#$       |d%k(  rd&| _        |d'k(  r| j                  d#(       t        | d)      rt        | j                  d      | _
        t        | d*      rd&| _        |d+k(  r| j                  d,-       |d.k(  rd| _        t        | t              r| j                  d/       t        | t              r| j                  d&0       |d1v r| j                  d2       |d3k(  r| j                  d45       d6d7g}||vrt        | d8      r| j                  d9:       t        | d;      r| j                  d9<       |d=k(  r| j                  d>?       |d@k(  r(t         t#        dA      k\  rdBndC}| j                  |D       |t$        v r| j                  d&/       |dEk(  r| j                  dFG       |dHk(  r| j                  d&I       y y )JNTSNEr   
perplexityn_iterr   rt  max_iterrv  )	LinearSVR	LinearSVCrf  NMFi  DictionaryLearning
lasso_lars)rv  transform_algorithmMiniBatchNMFT)rv  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cvr-  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_paramsrv  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dfnA&V)  #a1C1C*D E--  " -5=  # .''  ", O''>9  "T B44  # .00  ! ,!,#a1G1G*HIv+6A&vdooe&<+{ 	s+~ "#	} 	C0y,'"9#7#7;	y(#	{3'""&)	#)12
 	!,)[) 	q!RR 	a0   	l3 ,-F6gi6"y*%a(H5""&-*@@FVF+""!, ""t,y+ r7  c                   $    e Zd ZdZd ZddZd Zy)_NotAnArrayzvAn object that is convertible to an array.

    Parameters
    ----------
    data : array-like
        The data.
    c                 8    t        j                  |      | _        y rP  )r   asarraydata)selfr  s     r   __init__z_NotAnArray.__init__%  s    JJt$	r7  Nc                     | j                   S rP  )r  )r  dtypecopys      r   	__array__z_NotAnArray.__array__(  s    yyr7  c                 j    |j                   dk(  ryt        dj                  |j                               )Nmay_share_memoryTz%Don't want to call array_function {}!)rg   r[  r  )r  r  typesrE  rF  s        r   __array_function__z_NotAnArray.__array_function__+  s-    ==..?FFt}}UVVr7  )NN)rg   r   __qualname____doc__r  r  r   r7  r   r  r    s    %Wr7  r  c                 8    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)r0  bool)r   r  s     r   _is_pairwise_metricr  1  s"     Y$/F-'((r7  c              #     K   | j                   dk(  sJ d| j                         f dD ]  }|| j                  |      f  | j                  d      }|j                  j	                  d      |_        |j
                  j	                  d      |_        d|f dD ]\  }| j                  |      }|j                  j	                  d      |_        |j                  j	                  d      |_        |dz   |f ^ yw)	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::: D NN5!E		  )EI		  )EI
E/'NN=)II$$W-	88??7+e#Q&&	 (s   C;C=c           	      	   t        ||      }t        d      \  }}|j                  |d      }t        ||      }t	        ||      }t        |      }	|j                  ||      }
|j                  ||      }|	j                  ||       t        |	      j                         D ci c]#  \  }}t        |t        j                        s!||% }}}t        |	      }t        d      5  |j                  |
|       t        |
      d   j                  }d	d	d	       |j                         D ]  \  }}t!        ||      }t        d      5  t        |      d   j                  }d	d	d	       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(  rJ  d}|D ]  }t!        |	|d	      }||dk(  r~ |||      }t        d      5   t!        ||      |
|      }d	d	d	       t        |t.              sJ t        t.              sJ |r&t1        ||z
        t)        |j*                        k  sJ  ||      }t        d      5   t!        ||      |
      }d	d	d	       t        d      5  t              d   j                  }d	d	d	       k(  sJ d
| d| d| d       t#              t#        |
      k(  sJ t%        ||      }|r&t'        ||| dt)        |j*                               nBt3        |d      r6|j,                  |j,                  k(  sJ |j*                  |j*                  k(  sJ |dk(  st3        |	d      s|	j5                  |      }t        d      5  |j5                  |      }t        |      d   j                  }d	d	d	       |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(  rJ  y	c c}}w # 1 sw Y   xY w# 1 sw Y   RxY w# 1 sw Y   vxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w)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.
    rg  r(  Fr  r7   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  r   ndarrayr   r5   rg   r0  array_devicer4   rE   r3   r  r  floatabsrz   r  ) r   r   r   r8   r   check_valuesr  r   r   rS  X_xpy_xpr   r   array_attributesest_xpinput_ns	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	6BB/DAq	%(A!.!4A!.!4A

C::a:'D::a:'DGGAqM &*#Y__%6%6zsE*UBJJ:WU
%6   3ZF	4	0

4 &q)22 
1 +002Yvs+t4(6q9BBL 5x' 	
u@
 K."	
'
 L)\$-????+LR@%}-#AGG,	 ??o&;&;;;;??o&;&;;;;+ 30G k40>'!Aq\F488GFK8tD	 9 fe,,,i///6I-.1HHHHAYF488GFK8>	 9 t4%i03<<I 5H$ 	
x@
 K+Q 	
$
 I&,t*<<<<(r:!("EF#AGG,	 vw'|||'9'9999|||'9'9999+%'#7J*K 226:N48#)#;#;I#F $12B$CA$F$O$O! 9 %0 :V$5#6a90
   01\$5GGGG"34D"L"'R'0	 &++/B/H/HHHH%++/B/H/HHHHA [
 
1	0 54N 98 98 540 98sT   &"R	R(+R%	R27R?4SS*S&%R/2R<	?S		S	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#     !' r7  c                    t         j                  j                  d      }|j                  d      }d||dk  <   t	        ||      }d|j                  |j
                  d         z  j                  t         j                        }t        t              5  t        |      }d d d        t        |      }t        |      }t         ||            D ]Z  \  }}t        t              5  t        |      }| dv r|j                  d	       d d d        d
|v r
d|  d| d}	nd|  d}	t        t         t"        fddgd|	      5  t        t              5  |j%                  ||       d d d        t'        |d      rU|j)                  |      }
|d   r |
j
                  |j
                  d   dfk(  s!J |
j
                  |j
                  d   fk(  sJ t'        |d      rJ|j+                  |      }|d   r|j
                  d   df}n|j
                  d   df}|j
                  |k(  sJ d d d        ] y # 1 sw Y   xY w# 1 sw Y   5xY w# 1 sw Y   xY w# 1 sw Y   xY w)Nr   )(   r-  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    sE   
))


"C!AAa#gJ!.!4A	
S[[aggaj[)	)11"((;A	-	0.)	 
1!)Q/An%D1+a.Aqm4n-I33$$u$5 5
 = TF";M? K= =  TF #7 7  
#X&	
 !-8a# 9y), ((+*+::!''!*a888::!''!*666y/2!//2&,-GGAJ?(,-GGAJ?({{&::::)
 
) B	 
1	0 540 98
 
s=   H0("H=II
%B?I0H:=I	
III 	c                 :    t        | |t        j                         y rP  )r  r   
csr_matrixr   r   s     r   r}   r}   :  s    %dNF<M<MNr7  c                 H    t         rt        | |t        j                         y y rP  )rP   r  r   	csr_arrayr!  s     r   r|   r|   >  s    )$@P@PQ r7  c                    t        |      }	 dd l}t        j                  ddgddgddgddgddgddgddgddgddgddgddgddgg      }|j	                  t        ||      d      }|j                  g d      }|j                  dgd	z        }t        |d
      r|j	                  |d      }	 |j                  |||       y # t        $ r t        dj                  |             w xY w# t        $ r t        d      w xY w)Nr   r<   r   r-  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$
HHAAAAAAAAAAAA
  LL2>1EELRII:;))QC"H%i%78QU+A	MM!QgM6 	%%+VD\ 	  
;
 	

s   B"C, 0C $C))C, ,Dc                 z   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                  j                  d	d            }|j                  |||
       y )Nr<   r   r-  r  r%  r&  r   r   r'  )	r   r   r)  r  r  rA   r  reshaper   )r   r   r   r   r   r.  s         r   rl   rl   o  s     n%I
FFFFFFFFFFFF	
	A  	-na@AA89A1#(#G)!34r1-.MM!QgM.r7  c                    t        |      }t        j                  j                  d      }d}t	        ||j                  |df            }t        j                  |      dz  }t        ||      }dg|z  }|j                  |||       y )Nr      r-  r   r'  )	r   r   r   r   r  r  aranger   r   )r   r   r   rndrh  r   r   r[   s           r   rm   rm     s~     n%I
))


"CI!.#++Iq>+2RSA
		)q A!)Q/AC)OMMM!QmM4r7  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        ||      }|j	                  ||t        j
                  t        |                   t        t              5  |j	                  ||t        j
                  dt        |      z               d d d        t        t              5  |j	                  ||t        j
                  t        |      df             d d d        y # 1 sw Y   TxY w# 1 sw Y   y xY w)Nr<   r-  r   r  r<   r<   r<   r<   r   r   r   r   r<   r<   r<   r<   r   r   r   r   r'  )	r   r   r)  r   r   r]   r1  rM   r   )r   r   r   r   r   s        r   rn   rn     sC    n%I
FFFFFFFFFFFFFFFF!	
	A( 	ABA!)Q/AMM!Qbggc!foM6	
	a"''!c!f**=> 
 

	a"''3q61+*>? 
	 
	 
	s   34D:>3E:EEc                    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(  r~t        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        ||      }|j                  ||d        |j                  |||	       dD ]A  }t        ||      s t        ||      |      } t        ||      |      }t!        |||
       C y )Nr   r(  r<   r-  r   r  r  r7  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)  float64intr]   r1  vstackhstackr=   r   r   r   rz   r0  rF   )r   r   r^   
estimator1
estimator2X1y1X2y2sw2r   r  X_pred1X_pred2s                 r   rp   rp     s    ~&J~&JZa0Za0	FFFFFFFFFFFFFFFF!	
$ jj'
B* 
B#	NBv~ggCG$4&ST 	 
 YYBF|$YYAF|$ggCGaK(CGIb"c:B 4&WX 	 	":r	2B	":r	2BNN24N0NN23N/P>6*1gj&1"5G1gj&1"5G('7K	 Qr7  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<   |j                         }|j                  |||
       |  d}t        |||       y )Nr   r(  r<   r-  r   r  r9  r7  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     s    n%IYQ/
FFFFFFFFFFFFFFFF!	
$ jj'	A* 	AMA!)Q/AWWQWWQZ0 $1.335MM!Q&7M8NOG%'=wOr7  c                    t         j                  j                  d      }t        ||j	                  d            }|j                  t              }t        |      }|d d df   dz  j                  t              }t        |      }t        ||      }|j                  ||       t        |d      r|j                  |       t        |d      r|j                  |       t        t         dd	      5  |j                  ||j                  t                     d d d        d
|d   vr6ddi|d<   d}t        t"        |      5  |j                  ||       d d d        y |j                  ||       y # 1 sw Y   YxY w# 1 sw Y   y xY w)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   r5  s           r   rs   rs   -  sF    ))


"C!.#++8+2LMA	An%D	
1a41S!An%I!)Q/AMM!Qy)$!y+&A		!5	Ea&)* 
F tI&%.$ 4IS)MM!Q *) 	a! 
F	E *)s   0&E.?E:.E7:Fc                    t         j                  j                  d      }|j                  d      d|j                  d      z  z   }|j	                  dd      }|j                  ddd	      dz   }t        |      }t        |d
       t        t        d      5  |j                  ||       d d d        y # 1 sw Y   y xY w)Nrg  r   r   y              ?r0  r<   r   r   lowhighr   r(  zComplex data not supportedrQ  )r   r   r   r  r1  randintr   rN   rM   r   r   )r   r   r   r   r   r   s         r   rr   rr   R  s    
))


#CrCKKRK$888A			"aA 	+b0An%IYQ/	
">	?a 
@	?	?s   B66B?c                    | dv ry t         j                  j                  d      }| dv rd|j                  d      z  }nd|j                  d      z  }t	        ||      }|d d df   j                  t              }t        |      }t        ||      }t        |d      rd	|_
        t        |d
      rd	|_        t        |d      rd	|_        t        |d	       |j                  ||       dD ]T  }t        ||      s|j                  j!                         } t#        ||      |       |j                  |k(  rLJ d|z          y )N)SpectralCoclusteringr   )r!   r-  rf  r-  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  r0  )r   r   r5  r   r   r   r  dict_befores           r   r  r  `  s:    ''
))


"C""))))!.!4A	!Q$sAn%I!)Q/Ay.)!"	y,' 	y(#	Y"MM!QP9f%#,,113K&GIv&q)%%4 6?4	 Qr7  c                 L    | j                  d      xs | j                  d       S )N_)r   r   )attrs    r   _is_public_parameterrb    s"    $:c(:;;r7  c                 >   t        |j                  d      ry t        |      }t        j                  j                  d      }d|j                  d      z  }t        ||      }|d d df   j                  t              }t        ||      }t        |d      rd|_        t        |d      rd|_        t        |d       |j                  j                         }|j!                  ||       |j                  }|j#                         D cg c]  }t%        |      s| }	}|	D cg c]  }||j#                         vs| }
}|
rJ d	d
j'                  |
      z         |	D cg c]  }||   ||   ur| }}|rJ dd
j'                  |      z         y c c}w c c}w c c}w )Ndeprecated_originalr   r-  r[  r   r  r<   r  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, 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   r]  r  r   r   rb  r  )r   r   r   r5  r   r   dict_before_fitdict_after_fitr   public_keys_after_fitattrs_added_by_fitattrs_changed_by_fits               r   r  r    s    ~&&(=>n%I
))


"C	CKKWK%%A!.!4A	!Q$sA!)Q/Ay.)!"	y,' 	Y"((--/OMM!Q''N &**,,0DS0I,  
 -,?;O;O;Q0Q,  
 " 	 "&+=!>		?! )(CC s(;; 	(   $ 	 		"67		8##1s   FF"F:FFc           	         t         j                  j                  d      }d|j                  d      z  }t	        ||      }|d d df   j                  t              }t        |      }t        ||      }t        |d      rd|_
        t        |d      rd|_        t        |d       |j                  ||       dD ].  }t        ||      st        t        d	t!        ||      |d          0 y )
Nr   r-  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   r0  )r   r   r5  r   r   r   r  s          r   r  r    s     ))


"C	CKKWK%%A!.!4A	!Q$sAn%I!)Q/Ay.)!"	y,' 	Y"MM!QP9f% /F1KQqT Qr7  c           	          | |      }|j                   d   }|D cg c]  } | |j                  d|             }}t        |t              r|d   }t	        t        d |            }t        j                  |      r-|j                         }|D cg c]  }|j                          }}t        j                  |      t        j                  |      fS c c}w c c}w )Nr<   r   c                     | d   S )Nr   r  )xs    r   <lambda>z#_apply_on_subsets.<locals>.<lambda>  s    QqTr7  )r  r1  r  tuplelistmapr   issparsetoarrayr   ravel)r  r   result_fullri  batchresult_by_batchrn  s          r   _apply_on_subsetsry    s    q'KJGHIqetEMM!Z89qOI +u%!!ns>?CD{#!))+0?@1199;@88K "((?";;; J As   CCc                    t         j                  j                  d      }d|j                  d      z  }t	        ||      }|d d df   j                  t              }t        |      }t        ||      }t        |d      rd|_
        t        |d      rd|_        t        |d       |j                  ||       dD ]J  }d	j                  || 
      }t        ||      s#t        t!        ||      |      \  }}	t#        ||	d|       L y )Nr   r-  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  ry  r0  rE   )
r   r   r5  r   r   r   r  r5  rv  rx  s
             r   r  r    s    ))


"C	CKKWK%%A!.!4A	!Q$sAn%I!)Q/Ay.)!"	y,' 	Y"MM!Q OVV W 
 9f%+<	6*A,(K KtSQr7  c           	         t         j                  j                  d      }d|j                  d      z  }t	        ||      }|d d df   j                  t         j                        }t        |d      rd||dk(  <   t        |      }t        ||      }t        |d	      rd|_        t        |d
      rd|_        t        |d       |j                  ||       t         j                  j                  |j                   d         }dD ]W  }dj#                  ||       }t        ||      s#t%         t'        ||      |      |    t'        ||      ||         d|       Y y )Nr   r-  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   r0  )	r   r   r5  r   r   r   idxr  r5  s	            r   r  r    sA    ))


"C	CKKWK%%A!.!4A	!Q$rxx A.m4!q&	n%I!)Q/Ay.)!"	y,' 	Y"MM!Q
))



+C+
&T&
* 	
 9f%(*	6*1-c2*	6*1S62	r7  c                 $   t         j                  j                  d      }d|j                  d      z  }t	        ||      }|d d df   j                  t              }t        |      }t        ||      }t        |d      rd|_
        t        |d      rd|_        t        |d       | dk(  r|j                  d	
       | dk(  r|j                  d       g d}t        t        |d      5  |j!                  ||       d d d        y # 1 sw Y   y xY w)Nr   r-  )r<   r   r   r  r<   r  OPTICSr  r  rq  r  rr  )z1 samplezn_samples = 1zn_samples=1z
one samplez1 classz	one classTrL  )r   r   r   r  r  r  r<  r   r   rz   r  r  rN   r  rM   r   r   r   r   r5  r   r   r   msgss          r   r  r  A  s    
 ))


"C	CKKWK%%A!.!4A	!Q$sAn%I!)Q/Ay.)!"	y,' 	Y" x- v~,D 

$	6a 
7	6	6s   *DDc                    t         j                  j                  d      }d|j                  d      z  }t	        ||      }|d d df   j                  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  |j#                  ||       d d d        y # 1 sw Y   y xY w)Nr   r-  )r   r<   r   r  r<   r  RandomizedLogisticRegressionr!   r  )z1 feature\(s\)zn_features = 1zn_features=1TrL  )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!.!4A	!Q$sAn%I!)Q/Ay.)!"	y,' 	--$%	!  '*	$!)Q/AY"@D	
$	6a 
7	6	6s    C<<Dc                    t         j                  j                  d      }d|j                  d      z  }|j	                  t
              }t        |      }t        ||      }t        |d      rd|_	        t        |d      rd|_
        t        |d       t        t              5  |j                  ||       d d d        y # 1 sw Y   y xY w)Nr   r-  rf  r   r  r<   r  )r   r   r   r  r  r<  r   r   rz   r  r  rN   rM   r   r   )r   r   r5  r   r   r   s         r   r  r    s     ))


"C	CKKbK""A	An%I!)Q/Ay.)!"	y,' 	Y"	
	a 
		s   "B>>Cc                     t        dg dg dgddd      \  }}t               j                  |      }t        ||      }|rt	        ||g      \  }}t        | |||       y Nr3  r   r   r   r<   r<   r<   r   r   皙?rh  centersr)  ri  cluster_std)r   r.   rn  r  rK   _check_transformer)r   r   ra   r   r   s        r   r   r     sh    I&DAq 	&&q)A!+q1A(!Q01t[!Q/r7  c                 B   t        dg dg dgddd      \  }}t               j                  |      }t        ||      }t	        |      }t	        t        j                  |            }t        | |||       t        | ||j                         |j                                y r  )	r   r.   rn  r  r  r   r  r  tolist)r   r   r   r   this_Xthis_ys         r   r   r     s    I&DAq 	&&q)A!+q1A^FA'Ft[&&9t[!((*ahhjAr7  c                     t               \  }}t        |      }t        t        t        fd|  d      5  |j                  |       d d d        y # 1 sw Y   y xY w)NzThe unfitted transformer z\ does not raise an error when transform is called. Perhaps use check_is_fitted in transform.r:  )ro  r   rM   AttributeErrorr   r   )r   r   r   r   s       r   r   r     s\     DAq$K		$& !,,
 	a 
 
 
s   AAc                     t         j                  j                  d      }|j                  d      }t	        ||      }t        |      }|j                  |      }|j                  d   |j                  d   k(  sJ y)ztCheck that using transform without prior fitting
    doesn't raise a NotFittedError for stateless transformers.
    r   rf  r   r   N)r   r   r   r  r  r   r   r  )r   r   r   r   X_transs        r   r   r     sm    
 ))


"C!A!+q1A$K##A&G==qwwqz)))r7  c                 v   t        j                  |      j                  \  }}t        |      }t	        |       | t
        v rit         j                  t        j                  |      t        j                  |      f   }|d d ddfxx   dz  cc<   t        |t              rt        |      }n|}|j                  ||       t        |      }|j                  ||      }	t        |	t              r|	D ]  }
|
j                  d   |k(  rJ  n|	j                  d   |k(  sJ t        |d      r| t
        v r&|j                  ||      }|j                  ||      }n$|j                  |      }|j                  ||      }t        |d      r| dz   }t        |      t        |	t              rKt        |t              r;t!        |	||      D ]*  \  }
}}t#        |
|d	d
|z         t#        |
|d	d|z         , nDt#        |	|d
|z  d	       t#        |	|d	d|z         t%        |      |k(  sJ t%        |      |k(  sJ t        |d      rjt        |d      s\|j&                  dk(  rL|j                  d   dkD  r9t)        t*        d|  d      5  |j                  |d d d df          d d d        y y y y y y # 1 sw Y   y xY w)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:  r0  )r   r  r  r   rN   ru   c_r  r  r   rn  rp  rz   r   rA   rB   ziprF   rS   ndimrM   r   )r   transformer_origr   r   rh  ri  r   y_transformer_cloneX_predx_predrG  X_pred3r5  x_pred2x_pred3s                   r   r  r    s   JJqM//Iz()K[! ""UU2::a="**Q-/0
3Q36
a
a%RBOOArk*,,Q",5F&% F<<?i///  ||A)+++{K(&&!++Ar2G!//R/8G!++A.G!//R/8G&,?@00C3-fe$GU)C,/,I(,W!"	 -U!"	 -J  )S )Q	  (I555(I555 Aw{<!
Q &tf -5 5 %%a3B3i0    =  _ )j s   J//J8c                    t        |d      r| dz   }t        |      t        dg dg dgddd	
      \  }}t        ||t              }t        |      }t        ||      }t        |       t        |      }|j                  ||       |j                  ||       ddg}|D ]<  }t        ||d       }	|	t        ||      }
 |	||      } |
||      }t        ||       > y )Nr   r   r  r3  r  r  r   r   r  r  kernelr  rn  )rA   rB   r   r  r)   r   r   rN   r-   r   r0  rF   )r   r   r5  r   r   r   pipelinefuncs	func_namer  func_pipeliner  result_pipes                r   rv   rv   ;  s    .&9:,,sm I&DAq 	".!JGAn%I!)Q/AYY'HMM!QLLAo&E	y)T2#Hi8M!QZF'1-K(= r7  c           	      0   t         j                  j                  d      }d}|j                  |df      }t	        ||      }t        j
                  |      dz  }t        |      }t        ||      }t        |       g d}|D ]  }t        ||d       }	|	 |	||       t        |	      j                  j                         D 
cg c]  }
|
j                   }}
|d   dk(  r|dd  }|d   dv rkJ d	|d
t        |      j                  d|d        y c c}
w )Nr   r3  r-  r   )r   r  partial_fitr   rn  r  r<   )r   Yz.Expected y or Y as second argument for method  of z. Got arguments: r  )r   r   r   r  r  r4  r   r   rN   r0  r   
parametersvaluesr   rQ  rg   )r   r   r5  rh  r   r   r   r  r  r  prE  s               r   rj   rj   \  s    ))


"CI)Q(A!.!4A
		)q An%I!)Q/AYKE	y)T2AJ$-dO$>$>$E$E$GH$GqAFF$GDHAw&  ABx7j(  d9o66>(  Is   Dc                    t         j                  j                  d      }d|j                  d      j	                  t         j
                        z  }t        ||      }|j	                  t         j                        }|j	                  t         j                        }|j	                  t         j                        }t        j                  ddgdz  t         j                        }t        ||      }g d	}||||fD ]Q  }	t        |      }
t        |
d       |
j                  |	|       |D ]!  }t        |
|      s t!        |
|      |	       # S y )
Nr   r-  r  r   r<   r   r   r9  r\  )r   r   r   r  r  r   r  r;  r  r  r)  r   r   rN   r   rz   r0  )r   r   r5  
X_train_32
X_train_64X_train_int_64X_train_int_32r   r  X_trainr   r  s               r   ri   ri   z  s
   
))


"CS[[g[.55bjjAAJ*>:FJ""2::.J&&rxx0N&&rxx0N
!Q"BHH-A!.!4ALG
NNK.)	A&gq!Fy&)*	6*73  Lr7  c                    t        dg dg dgdd      \  }}t               j                  |      }t        ||      }t	        |d      D ]  }|j                  |      }t        |      }t        |       |j                  ||      }|j                  ||      j                  |      }t        ||gd	d
g      D ]P  \  }	}
t        |	t              r|	d   }	|	j                  |k(  r+J |  d|
 d|j                   d|	j                   d         y )Nr3  r  r  r   r  )rh  r  r)  r  r   r   rn  r   z	 (method=z3) does not preserve dtype. Original/Expected dtype=z, got dtype=r  )r   r.   rn  r  rA   r  r   rN   r   r   r  r  rp  r  rg   )r   r  r   r   r  X_castr   X_trans1X_trans2Xtr  s              r   r   r     s#    I&	DAq 	&&q)A!"2A6A,2CD%,-%,,VQ7??61-77?x2_k4RSJB"e$ U 88u$ &	& *++0>>*:,rxxjPQS$ T Er7  c                    t        |      }t        |d       t        j                  d      j	                  dd      }d|  d}t        t        |      5  |j                  |g        d d d        t        j                  d      j	                  dd      }t        |t        j                  g d            }d	}t        t        |
      5  |j                  ||       d d d        y # 1 sw Y   ~xY w# 1 sw Y   y xY w)Nr<   r   r-  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.rQ  )
r   rN   r   emptyr1  rM   r   r   r   r)  )r   r   eX_zero_samplesr   X_zero_featuresr   r5  s           r   rt   rt     s    nAQXXa[((A.N  I 	I  

G	,	nb! 
- hhqk))"a0O 	"!RXX.R%STA
WC	
#	&	oq! 
'	& 
-	, 
'	&s   C$C0$C-0C9c                    t         j                  j                  d      }t        ||j	                  d            }|j	                  d      }t         j
                  |d<   |j	                  d      }t         j                  |d<   t        j                  d      }d|d d t        ||      }d|  d}d|  d	}d|  d
}	||fD ]  }
t        t              5  t        |      }t        |d       t        t        ddg|      5  |j                  |
|       d d d        |j                  ||       t!        |d      r.t        t        ddg|      5  |j#                  |
       d d d        t!        |d      r.t        t        ddg|	      5  |j%                  |
       d d d        d d d         y # 1 sw Y   xY w# 1 sw Y   ZxY w# 1 sw Y   ,xY w# 1 sw Y   xY w)Nr   r   r-  r   rP  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   r5  X_train_finiteX_train_nanX_train_infr   error_string_fiterror_string_predicterror_string_transformr  r   s               r   rw   rw     s    ))


"C.1N ++7++KK++7++KK
AAbqE!.!4A#D6)OP'v-WX
TFFG   -m4n-IY*
5%.BRSgq) T MM.!, y), %.0
 %%g. y+. %.2
 ''0) 54 . TS  ) 54sT   ,GF-:GF9 (GGG-F62G9G>GG
GG	c                     t        dd      \  }}t        |      }t        t        d|  d      5  |j	                  ||       ddd       y# 1 sw Y   yxY w)z8Test that error is thrown when non-square data provided.rf  r   )rh  ri  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     sV     r2DAqn%I	%dV+VW
 	a
 
 
s   AAc                 >   g d}t        dg dg dgddd      \  }}t        ||t        	      }t        |      }|d
   r_t        j
                  j                  d      }|j                  |j                  dd      }t        j                  |j                  d      |<   t        |      }	t        |	|      }t        |	       |	j                  ||       |rt        |	      }
nbt!        j"                  |	      }|	j$                  }|j'                  d      rd|v s|j)                  d      sd|v sJ t!        j*                  |      }
t-               }|D ]$  }t/        |	|      s t1        |	|      |      ||<   & |D ]#  } t1        |
|      |      }t3        ||   |       % y)z'Test that we can pickle all estimators.r\  r3  r  r  r   r   r  r  r  rc   rg  r   F)replacer0  r   r   r   s   _sklearn_versionN)r   r  r)   rA   r   r   r   choicer   r   r1  r   r   rN   r   rK   pickledumpsr   r   r   loadsdictrz   r0  rF   )r   r   ra   check_methodsr   r   r   r   maskr   unpickled_estimatorpickled_estimatorr   r  r  unpickled_results                   r   r~   r~   
  s    SMI&DAq 	".!JGAn%DKii##B'zz!&&"ez4 ff		"dn%I!)Q/AYMM!Q7	B #LL3**!!*-{"k&:&::&F '*;;;;$ll+<=VF9f%7WY7:F6N   ?7#6?B$VF^5EF r7  c                    t        |d      sy t        |      }t        dd      \  }}t        ||      }t	        ||      }	 t        |      r*t        j                  |      }|j                  |||       n|j                  ||       t        t        d|  d      5  |j                  |d d d d	f   |       d d d        y # t        $ r Y y w xY w# 1 sw Y   y xY w)
Nr  2   r<   rh  r)  classesr  zZ does not raise an error when the number of features changes between calls to partial_fit.r:  r0  )rz   r   r   r  r   r   r   uniquer  NotImplementedErrorrM   r   )r   r   r   r   r   r  s         r   r   r   @  s     >=1n%I3DAq!.!4A!.!4A#iilG!!!Q!8!!!Q' 
TF #G G
 	a3B3i+
 
  
 
s   AC C	CCCc           	         d\  }}}t        |      }t        |      }t        d|||      \  }}|j                  ||       |j	                  |      }|j
                  ||fk(  s#J dj                  ||f|j
                               |j                  j                  dk(  sJ t        |d      r|j                  |      }	t        |	t        j                        sJ |	j
                  ||fk(  s#J dj                  ||f|	j
                               |	dkD  j                  t              }
|j                   |
   }t#        ||       t        |d	      r|j%                  |      }t        |t&              r|d
   st)        |      D ]z  }||   j
                  |dfk(  s&J dj                  |df||   j
                               t#        t        j*                  ||   d      j                  t              |d d |f          | nf|d
   sa|j
                  ||fk(  s#J dj                  ||f|j
                               t#        |j-                         j                  t              |       t        |d      rlt        |d	      r_t)        |      D ]P  }|j%                  |      d d |f   }|j                  |      }t#        t/        |      t/        |d d |f                R y y y )N)rg  r   r-  rg  )r)  rh  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  rq  rangeargmaxroundr   )r   r   rh  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 	**0&)X1F*U1 <<###y-...q1(BJJ///~~)Y!77 	
BBH&I&C	
7 qL((-$$X.7F+y/*((+fd#D,>9%ay9a.8 77=v"Aq	88 #IIfQia077<fQTl & l#<<Iy#99 3396	*FLL49 v||~44S96By-.79o3Vy!A--a0A6G"44Q7Jx0(:ad;K2LM " 4W.r7  c                    t        |      }dx}}t        |      s|dz   }t        dd||      \  }}t        ||      }|j	                  ||       |j                  |      }|j                  t        j                  d      k(  s J dj                  |j                               |j                  |j                  k(  sJ d       y )	Nr   r<   rg  r   )r)  	n_targetsrh  ri  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   rh  ri  r   r   r  s          r   r   r     s    i II
y)M	1	jDAq 	")Q/AMM!Qq!F<<288I.. 	44:F6<<4H. <<177" 	 "r7  c                 f   t        |      }t        dd      \  }}t        ||d      \  }}t               j	                  |      }t
        j                  j                  d      }t        j                  ||j                  ddd	      g      }|rt        |||g      \  }}}|j                  \  }}	t        |d
      r|j                  d       t        |       | dk(  r$|j                  d       |j                  d       |j                  |       |j                  |j!                                |j"                  }
|
j                  |fk(  sJ t%        |
|      dkD  sJ t'        |d      ry t        |       t)        j*                  d      5  |j-                  |      }d d d        t/        |
       |
j0                  t        j0                  d      t        j0                  d      fv sJ |j0                  t        j0                  d      t        j0                  d      fv sJ |j-                  |      }t        j2                  |      }t/        |t        j4                  |d   |d   dz                |d   dv sJ t        |d
      rt7        |d
      }|dz
  |d   k\  sJ y y # 1 sw Y   xY w)Nr  r<   r     r(  r-  )r   r   rU  r  )r  AffinityPropagationi)
preferencer  rw  g?r   r   Trecordr  r  r   r0  )r   r0  )r   r   r=   r.   rn  r   r   r   concatenater  rK   r  rz   r  rN   r   r  labels_r%   rA   r   catch_warningsr   rH   r  r  r4  r0  )r   clusterer_origra   r   r   r   r   X_noiserh  ri  r  pred2labelslabels_sortedr  s                  r   r   r     sp   n%I3DAq1aa(DAq&&q)A
))


"Cnna!&!IJKG11a/B1gGGIzy,'*Y$$-c* MM!MM!((*D::)%%%tQ'#---)!45Y		 	 	-%%a( 
.tU# ::"((7+RXXg->????;;288G,bhhw.?@@@@ ""7+F
 IIf%Mryyq!1=3Dq3HI
 w&&&y,'Y5
A~r!2222 (- 
.	-s   J&&J0c                 &   t        dd      \  }}t        |      }t        |       t        |d      r_|j	                  |      j                  |      }|j                  d       |j	                  |      j                  |      }t        ||       yy)z2Check that predict is invariant of compute_labels.rf  r   r  compute_labelsF)r  N)r   r   rN   rz   r   r   r  rH   )r   r
  r   r   r   rF  rG  s          r   r   r     s     3DAqn%IYy*+--"**1-E2--"**1-7G, ,r7  c                    d}d}t         j                  j                  d      }|j                  d      }|j                  d      }t        j                  d      }t        t              5  t        |      }t        t        dd	|
      5 }	|j                  ||       d d d        	j                  r
	 d d d        y t        |j                  |      ||       d d d        y # 1 sw Y   ExY w# 1 sw Y   y xY w)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  r5  r  X_testr   r   cms
             r   r   r     s    OU
))


"Ckkwk'G[[g[&F
A	-	0?+
g>N
NN7A&

    
1	0 	:--f5qBVW 
1	0
 
 
1	0s*   -C/C#C/=C/#C,	(C//C8c                 ^   |  d}|  d}t         j                  j                  d      }|j                  d      }|j                  d      }t        j                  d      dz  }|j                         }t        |      }	t        |	d      rd	|g}
t        t        f|}}nd
}
t        t        fd}}t        ||
d|      5 }|	j                  |||       |j                  r
	 ddd       yt        |	j                  |      t        j                   d      |       ddd       y# 1 sw Y   yxY w)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  r4  r  r   rU   AssertionErrorr   r[  rM   r   r  rH   r   r]   )r   r  	error_fiterror_predictr5  r  r  r   r[   r   r   err_typer   r  s                 r   r   r   	  s    & ; 	;  fWXM
))


"Ckkxk(G[[h['F
		"AFFHM'J_5"M2+Z8)'$&
3T'	g	F"w?  	 
G	F 	v&]	
 
G	F	Fs   ?"D#*0D##D,c                    t        dd      \  }}|j                  |      }t        ||d      \  }}t               j	                  |      }||dk7     }||dk7     }| dv r&||j                         z  }||j                         z  }|rt        ||||g      \  }}}}||fg}t        |      }	|	d   s|j                  ||f       |D ]  \  }
}t        j                  |      }t        |      }|
j                  \  }}t        |      }t        ||
      }
t        ||      }t!        |       |	d	   s3t#        t$        d
|  d      5  |j'                  |
|d d        d d d        |j'                  |
|       |j'                  |
j)                         |j)                                t+        |d      sJ |j-                  |
      }|j                  |fk(  sJ |	d   st/        ||      dkD  sJ d}d}|	d	   s|	d   rLt#        t$        |j1                  | d            5  |j-                  |
j3                  dd             d d d        nEt#        t$        |j1                  | d            5  |j-                  |
j4                         d d d        t+        |d      rC	 |j7                  |
      }|dk(  r]|	d   s|j                  |fk(  sJ |j                  |dfk(  sJ |j9                         dkD  j                  t:              }t=        ||       n4|j                  ||fk(  sJ t=        t        j>                  |d      |       |	d	   s|	d   rLt#        t$        |j1                  | d            5  |j7                  |
j3                  dd             d d d        nEt#        t$        |j1                  | d            5  |j7                  |
j4                         d d d        t+        |d      s |jC                  |
      }|j                  ||fk(  sJ t=        t        j>                  |d      |       tE        t        jF                  |d      t        jH                  |             |	d	   s|	d   rLt#        t$        |j1                  | d            5  |jC                  |
j3                  dd             d d d        nEt#        t$        |j1                  | d            5  |jC                  |
j4                         d d d        t+        |d      sB|jK                  |
      }tM        |t        jN                  |      dd       t=        t        jP                  |      t        jP                  |              y # 1 sw Y   xY w# 1 sw Y    xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# t@        $ r Y w xY w# 1 sw Y   xY w# 1 sw Y   xY w)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:  r0  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.   rn  r  rK   rA   appendr   r  r1  r  r   r  r   rN   rM   r   r   r  rz   r   r$   r  r1  Tr  ru  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  rh  ri  r   r  msg_pairwiser5  r  r  r  
y_log_probs                           r   r   r   ;	  sP    Ca8HC
**W
CsCa0HC


(
(
-C
cQh-C
cQh-CPPswwyswwy6S#s7KLS#sc
|Ho&Dc
#1))A,L	 !	:?+
%j!4%j!4$O$%dV ,< < q!CR&) 	q!qxxz188:.z:...##A&||	|+++L!!!V,t333G 	
 	 O$J(//i@ &&qyyQ'78	  J

40KL&&qss+ M:23%77:> 23'~~)==='~~)Q??? ( 01 4<<SAH&x8#>>i-CCCC&ryy'BFK O,J'#&$0$7$7>Q$R '882q9IJ	  $&$'JJt5H$I '88=	 :/--a0F<<Iy#9999ryya8&A%bffV!&<bggi>PQ(
#" , 3 3D/ J #002q1AB	   " #

4 A #005	
 z#67'99!<

BFF6NADI"2::j#92::f;MNa  H  ML(  
 '   s   U1"U>$VCV2("V
*V24V%V2
"WW1U;	>V	V	V"	V2%V/	*V22	V?>V?W	W	c                     | |k  r| }|dz   }n|}| dz   }t        j                  |      }d}t        t        j                  |||             dk(  sJ |       y )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   sortr1  r  )num_outliersexpected_outliersr  startendsorted_decisionr5  s          r   check_outlier_corruptionr8  	  so     ''!#!Q
 ggh'O	9 
 ryys345:?C?:r7  c                    d}t        |d      \  }}t        |d      }|rt        |      }|j                  \  }}t	        |      }t        |       |j                  |       |j                  |j                                |j                  |      }|j                  |fk(  sJ |j                  j                  dk(  sJ t        t        j                  |      t        j                  ddg             |j                  |      }	|j!                  |      }
|	|
fD ]8  }|j                  t        j                  d	      k(  sJ |j                  |fk(  r8J  t#        t$              5  |j                  |j&                         d d d        |	dk\  j)                  t*              }d||dk(  <   t        ||       t#        t$              5  |j                  |j&                         d d d        |
|j,                  z
  }t/        ||	       t#        t$              5  |j!                  |j&                         d d d        t1        |d
      rt1        |d      sxd}||z  }|j3                  |       |j                  |       |j                  |      }t        j4                  |dk7        }||k7  r|j                  |      }	t7        |||	       y y y y # 1 sw Y   IxY w# 1 sw Y   xY w# 1 sw Y   xY w)Nr  r   r  r  r(  r  r0  r<   r  r   noveltyr3  r   )r   r=   rK   r  r   rN   r   r  r   r  r^   rH   r   r  r)  r  r  rM   r   r&  r  r<  offset_rE   rz   r  r'  r8  )r   r   ra   rh  r   r`  ri  r   r  r  scoresoutputr  y_decr4  r   r3  s                    r   r   r   	  s   I	:DAq"A%a(GGIzn%IY MM!MM!((*q!F<<I<'''<<###ryy("((B7*;<**1-H$$Q'FV$||rxx0000||	|+++ %
 

	!## 
 A%%c*H HX]x( 

	##ACC( 
 Y&&&EE8$ 

	$ 
 y/*79i3P
 )I5=9a""1%vvfk* ,, 2215H$\3DhO -# 4Q*+ 
	 
	 
	s$   $KKK KK K)c           	         t        |d      sy d|j                  vry |j                  d   }t        |D cg c]  }t        |t               c}      st        d      |D ]i  }t        |t              s|j                  t        k(  r=|j                  dk\  r.|j                  dk  r|j                  dkD  rU|j                  dv rdJ d        y c c}w )	N_parameter_constraintsr   zDcontamination constraints should contain a Real Interval constraint.        r  r   >   rightneitherz:contamination constraint should be an interval in (0, 0.5])rz   rA  rZ  r  r?   r  rQ  r
   leftrC  closed)r   r   contamination_constraintsc
constraints        r   r   r   $
  s     >#;<nCCC . E Eo V1JK1JA
1h'1JKLR
 	
 0
j(+4'OOs*$$+__q(J,=,=AU,U	L
 LLW 0 Ls   Cc           	         t        ddddddd      \  }}t        |      }|d d	 |d d	 }}|d	d  }|j                         }t        |      }t	        |      }	t        |	       |	j                  ||      j                  |      }
|	j                  ||      j                  |      }|	j                  ||      j                  |      }t        |
|       t        |
|       |
j                  |j                  k(  sJ |
j                  |j                  k(  sJ t        |
      t        |      k(  sJ t        |
      t        |      k(  sJ y )
Nr  r   r   r-  r  Tr   rh  ri  r  r  lengthallow_unlabeledr)  P   )r   r/   r  rq  r   rN   r   r   rH   r  rQ  )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   ?
  sP   )DAq 	aA"vq"vWGrsVF#NN,!']'JZ ^^GW-55f=F%>>'3HIQQ 'NN74JKSS v45v34<<066666<</55555<4 56666<4 45555r7  c           	      x   t        |      }t        |       d\  }}}t        |d|dddd      \  }}t        |      }|d|  || d }	}|d|  || d }}
|j	                  ||
       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       y)zeCheck the output of the `predict` method for classifiers supporting
    multilabel-indicator targets.r     r   r   r-  r  Tr   rK  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   r0  rB   r  r   r  rQ  r  r  )r   r  r   rh  	test_size	n_outputsr   r   r  r  rO  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DN$01E0FhOPPF#F fbjj) &B<.		#) <<6<<' &8 Gll^1	&' <<6<<' & ||nLa	9'r7  c           	      
   t        |      }t        |       d\  }}}t        |d|dddd      \  }}t        |      }|d|  || d }	}|d|  }
|j	                  ||
       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        |j                  d      d|        yt        |t        j                         r|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|       yt%        dt'        |       d|  d      )zkCheck the output of the `predict_proba` method for classifiers supporting
    multilabel-indicator targets.rU  r   r-  r  Tr   rK  Nr  rW  rX  zWhen zn.predict_proba returns a list, the list should be of length n_outputs and contain NumPy arrays. Got length of rZ  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 rY  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   r0  rB   r  rq  r1  r  r  r^   rE   r'  r   r  rI   r   rQ  )r   r  r   rh  r[  r\  r   r   r  r  rO  r^  predict_proba_methodr  r  r   s                   r   r   r   
  s    'JZ &0#Iy))DAq 	aA)na
nVG)nGNN7G$*":/CTJ#$01E0FhOPP!&)F &$6{i' 	
D6 f+l9+Q8	
'
 D::)Q/ v ))-Lq>"!%/ ::??c) v A::,i)) v % %  DHH!H,aA' ( 
FBJJ	'||	955 	
D6 ==C\\NIy12!5	
5
 ||  C' 	
D6 339<<.	K	
'
 D6 C C 	
 	!VW5&!W5$T&\N$tf =B B
 	
r7  c           	      2   t        |      }t        |       d\  }}}t        |d|dddd      \  }}t        |      }|d|  || d }	}|d|  }
|j	                  ||
       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       y)zoCheck the output of the `decision_function` method for classifiers supporting
    multilabel-indicator targets.rU  r   r-  r  Tr   rK  Nr  rW  rX  z<.decision_function is expected to output a NumPy array. Got rY  z].decision_function is expected to provide a NumPy array of shape (n_samples, n_outputs). Got rZ  r  ra  z?.decision_function is expected to output a floating dtype. Got )r   rN   r   r/   r   r0  rB   r  r   r  rQ  r  r  r^   )r   r  r   rh  r[  r\  r   r   r  r  rO  r^  decision_function_methodr  s                 r   r   r   
  s~    'JZ &0#Iy))DAq 	aA)na
nVG)nGNN7G$.&z3GN'$01E0FhOPP%f-F fbjj) & V~Y	() <<Iy11 & 006~\y!
"!	%1
 <<# & ~Y	(#r7  c                     t        |      }d|  d}t        t        |      5  |j                          ddd       y# 1 sw Y   yxY w)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_errorrg    sH     n%I
TF ( 	(  
	0'') 
1	0	0s	   =Ac                     t        dd      \  }}t        ||      }t        |      }t        ||      }|rt	        ||g      \  }}t        |       |j                  ||      |u sJ y)z+Check if self is returned when calling fit.r      r)  rh  N)r   r  r   r   rK   rN   r   )r   r   ra   r   r   r   s         r   rq   rq   '  sl     13DAq!.!4An%I!)Q/A(!Q01Y==A)+++r7  c                     t               \  }}t        |      }dD ]9  }t        ||      st        t              5   t        ||      |       ddd       ; y# 1 sw Y   FxY w)z}Check that predict raises an exception in an unfitted estimator.

    Unfitted estimators should raise a NotFittedError.
    )r  r   r  r  N)ro  r   rz   rM   r   r0  )r   r   r   r   r   r  s         r   r   r   7  s\      DAqn%I 9f%'*	6*1- (' ('s   AA!	c           	         t        |      }t        j                  j                  d      }d}t	        ||j                  |df            }t        j                  |      dz  }t        ||      }t        |      }t        |       |j                  ||       |j                  |      }t        |       t        j                  d      5 }	t        j                  dt               t        j                  dt                |j                  ||d d t        j"                  f          d d d        |j                  |      }
d	d
j%                  	D cg c]  }t'        |       c}      z  }|d   st)        |	      dkD  sJ |       d|v sJ t+        |j-                         |
j-                                y # 1 sw Y   xY wc c}w )Nr   r3  r-  r   Tr  alwaysr  z)expected 1 DataConversionWarning, got: %sre  r   zPDataConversionWarning('A column-vector y was passed when a 1d array was expected)rA   r   r   r   r  r  r4  r   r   rN   r   r   r   r	  simplefilterr   RuntimeWarningnewaxisr  r  r1  rE   ru  )r   r   r   r5  rh  r   r   r   r  w	y_pred_2dw_xr5  s                r   r   r   L  s   n%D
))


"CI!.#++Iq>+2RSA
		)q A!.!4An%IYMM!Qq!FY 
	 	 	-h(=>h7a1bjj=)* 
. !!!$I
5		QcSQ9 C 1vz3z7:=>	
> FLLNIOO$56 
.	- 	 s   	AF2F>
2F;c                    t        j                  |      }t        |      }|dk(  r| | j                         kD  } t	        |       |j                  | |       |j                  |       }t        |d      r^|j                  |       }t        |t         j                        sJ t        |      dk(  r|j                         dkD  j                  t              }|j                  |   }	t!        |	|d|ddj#                  t%        t&        |	            ddj#                  t%        t&        |            d	
       nt)        |dd      dk(  rt        j*                  |d      j                  t              }
|j                  |
   }t!        ||d|ddj#                  t%        t&        |            ddj#                  t%        t&        |            d	
       |dk7  r2t!        t        j                  |      t        j                  |             t!        ||j                  d|ddj#                  t%        t&        |            ddj#                  t%        t&        |j                              d	
       y )Nr  r  r   r   z0decision_function does not match classifier for z: expected 're  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  r1  ru  r  r<  r  rH   r  rr  r  r0  r  )r   r   r   r  r  r   r  r  r  r  
decision_yy_exps               r   check_classifiers_predictionsrz  o  s   iilG'J}LZ NN1a"Fz.///2(BJJ///w<1 (1,44S9H ))(3G IIc#w/0IIc#v./ Z!:EBeK8!4;;C@J''
3E IIc#uo.IIc#v./ ~ 	299Q<6):; IIc#w'(IIc#z2234	
	r7  c                     | dv r|S |S )N)LabelPropagationLabelSpreadingSelfTrainingClassifierr  )r   r   y_namess      r    _choose_check_classifiers_labelsr    s!    
 SS 	
 r7  c                 f   t        ddd      \  }}t        ||d      \  }}t               j                  |      }||dk7     }||dk7     }t	        ||      }t	        ||      }g d}d	d
g}t        j                  ||      }t        j                  ||      }	|||	fg}
t        |d      s|
j                  |||f       |
D ]9  \  }}}||j                  d      fD ]  }t        | ||      }t        ||| |        ; ddg}t        j                  ||      }	t        | ||	      }t        ||| |       y )Nr3  r   r  )rh  r)  r  r  r(  r   )onetwothreer  r  r  r   Or0  r<   )r   r=   r.   rn  r  r   takerA   r%  r  r  rz  )r   r  X_multiclassy_multiclassX_binaryy_binarylabels_multiclasslabels_binaryy_names_multiclassy_names_binaryr.  r   r   r  	y_names_ir  s                   r   r   r     sP   !+1#"L, ")|RS!TL,!#11,?LLA-.HLA-.H,_lKL((CH/ENM!2LAWW]H5N8^45Ho=9|5GHI!1g!7>>##67I1$9EB)!RG 8 "
 GMWW]H5N/hOH!(HdOLr7  c           
         t               \  }}t        ||d d       }t        j                  j	                  d      }|j                  d|j                  d         }t        ||      }t        j                  j	                  d      }t        |      }t        |      }t        |       t        |       | t        v rDt        j                  |d|z  |j                  dt        |            z   g      }|j                  }n|}|j                  ||       |j                  |      }	|j                  ||j!                  t"                     |j                  |      }
t%        |	|
d|        y )Nr  r   r-  r   r   r  r~  )ro  r  r   r   r   rX  r  r   r   rN   ru   r=  r1  r&  r   r   r  r  rE   )r   regressor_origr   r`  r5  r   regressor_1regressor_2r  pred1r  s              r   r   r     s+    DAq!.!CR&9A
))


"CAAGGAJ'A!.!4A
))


"C'K'K[![!""YY1q53;;qs1v;#>>?@TT OOAr"EOOAryy'("EE5tT:r7  c           
         t               \  }}|j                  |      }t        |      }t        |      }t	        ||      }t        ||      }| t        v rct        j                  j                  d      }t        j                  |d|z  |j                  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  |j)                  ||d d        d d d        t+        |       |j)                  ||       |j)                  |j-                         |j-                                |j/                  |      }	|	j0                  |j0                  k(  sJ t3        |d      s|j5                  ||      dkD  sJ y y # 1 sw Y   xY w)Nr   r   r   alphasr  r  PassiveAggressiveRegressorr"  r#  r:  r0  r  r   r  )ro  r  r/   r   r  r   ru   r   r   r   r=  rX  r1  r&  rK   rz   r  r*  rM   r   r   rN   r  r   r  rA   r  )
r   r  ra   r   r   r   r   r5  r  r  s
             r   r   r     s     DAq	AaAn%I!)Q/A!)Q/A""ii##A&YY1q53;;qs1v;#>>?@TT,aBZ81b9h'GIw,G	++	 
dV $$ $
 	a3B 
 YMM!RMM!((*biik*q!F<<288###
 i\2q"%+++ 3)
 
s   G		Gc                    t         j                  j                  d      }t        |      }|j	                  d      }t        ||      }t        ||d d df         }|j                  ||       g d}|D ]  }t        ||      sJ  y )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!.!4A!)Qq!tW5AMM!QGE	9i000 r7  c                    t        |d      rdg}nddg}|D ]i  }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        |      j                  |
      }t        |d      r|j                  d       t        |d      r|j                  d       t        |d      r|j                  d       t        |d      r|j                  d       t        |       |j                  ||       |j                  |      }t        |d      rMt        j                  |dk(        dkD  rjJ  y )Nr  r   r   r-  r   rf  )r  r)  r  r  r[  r)  r\     g-C6?)r   r<   )r   r<   r   r   rt  r  ru  rv  rw  min_weight_fraction_leafr  )r  n_iter_no_change)r  r  gףp=
?)rA   r   r+   r)   r1  r   r  r   r  rz   rN   r   r   rw  )r   r  r.  	n_centersr   r   r  r  rO  r]  r   r   r  s                r   r   r   <  s|   /}53q6	)!L1+;qCa,
(&
 o:60F '2G		'*+	>#/L#6:L?+66L6Q
:x(!!!-:z*!!4!0:9:!!4!@:12!!2!6$w(##F+ /|<776Q;'$...G r7  c                    t        |      }t        |d      r|j                  d       t        |d      r|j                  d       t        |       |j	                  ||       |j                  |      }|j                  d       |j	                  ||       |j                  |      }	t        ||	d	
      t        ||d	
      kD  sJ y )Nrt  r  ru  rv  r  rw  balancedr  weighted)average)r   rz   r  rN   r   r   r&   )
r   r  r  rO  r  r]  r.  r   r  y_pred_balanceds
             r   'check_class_weight_balanced_classifiersr  i  s     'Jz8$S)z:&t,Z NN7G$'Fz2NN7G$ ((0OFOZ@8
D   r7  c                 B   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|j                  d	       t        |d
      r|j                  d       t        |d      r|j                  d       t	        |       |j                  d       |j                  ||      j                  j                         }t        |      }t        t        t        j                  |                  }|t        j                  |dk(        |z  z  |t        j                  |dk(        |z  z  d}|j                  |       |j                  ||      j                  j                         }	t        ||	d| z         y)z4Test class weights with non-contiguous class labels.      r   gr  rB  )r<   r<   r<   r0  r0  rt  r  ru  rv  rw  r  r-  r  r  r  r<   r0  )r<   r0  z>Classifier %s is not computing class_weight=balanced properly.r:  N)r   r)  rz   r  rN   r   coef_r  r1  r  r  r'  rE   )
r   
Classifierr   r   r   coef_balancedrh  r  r   coef_manuals
             r   -check_class_weight_balanced_linear_classifierr    sz    	4,q	D$<#sc3ZPQA
"#AJz8$ 	T*z:&t,z4 #Z  z2NN1a(..335M AIc"))A,'(I qAv23R945L |4..A&,,113KPSWWr7  c                    t        dd      \  }}t        ||t              }t        |      }t	        ||      }t        |       |j                         }t        |      }|j                  ||       |j                         }|j                         D ]I  \  }}	||   }
t        j                  |
      t        j                  |	      k(  r7J d| d|d|	d|
d		        y )
Nr   ri  rj  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3DAq!.!JGAn%I!)Q/AY !!#Fv&O MM!Q %%'J&5&;&;&="
Nz*	 {{9%^)DD 	
 Z<	
D '>r7  c                 p   	 t        |      }t        t        |      j                  d      ryt        t        |      j                        }t        rdD ]  }||v s|j                  |        d t        |      j                  D        D cg c]  }|D ]  }|  }}}t        t        |            t        |      z
  t        |      z
  }t        |D 	cg c]  }	|	j                  d      r|	 c}	      }|rJ d| dt        |      d	       y# t        $ r t        d|  d      w xY wc c}}w c c}	w )
zCheck setting during init.r   z9 should store all parameters as an attribute during init.rd  N)r   c              3   2   K   | ]  }t        |        y wrP  )rD   )rR  parents     r   rT  z2check_no_attributes_set_in_init.<locals>.<genexpr>  s     V>UFi/>Us   r`  zR should not set any attribute apart from parameters during init. Found attributes r  )r   r  rz   rQ  r  rD   rO   remove__mro__setr  r   sorted)
r   r   r   init_paramsr   params_parentr<  parents_init_paramsinvalid_attrra  s
             r   rh   rh     sD   
 .)	 tI'')>?DO445KCk!""3' 
 Wd9o>U>UVVM"E 	" 	V   tI'#k*::SAT=UULRT__S=QRSL  %	'|1  
WX
 	

 Ss   D D-D3,D3D*c                 n   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        |      }|j	                  ||       |j                  |      }|j                          t        j                  |j                        sJ |j                  |      }t        ||       t        j                  t        j                  |            }t        j                  |j                        sJ |j                  |      }t        ||       y )Nr0  r<   r   )	r<   r<   r<   r   r   r   r-  r-  r-  )r   r)  r   r   r   r   rd   r   rs  r  rH   r  r  r  )r   r   r   r   rS  	pred_origr  s          r   r{   r{     s   
HHHFFFHFH
	
	A 	,-A!.!4A

CGGAqMAI LLN??399%%%;;q>DtY' ,,v||C(
)C??399%%%;;q>DtY'r7  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	        | ||||        y )Nr-  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  	".!4A
56A!.!4A5*4AxP 6r7  c                 z    t               \  }}t        ||      }t        ||      }dD ]  }t        | ||||        y )Nr  )ro  r  r   r  r  s        r   r   r   ,  s@     DAq!.!4A!.!4A5*4AxP 6r7  c                    | t         v rt        d      t        |      }t        |      }t        |       t        |       |dvrt	        dj                  |            |dk(  r=t        t        j                  |            }t        t        j                  |            }nv	 dd l	}	t        j                  |      }|j                  dk(  r|	j                  |d      }n|	j                  |d      }|	j                  t        j                  |      d      }|j                  ||       |j                  |      }
|j                  ||       |j                  |      }t!        |
|d
|        y # t        $ r t        d	      w xY w)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  r+  r*  r,  r   r   rE   )r   r   r   r   r  estimator_1estimator_2r  X_r-  r  r  s               r   r  r  5  sZ   ""%
 	
 'K'K[![!886==hGHH<A'A'
	ABww!|YYrY.\\"5\1bjjm%8B OOB#EOOAq"EE5tT:  	V 	s   !A5E, ,Fc                 :   |j                   }t        t              5  t        |      }t	        |       t        |       |j                         |u sJ t        |j                  d|j                        }	 d }t        |      j                  j                         D cg c]  } ||      s| }}|j                         }|t        t        |dg             d  }|D ]  }|j                   |j"                  k7  s+J d|j$                  dt'        |      j(                  d       t*        t,        t.        t0        t2        t'        d       t&        h}	|	j5                  t6        j8                  j                                t'        |j                         |	v xs t;        |j                         }
|
sbJ d|j$                   d	|j(                   d
t'        |j                         j(                   d|j$                   dt=        d |	D               d       |j$                  |j?                         vr0|j                   "J d|j$                   d	|j(                   d       }||j$                     }tA        |t6        jB                        rtE        ||j                          d|j$                   d}tG        |      r||j                   u rJ |       ||j                   k(  rJ |        	 d d d        y c c}w # t        t        f$ r Y d d d        y w xY w# 1 sw Y   y xY w)Nr   rd  c                     | j                   dk7  xr4 | j                  | j                  k7  xr | j                  | j                  k7  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}  sA     FFf$ 3!--/3!"2"22r7  r&  z
parameter rD  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   4   K   | ]  }|j                     y wrP  )rg   )rR  rQ  s     r   rT  z9check_parameters_default_constructible.<locals>.<genexpr>  s     ?t}}s   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  r6  r   reprr  r0  r  r   r  r  r[  r   r   r1  defaultr  r   rQ  rg   r  r<  r  r  rp  updater   
sctypeDictcallabler  r   r  r  rH   r>   )r   r3  r   initr  r  r  r  
init_paramallowed_typesallowed_valueparam_valuefailure_texts                r   r  r  d  s    ##I	-	0'	2	iY##%222 y))+@)BTBTU	 %T?55<<>>a,q/>   %%'!#gi9OQS&T"U"WX%J""j&6&66 Y((6 T
M   !5!5!78 Z''(M9 - ++,  ! joo. /&&'}
**+445 6OO$$L???@	C= fkkm3!))1 +JOO+< =!**+ ,JJ1
  1K+rzz2";
0B0BC ! 1 2; ;  !-&**<*<<JlJ<&**<*<<JlJ<s &O 
1	06 :& 	 E 
1	0>	? 
1	0sU   AL5(K4K/+K//K41HLLL/K44LLLLLc                 J   t        | d      r|dt        |j                               z   z  }t        | d      rF|j                  dkD  r7t	        j
                  ||j                  d   k(  ||j                  d   dz         }t        | d      rt	        j                  |d      S |S )Nrequires_positive_yr   r<   r  r   r   )r0  r<   )rA   r  r  r   r   whereflatr1  )r   r   s     r   r   r     s     )!67 	
QQUUW)/AFFQJHHQ!&&)^Qq	A6 )!34zz!W%%Hr7  c                    dt        | d      v r	|d d df   }t        | d      r||j                         z
  }dt        | d      v rbt        | d      rt        j                  nt        j                  }t        j
                  ||j                         z
        j                  |      }| j                  j                  dk(  r||j                         z
  }t        |       rt        |d	
      }|S 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adG )!67K
9)<<(D

"((HHa!%%'k#**51##'::K 9%q5 H 
I:	.1aLHr7  c                    g d}|t         z  }| |v ry | dk(  rt        |      j                  d      }nt        |      }t        |d      r}t	               }|j
                  |j                  }}t        ||      }t        |d       t        ||      }|j                  ||       t        j                  |j                  dk\        sJ y y )N)r"   RidgeClassifierr   r   ry  r    r~  	LassoLarsrB  r  rv  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A&%na8avvi''1,--- &r7  c                 h   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       |j                  ||       | t        v r|j                  D ]	  }|dk\  r	J  y |j                  dk\  sJ y y )Nrv  )rB  rB  r  )r  rB  rB  )       @r  r  )r  re  g      @r  gɿg?g?g      g333333?r3  r  r  r   r   r  r<   )r   rz   ru   r   r  rN   r   r  )r   r   r   r   r  iter_s         r   r   r   "  s     n%Iy*%&& /?OTA+SzC;dDB "I.EAr *.!<AA&a &&"**z!z + $$)))/ &r7  c                     t        |      }|j                  d      }|j                  d      t        fd|j                         D              sJ y )NFdeepTc              3   B   K   | ]  }|j                         v   y wrP  )r  )rR  itemdeep_paramss     r   rT  z.check_get_params_invariance.<locals>.<genexpr>I  s"     N7Mtt{((**7Ms   )r   r   r  r  )r   r   r  shallow_paramsr  s       @r   r	  r	  A  sL     	nA\\u\-N,,D,)KN~7K7K7MNNNNr7  c           
         t        |      }|j                  d      }d} |j                  di | |j                  d      }t        |j	                               t        |j	                               k(  sJ |       |j                         D ]  \  }}||   |u rJ |        t        j                   t        j                  d g}t        |      }	|j	                         D ]  }
||
   }|D ]  }||	|
<   	  |j                  di |	 |j                  d      }t        |	j	                               t        |j	                               k(  sJ |       |j                         D ]  \  }}|	|   |u rJ |         ||	|
<    y # t        t        f$ r}|j                  j                  }t        j                  dj                  ||
|              dj                  |      }|}|j                  d      }	 t        |j	                               t        |j	                               k(  sJ |j                         D ]  \  }}||   |u rJ  n$# t         $ r t        j                  |       Y nw xY wY d }~d }~ww xY w)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_paramsr5  curr_paramsr!  r"  test_valuestest_paramsr  default_valuer   r  e_typechange_warning_msgparams_before_exceptions                    r   r
  r
  L  s    n%I&&E&2K
JCI';'&&E&2K{!"c+*:*:*<&==BsB=!!#11~"'C'" $ FF7BFFD)K;'K!&&(
#J/ E&+K
#4$	$$3{34 (222>;++-.#k6F6F6H2IIN3NI'--/DAq&q>Q.33. 0? !B #0JG ) z* 6--,,2F6:t,L PVV #
 +6''222>66;;=>##((*C    !, 1 1 316q9Q>>> !4% 6MM"456-6sD   4FI9A!I43AI
I
	I4
I+	(I4*I+	+I44I9c                     t               \  }}t        ||      }t        |      }d}t        |d      s-t	        t
        |      5  |j                  ||       d d d        y y # 1 sw Y   y xY w)NzUnknown label type: rb   r   rQ  )ro  r  r   rA   rM   r   r   )r   r   r   r   r  r5  s         r   r   r     s`      DAq!.!4AnA
 Ca_-Jc*EE!QK +* .**s   A""A+c           	         ddg}t        ddd|dd      \  }}t        ||d	d
      \  }}}}t        |      }	t        |	d      rt        |	d      r|	j	                  ||       |	j                  |      d d df   j                  d      }
|	j                  |      j                  d      }t        |
      t        |      }}	 t        ||       y y y # t        $ r t        j                  t        j                  |      D cg c]  }|||k(     j                          nc c}w c}      }t        j                  |      }t!        |t        j"                  t%        |                   Y y w xY w)N)r   r   )r  r  r  r   r  r  T)rh  r)  ri  r  r  r=   皙?r  r  r  r<   r   )decimals)r   r+   r   rz   r   r  r  r  r   rG   r  r   r)  r  rw  r)  rH   r4  r1  )r   r   r  r   r   r  r  rO  r]  r   ab
rank_proba
rank_scoregroupgrouped_y_score
sorted_idxs                    r   r   r     se   
 vGDAq (8	1!($GVWf n%Iy-.79o3Vgw' ##F+AqD1777D''/55r5B!)!hqkJ
	G%j*= 4W.  
	G !hh<>IIj<QR<Q5:&',,.<QRO O4Jz299S_+EF
	Gs   C /E* D
A
E*)E*c                    d}t        |d      \  }}t        |d      }|j                  \  }}t        |      }t	        |       |j                  |      }|j                  |fk(  sJ |j                  j                  dk(  sJ t        t        j                  |      t        j                  ddg             t        |d	      r,|j                  |      j                  |      }t        ||       t        |d
      r}d}	t        |	      |z  }
|j!                  |
       |j                  |      }t        j"                  |dk7        }||	k7  r,t        |d      r|j%                  |      }t'        ||	|       y y y y )Nr  r   r  r  r(  r  r0  r<   r   r   r3  r;  r  )r   r=   r  r   rN   r   r  r^   rH   r   r  r)  rz   r   r   r  r  r'  r  r8  )r   r   rh  r   r`  ri  r   r  y_pred_2r4  r   r3  r  s                r   r   r     si    I	:DAq"AGGIzn%IY""1%F<<I<'''<<###ryy("((B7*;<
 y)$==#++A.68,y/* /09<=9&&q)vvfk*
 ,,*2
 !2215H$\3DhO	2
, +r7  c                     t        j                  ddgddgg      }t        j                  ddg      }t        |      }t        t              5  |j                  ||       d d d        y # 1 sw Y   y xY w)Nr  r<   r   )r   r)  r   rM   r   r   r  s        r   r  r    s]     	4)dAY'(A
!QAn%I	
	a 
		s   A))A2c           
         g d}t         j                  j                  d      }t        |      }t	        |       d|j                         j                         v r|j                  d       d}|j                  d|df      }t        ||      }t        |      r|j                  |	      }n|j                  dd|
      }t        ||      }t        t        d|      j                  |            \  }}	t!        ||||      \  }
}t!        ||||	|      \  }}|j#                  |
|       |D ci c]!  }t%        ||      r| t'        ||      |      # }}t	        |       |j#                  |
|       |D ]  }t%        ||      s t'        ||      |      }t        j(                  |j*                  t         j,                        r-dt        j.                  |j*                        j0                  z  }n0dt        j.                  t         j2                        j0                  z  }t5        ||   |t7        |d      t7        |d      dj9                  |              y c c}w )Nr\  r   
warm_startFr  r  r   locr   r   rU  r  r  r  r}  z&Idempotency check failed for method {})r  rtolr   )r   r   r   r   rN   r   r   r  r  r  r   rX  r   nextr*   splitr,   r   rz   r0  
issubdtyper  floatingfinfoepsr;  rF   maxr  )r   r   r  r   r   rh  r   r   traintestr  rO  r  r]  r  r  
new_resulttols                     r   r  r    s    SM
))


"Cn%IYy++-2244.I

s)Q
0A!)Q/AN#JJIJ&KKAAIK6!)Q/A|cDJJ1MNKE4"9aE:GW Aq$>NFF MM'7# $#F9f% 	*	6*622#   YMM'7#9f%3F3F;J}}Z--r{{;"((:#3#34888"((2::.222(vd^d^@GGO  s   .&Ic                    t         j                  j                  d      }t        |      }t	        |       d|j                         v r|j                  d       d}|j                  d|df      }t        ||      }t        |      r|j                  |      }n|j                  d	d|
      }t        ||      }t        |      j                  dd      s.	 t        |       t        |j                   j"                   d      |j'                  ||       	 t        |       y # t$        $ r Y *w xY w# t$        $ r}t%        d      |d }~ww xY w)Nrg  r  Fr  r  r   r  r   r   rU  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   rX  r   rA   getrT   r  rf   rg   r   r   )r   r   r   r   rh  r   r   r  s           r   r  r  /  sK    ))


#Cn%IYy++--.I

s)Q
0A!)Q/AN#JJIJ&KKAAIK6!)Q/Ai $$[%8	I& &&//0 1   MM!Q	"	  		
  T
	s*   -D# D2 #	D/.D/2	E;EEc                    t         j                  j                  d      }t        |      }t	        |       d|j                         v r|j                  d       d}|j                  d|df      }t        ||      }t        |      r|j                  |      }n|j                  dd|	      }t        ||      }t        |d
      rJ |j                  ||       t        |d
      sJ |j                  |j                  d   k(  sJ y )Nr   r  Fr  r  r   r  r   rU  n_features_in_r<   )r   r   r   r   rN   r   r  r  r  r   rX  r   rz   r   r'  r  )r   r   r   r   rh  r   r   s          r   r  r  V  s     ))


"Cn%IYy++--.I

s)Q
0A!)Q/AN#JJIJ&KKAAIK6!)Q/Ay"2333MM!Q9.///##qwwqz111r7  c                 8   t         j                  j                  d      }t        |      }t	        |       d}|j                  d|df      }t        ||      }d}	 |j                  |d        y # t        $ r t        fd|D              sY d y 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   8   K   | ]  }|t              v   y wrP  )r  )rR  r5  ves     r   rT  z(check_requires_y_none.<locals>.<genexpr>  s     ?->c3#b'>->s   )
r   r   r   r   rN   r  r  r   r   rZ  )r   r   r   r   rh  r   expected_err_msgsr*  s          @r   r  r  p  s     ))


"Cn%IYI

s)Q
0A!)Q/Aa ?->??H @s   A0 0	B9BBc                    t        |      }d|d   v xs d|d   v }|r|d   ry t        j                  j                  d      }t	        |      }t        |       d|j                         v r|j                  d       d	}|j                  |d
f      }t        ||      }t        |      r|j                  |      }n|j                  dd|      }t        ||      }|j                  ||       |j                  |j                  d   k(  sJ g d}	|d d dgf   }
d|j                  d    d}|	D ]O  }t!        ||      st#        ||      }|dk(  rt%        ||      }t'        t(        |      5   ||
       d d d        Q t!        |d      sy t	        |      }t+        |      r(|j-                  ||t        j.                  |             n|j-                  ||       |j                  |j                  d   k(  sJ t'        t(        |      5  |j-                  |
|       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr   r   r  rb   r   r  Fr  r   r  r   r   rU  r<   )r   r   r  r  r  z'X has 1 features, but \w+ is expecting z features as inputr  r  rQ  r  r  )rA   r   r   r   r   rN   r   r  r  r  r   rX  r   r   r'  r  rz   r0  r   rM   r   r   r  r  )r   r   r   is_supported_X_typesr   r   rh  r   r   r  X_badr5  r  callable_methods                 r   !check_n_features_in_after_fittingr0    s+    n%D 	T)_$Hi(H   4#8
))


"Cn%IYy++--.I

A
'A!)Q/AIJJIJ&KKAAIK6!)Q/AMM!Q##qwwqz111M a!fIE4QWWQZL@R
SCy&)!)V4W%o;OJc*E" +*   9m,n%IYaBIIaL9a###qwwqz111	
#	&eQ' 
'	& +* 
'	&s   /	H*H7*H4	7I c                     t        |      }t        |d      sy t        |j                         j	                               }t        t        j                               }|j                  |      |k(  sJ |  d||j                  |      z
          y )N	_get_tagsz@._get_tags() is missing entries for the following default tags: )r   rz   r  r2  r   r@   intersection)r   r   r   	tags_keysdefault_tags_keyss        r   r   r     s     n%I9k*I'')..01IM..01!!"348II & !7!78I!JJK	MIr7  c           	      	   	 dd l }t        |      }d|d   v xs d|d   v }|r|d   ry t        j
                  j                  d      }t        |      }t        |       |j                  d      }t        ||      }|j                  \  }}	t	        j                  t        |	      D 
cg c]  }
d	|
 	 c}
      }|j                  ||d
      }t        |      r|j                  |      }n|j!                  dd|      }t#        ||      }t%        j&                         5  t%        j(                  ddt*        d       |j-                  ||       d d d        t/        |d      st1        d      t3        |j4                  t        j6                        sJ |j4                  j8                  t:        k(  sJ t=        |j4                  |       |j>                  }|jA                  d      r2d|v s.|jC                  d      sd|jD                  vrt1        d|  d      g }dD ]@  }t/        ||      stG        ||      }|dk(  rtI        ||      }|jK                  ||f       B |D ]G  \  }}t%        j&                         5  t%        j(                  ddt*        d        ||       d d d        I |d d d   dft        |	      D 
cg c]  }
d|
 	 c}
df|d d  d!tM        |d d         d"fg}|jO                         jQ                         D ci c]  \  }}d#|v r|| }}}tS        d$ |jU                         D              }|D ]  \  }}|j                  ||d
      }tW        jX                  d%|       }|D ]+  \  } }t[        t0        ||  d&'      5   ||       d d d        - t/        |d(      r|rqt        |      }t]        |      r*t	        j^                  |      }|ja                  |||)       n|ja                  ||       t[        t0        |*      5  |ja                  ||       d d d         y # t        $ r t        d      w xY wc c}
w # 1 sw Y   xY w# 1 sw Y   xY wc c}
w c c}}w # 1 sw Y   
xY w# 1 sw Y   KxY w)+Nr   Hpandas is not installed: not checking column name consistency for pandasr   r   r  rb   )   r$  r   col_Fcolumnsr  r   rU  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  r0  z<Feature names must be in the same order as they were in fit.another_prefix_zHFeature names unseen at fit time:
- another_prefix_0
- another_prefix_1
r-  z3Feature names seen at fit time, yet now missing:
- 
early_stoppingc              3   $   K   | ]  }|d u  
 yw)TNr  )rR  r   s     r   rT  z;check_dataframe_column_names_consistency.<locals>.<genexpr>N  s      LO5$Os   zBThe feature names should match those that were passed during fit.
z did not raiser   r  r  rQ  )1r(  r,  rB   rA   r   r   r   r   rN   r  r  r  r)  r  r*  r   rX  r   r   r	  filterwarningsUserWarningr   rz   r   r  r@  r  r  rR  rH   r   r   r   r  r0  r   r%  r  r   r  rZ  r  r  escaperM   r   r  r  )r   r   r-  r   r-  r   r   X_origrh  ri  r  namesr   r   r   r  r  r/  r`  invalid_namesr   r   r  early_stopping_enabledinvalid_nameadditional_messager.  expected_msgr  s                                r   (check_dataframe_column_names_consistencyrO    s   
 n%DT)_$Hi(H   4#8
))


"Cn%IYZZXZ&F&y&9F"LLIzHH%
*;<*;QQCj*;<=E
VU7AIJJIJ&KKAAIK6!)Q/A 
	 	 	"9 		
 	a 
# 9127
 	
 i112::>>>&&,,666y22E: !++Kz*K';+?+?
+K )?)?@PQ
 	
 M y&)!)V4W%o;Ofo67" #	6$$&##=$ 	 1I '& # 
ttTU,1*,=>,=qqc",=>&	
 "1IB3uQRy>BRRTU	
M  $..06688JCs" 	U
8  
 ! LFMMO LL,9((Q5AyyQ!"$
 *LD&,4&8O u  * y-04J.)	#iilG!!!Q!8!!!Q'Jl3!!%+ 433 -:_  
V
 	

. = 
#	"` '& ? " 43sM   P3 'Q 0Q<&QQ*Q/	Q5R3QQQ'	5Q?R	c                    |j                         }d|d   vs|d   ry t        dg dg dgddd	
      \  }}t               j                  |      }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<   |j                  ||      }t        |      D 	cg c]  }	d|	 	 }
}	t        t        d      5  |j                  |
d d d          d d d        |j                  |
      }|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-        |              y c c}	w # 1 sw Y   xY w)Nr   r   rb   r3  r  r  r   r   r  r  r<   r  featurez'input_features should have length equalrQ  c              3   <   K   | ]  }t        |t                y wrP  )r  r  )rR  r   s     r   rT  z:check_transformer_get_feature_names_out.<locals>.<genexpr>  s     C1Bz$$1BrU  	Expected  feature names, got )r2  r   r.   rn  r   r  r  rN   ru   r   r  r  r  rM   r   rf  r  r  r  rR  r  rp  r1  )r   r  r   r   r   r   ri  r  X_transformr  input_featuresfeature_names_outn_features_outs                r   'check_transformer_get_feature_names_outrY  m  s   %%'DY'4+@I&DAq 	&&q)A()K!+q1AJ[!	
B""UU2::a="**Q-/0
3Q36
a
++A+4K-2:->?->sm->N? 

"K	L)).1*=> 
M $99.I((('444""f,,,C1BCCCC+u%$Q--a0$**1- 	.0P	>""6s;L7M6NOP0% @ 
M	Ls   8G(G--G6c                 .   	 dd l }|j                         }d|d   vs|d   ry t	        dg dg dgdd	d
      \  }}t               j                  |      }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<   t        |      D 	cg c]  }	d|	 	 }
}	|j!                  ||
d      }|j                  ||      }t        |      D 	cg c]  }	d|	 	 }}	t#        t$        d      5  |j'                  |       d d d        |j'                         }|j'                  |
      }t)        ||       t+        |t,              r|d   j                  d   }n|j                  d   }t/        |      |k(  sJ d| dt/        |              y # t        $ r t        d      w xY wc c}	w c c}	w # 1 sw Y   xY w)Nr   r7  r   r   rb   r3  r  r  r   r  r  r<   r  Fr:  r  badz0input_features is not equal to feature_names_in_rQ  rS  rT  )r(  r,  rB   r2  r   r.   rn  r   r  r  rN   ru   r   r  r  r  r*  rM   r   rf  rH   r  rp  r1  )r   r  r-  r   r   r   r   ri  r  r  feature_names_indfrU  invalid_feature_namesfeature_names_out_defaultfeature_names_in_explicit_namesrX  s                    r   .check_transformer_get_feature_names_out_pandasra    s5   
 %%'DY'4+@I&DAq 	&&q)A()K!+q1AJ[!	
B""UU2::a="**Q-/0
3Q36
a
+0+<=+<a#aS	+<=	a!1	>B++B"+5K 16j0AB0A1s1#Y0AB	
"T	U))*?@ 
V !, A A C&1&G&G'# 02QR+u%$Q--a0$**1- 	%&.8X	>""6s;T7U6VWX8e  
V
 	

: >
 C	U	Us#   G) *H,HH)G>Hc                    t         j                  j                  d      }|j                  d      }|j	                  ddd      }t        ||      }|j                  d      j                         }|r_|j                  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 ]u  }t        ||      s|  d| d}	t!        t"        ||	      5  t        d t%        |d      D              r t'        ||      |       n t'        ||      ||       d d d        w |D cg c]  }t)        |       }}|D ]  }	 t+        |      } |j                  di ||i |D ]u  }t        ||      s|  d| d}	t!        t"        ||	      5  t        d t%        |d      D              r t'        ||      |       n t'        ||      ||       d d d        w   y # 1 sw Y   ?xY wc c}w # t,        $ r Y w xY w# 1 sw Y   xY w) Nr   r  r   r   rf  Fr  z>Mismatch between _parameter_constraints and the parameters of z%.
Consider the unexpected parameters z% and expected but missing parameters BadTyper  )r   r  rn  r   rb   c              3   f   K   | ])  }t        |t              xr |j                  t        k(   + y wrP  )r  r?   rQ  r	   rR  rI  s     r   rT  z)check_param_validation.<locals>.<genexpr>  s0      
)
 z8,LH1LL)   /1c              3   f   K   | ])  }t        |t              xr |j                  t        k(   + y wrP  )r  r?   rQ  r
   re  s     r   rT  z)check_param_validation.<locals>.<genexpr>  s0      
)
 z8,HD1HH)rf  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   b   K   | ]'  }t        |t              xr |j                  d        ) ywr  N)r  r  r   rR  X_types     r   rT  z)check_param_validation.<locals>.<genexpr>  s0      "F vs+I0II"Fs   -/r   r   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   | ]  }|j                  d         ywri  )r   rj  s     r   rT  z)check_param_validation.<locals>.<genexpr>C  s!      &JF 1&Js   )r   r   r   r  rX  r   r   r   rA  r  rQ  rZ  r   r   r  rz   rM   r9   rA   r0  r;   r:   r  )r   r   r   r   r   estimator_paramsvalidation_paramsunexpected_paramsmissing_paramsr   param_with_bad_typefit_methodsr  constraintsr   r   r  rI  	bad_values                      r   check_param_validationru    s~    ))


"C!AAqr"A!.!4A%00e0<AAC *AAFFH 12S9I5JJ-.5F1GGLTF S44E3F G##1"24 	
 !$44=g=4 2$y"b13HK&
$;;JG/)  
)
 
  
)
 
 /
|4v F$ $  OD69TUf #$IK 	
 .)	 		A
,?@A!F9f- & <  DD  -UGL ",YI"F 
 /GIv.q1.GIv.q!4 ML "0 FQQ[zz2[Q%J6zB	 !I  ;J	#:;%y&1 f !!+ -""  1P &0	&J 
 3	62152	621a8 QP & &u 'V ML R
 ' ( QPs2   AJ!(J.J3AK	!J+3	J?>J?Kc                 >    |j                         }d|d   vs|d   ry t        j                  j                  d      }t	        |      }|j                  d      t        |      |j                  ddd      t        |      t        |        fd	}fd
}||d}|j                         D ]e  \   }t	        |      }t        |       s ||      }	 t        v r|	d   }	|j                  d        ||      }
 t        v r|
d   }
t        |	|
       g y )Nr   r   rb   r   r  r   r   rf  c                     t         v r"| j                        j                        S | j                        j                        S rP  )ru   r   r   )rS  r   r   r   s    r   fit_then_transformz6check_set_output_transform.<locals>.fit_then_transform]  sD    &&771a=**1a00wwq!}&&q))r7  c                 (    | j                        S rP  )rn  )rS  r   r   s    r   rn  z1check_set_output_transform.<locals>.fit_transformb  s      A&&r7  )r   rn  r  r   )r2  r   r   r   r   r  r  rX  r   rN   r  rz   ru   
set_outputrF   )r   r  r   r   r   rx  rn  transform_methodstransform_methodX_trans_no_settingX_trans_defaultr   r   s   `          @@r   check_set_output_transformr  M  s6    %%'DY'4+@
))


"C()K!A!"2A6AAqr"A!"2A6A[!*
' (& #4"9"9";K({D)-k: &&!3A!63*;7&&-a0O 	%%7I# #<r7  c                     i }d||fd||fd||fd||fg}t         fddD              ra|D ]\  \  }}}	 j                  ||       |t        v r j                  |	|      \  }
}n j                  |	      }
|
 j	                         f||<   ^ d|fd|fg}t         d	      rO|D ]J  \  }}|t        v r j                  ||      \  }
}n j                  ||      }
|
 j	                         f||<   L |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   6   K   | ]  }t        |        y wrP  )rz   )rR  methr   s     r   rT  z-_output_from_fit_transform.<locals>.<genexpr>  s     
G2F$7;%2Fs   )r   r   zfit_transform/dfzfit_transform/arrayrn  )r  r   ru   r   rf  rz   rn  )r   r   r   r]  r   outputscasescasedata_fitdata_transformr  r`  r  s   `            r   _output_from_fit_transformr  }  s:    G 
B'	!2q)	!1b)	$a+	E 
G2F
GG
 	
OOHa(**(22>1E
%//?$k&G&G&IJGDM  
R 	"E {O,JD$**(66tQ?
%33D!<$k&G&G&IJGDM   Nr7  c                     |\  }}	|\  }
} ||
      sJ |j                  d      r|nd} ||||      }	  ||
|       y# t        $ r}t        |  d| d|       |d}~ww xY w)a  Check if the generated DataFrame by the transformer is valid.

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

    Parameters
    ----------
    name : str
        The name of the transformer.
    case : str
        A single case from the cases generated by `_output_from_fit_transform`.
    index : index or None
        The index of the DataFrame. `None` if the library does not implement a DataFrame
        with an index.
    outputs_default : tuple
        A tuple containing the output data and feature names for the default output.
    outputs_dataframe_lib : tuple
        A tuple containing the output data and feature names for the pandas case.
    is_supported_dataframe : callable
        A callable that takes a DataFrame instance as input and return whether or
        E.g. `lambda X: isintance(X, pd.DataFrame)`.
    create_dataframe : callable
        A callable taking as parameters `data`, `columns`, and `index` and returns
        a callable. Be aware that `index` can be ignored. For example, polars dataframes
        would ignore the idnex.
    assert_frame_equal : callable
        A callable taking 2 dataframes to compare if they are equal.
    r]  Nr;  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1UtN)4N8%78 f@ G001s4
 		s   	A   	A"	AA"c                   |j                         }d|d   vs|d   ryt        j                  j                  d      }t	        |      }	|j                  d      }
t        ||
      }
|j                  ddd	      }t        ||      }t        |	       t        |
j                  d
         D cg c]  }d| 	 }}t        |
j                  d         D cg c]  }d| 	 }} ||
||      }t	        |	      j                  d      }t        || |
||      }|dk(  r&t	        |	      j                  |      }t               }nt	        |	      }t        |      }	 |5  t        || |
||      }ddd       |D ]  }t'        | ||||   |   |||        yc c}w c c}w # 1 sw Y   3xY w# t         $ r7}|j#                         }t%        |      }| d|v sd|v sJ |       Y d}~yd}~ww xY w)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   rf  r<   r  r  r  r  rz  local)transform_outputz% output does not support sparse data.z.The transformer outputs a scipy sparse matrix.)r2  r   r   r   r   r  r  rX  r   rN   r  r  r{  r  r   r   r   
capitalizer  r  )r   r  dataframe_libr  r  r  contextr   r   r   r   r   r  r\  r  r]  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6AAqr"A!"2A6A[!+0+<=+<a#aS	+<="'
"34"3QuQC["3E4	!%5U	CB,77)7L01DdArSTUO'{+666O${+'G3ND!RQRSJ   "D!t"		
  7 >4 ^ '224ADEV?=P	 	Q 	s<   +FFF) F+F) F&"F) )	G)2-G$$G)c           	          	 dd l t        | |dfdfdj                  j
                  |       y # t        $ r t        d      w xY w)Nr   z0pandas is not installed: not checking set outputr(  c                 0    t        | j                        S rP  r  r*  )r   r-  s    r   ro  z<_check_set_output_transform_pandas_context.<locals>.<lambda>K      Ar||)Dr7  c                 .    j                  | |d|      S )NF)r;  r  r  )r*  )r   r;  r  r-  s      r   ro  z<_check_set_output_transform_pandas_context.<locals>.<lambda>L  s    2<<wU% 4@ 4
r7  r  r  r  r  r  )r(  r,  rB   r  testingr  )r   r  r  r-  s      @r   *_check_set_output_transform_pandas_contextr  A  sX    K *D
 ::88
  KIJJKs	   4 A	c                     t        | |d       y Nr  r  r   r  s     r   !check_set_output_transform_pandasr  T      .t5EwOr7  c                     t        | |d       y Nglobalr  r  s     r   $check_global_output_transform_pandasr  X      .t5ExPr7  c           	          	 dd l ddlm} fd}t        | |dfd|||       y # t        $ r t	        d      w xY w)Nr   )r  z0polars is not installed: not checking set outputc                     t        |t        j                        r|j                         }j	                  | |d      S )Nr  )schemaorient)r  r   r  r  r*  )r   r;  r  pls      r   r  zD_check_set_output_transform_polars_context.<locals>.create_dataframec  s2    grzz*nn&G||Age|<<r7  polarsc                 0    t        | j                        S rP  r  )r   r  s    r   ro  z<_check_set_output_transform_polars_context.<locals>.<lambda>m  r  r7  r  )r  polars.testingr  r,  rB   r  )r   r  r  r  r  r  s        @r   *_check_set_output_transform_polars_contextr  \  sR    K5= *D)-  KIJJKs   
( =c                     t        | |d       y r  r  r  s     r   !check_set_output_transform_polarsr  t  r  r7  c                     t        | |d       y r  r  r  s     r   (check_global_set_output_transform_polarsr  x  r  r7  c                    t         j                  j                  d      }t        |      }t	        |       d}t        |d|      \  }}t        ||      }| dv rt        j                  |      }t        |d      rt         j                  |d<   t        |      r|j                  |      }n|j                  dd	|
      }t        ||      }|j                         }|j                  d       |j!                  ||       t        |d      r|j#                  |       |j$                  j&                  rJ t)        ||       y)a  Check that estimators able to do inplace operations can work on read-only
    input data even if a copy is not explicitly requested by the user.

    Make sure that a copy is made and consequently that the input array and its
    writeability are not modified by the estimator.
    r   r  r-  )rh  ri  r)  )Lasso
ElasticNetMultiTaskElasticNetMultiTaskLassomissing_valuesrP  r   r   rU  F)writer   N)r   r   r   r   rN   r   r  asfortranarrayrz   r   r   r  rX  r   r  setflagsr   r   flags	writeablerE   )	r   r   r   r   rh  r   r`  r   X_copys	            r   check_inplace_ensure_writeabler  |  s    ))


"Cn%IYI	acJDAq!)Q/A OOa  y*+&&$IJJIJ&KKAAIK6!)Q/AVVXF JJUJMM!Qy+&Aww    Avr7  )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   rm  ru   r   r   r  r   r   r   r   r   r   r  r$  r6  rA  rJ  r;  r]  rb  ro  r  r  r  r  r   r  r  r}   r|   rk   rl   rm   rn   rp   ro   rF  rs   rr   r  rb  r  r  ry  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   r8  r   r   r   r   r   r   rg  rq   r   r   rz  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  r0  r   rO  rY  ra  ru  r  r  r  r  r  r  r  r  r  r  r  r  r7  r   <module>r     s   W  	  "  $ ) "         P O <  D C L L < 5 $ 1 4 @  6 
  # '    M L H H H 7t!+H -(  ) D22'>
62*
6%r!/H,^
V*? ;|N;b x,vW W*)$'J LIf "3;lOR
 -((
 )(
V =*/ +/8 =*5 +5 -(!@ )!@H -(AL )ALH%PP =+67! 8!H $ $N< -(5 )5p -( )0<$ -(!R )!RH -(( )(V % %P  <  $ -(0 )0" -(B )B" -(! )!  -(* )*X1v > >@  : 4 4,@ -(" )". -(-1 )-1`   2G 2Gj -(, ),8 -(9N )9Nx -( )2 -(73 )73v -(- )- -(X )X, -(!
 )!
H :CGO GOT@,EPPL6 -(%6 )%6P -() ))X -(P
 )P
f -(* )*Z -(* )* -(, ), . .( -(7 )7D = =@MD -(; );6 -(*//, )/,d 1 1  -()/ ))/X -( )* -(% )%P -(
 )
B -(" )"J -(( )(D -(Q )Q0 -(Q )Q -(+; )+;\fKR  4A 4 -('. )'.T -(* )*< -(O )O -(50 )50p -(
 )
 -()G ))GX(PV7t$N244 -(A( )A(HL,^-P`6Xrt9n-J`*Z:zW
t&PQ0PQ -(* )*r7  