
    ZPho                       d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	m
Z
 ddlmZmZ ddlZddlmZ  e eej                  j                  Zd Zd Zd\d	Ze ed
          k     rd Zd ZnddlmZ ddlmZ e ed          k     rdefdZd Zd Zd Znddl mZmZ ddl!mZmZ e ed          k     rPddl"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) ddl"m*Z+  ej,                    dv Z-ddl"m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z; ddl"m<Z= nTddl>m+Z+m&Z&m'Z'm(Z( ddl?m.Z.m/Z/m1Z1m2Z2m9Z9m;Z; ddl@m4Z4m7Z7m:Z: ddlAm=Z=m8Z8 dd lBm5Z5m6Z6 dd!lCm0Z0 dd"lDm$Z$m)Z) dd#lm#Z#m-Z-m%Z% dd$l!m3Z3 e ed%          k     rCdd&lEmFZF d]d(d)d*ZGd+ ZH	 	 	 	 	 d^d.ZId/ ZJd0 ZK	 d_d-d1dd(d(dd(d-d(d2d2dd'd3d4ZL e	d`i  e             G d5 d6                      ZM e	d`i  e             G d7 d8                      ZN e	d`i  e             G d9 d:                      ZO e	d`i  e             G d; d<                      ZP e	d`i  e             G d= d>                      ZQ e	d`i  e             G d? d@                      ZR e	d`i  e             G dA dB                      ZSdC ZT	 	 dad-ddDdEddFdbdQZUd-ddRdcdSZVdS ddTl"mPZPmMZMmQZQmSZSmNZNmOZO  e	d`i  e             G dU d6eM                      ZM e	d`i  e             G dV d@                      ZR e	d`i  e             G dW dBeS                      ZSddXlWmHZH ddYlEmUZUmVZV ddZlXmGZG dd[l!mKZKmJZJmLZLmIZI dS )da{  Ease developer experience to support multiple versions of scikit-learn.

This file is intended to be vendored in your project if you do not want to depend on
`sklearn-compat` as a package. Then, you can import directly from this file.

Be aware that depending on `sklearn-compat` does not add any additional dependencies:
we are only depending on `scikit-learn`.

Version: 0.1.1
    )annotationsN)	dataclassfield)CallableLiteral)parse_versionc                 .    t           j        dk     ri S ddiS )N)   
   slotsT)sysversion_info     ^/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/imblearn/utils/_sklearn_compat.py_dataclass_argsr   "   s    
'!!	T?r   c                    	 ddl m}  ||           S # t          $ r" ddl m} t	           ||           |           cY S w xY w)a  Get estimator tags in a consistent format across different sklearn versions.

    This function provides compatibility between sklearn versions before and after 1.6.
    It returns either a Tags object (sklearn >= 1.6) or a converted Tags object from
    the dictionary format (sklearn < 1.6) containing metadata about the estimator's
    requirements and capabilities.

    Parameters
    ----------
    estimator : estimator object
        A scikit-learn estimator instance.

    Returns
    -------
    tags : Tags
        An object containing metadata about the estimator's requirements and
        capabilities (e.g., input types, fitting requirements, classifier/regressor
        specific tags).
    r   )get_tags)
_safe_tags)sklearn.utils._tagsr   ImportErrorr   _to_new_tags)	estimatorr   r   s      r   r   r   (   sv    (>000000x	""" > > >222222JJy119=====>s    )??c                   t          d| d         v d| d         v d| d         v d| d         v d| d         v d| d         v d| d         v | d	         | d
         | d         d| d         v           }t          | d         d| d         v d| d         v | d         | d         p| d         | d                    }|7t          |d          st          |d          rt          | d                   }nd}t	          |dd          }|dk    r&t          | d         | d          | d                   }nd}|d k    rt          | d         | d         !          }nd}|d"k    r%t          |                     d#d$          %          }nd}t          ||||||||                     d&d$          | d'         | d(         | d)         | d*         +          S ),zGUtility function convert old tags (dictionary) to new tags (dataclass).1darrayX_types2darray3darraysparsecategoricalstringdictrequires_positive_X	allow_nanpairwise	dataframe)one_d_arraytwo_d_arraythree_d_arrayr   r    r!   r"   positive_onlyr$   r%   r&   
requires_y1dlabels2dlabelsrequires_positive_ymultioutputmultioutput_only)requiredone_d_labelstwo_d_labelsr*   multi_outputsingle_outputN	transformfit_transformpreserves_dtype)r8   _estimator_type
classifier
poor_scorebinary_only
multilabel)r;   multi_classmulti_label	regressor)r;   r?   samplersample_indicesF)rB   array_api_supportno_validationnon_deterministicrequires_fit
_skip_test)estimator_typetarget_tagstransformer_tagsclassifier_tagsregressor_tagssampler_tags
input_tagsrC   rD   rE   rF   rG   )
	InputTags
TargetTagshasattrTransformerTagsgetattrClassifierTagsRegressorTagsSamplerTagsgetTags)	old_tagsr   rN   rI   rJ   rH   rK   rL   rM   s	            r   r   r   F   sv   )!44)!448I#668I..!Xi%888I..x	**45;'*%)!44  J ,'8I#668I#6645m,L9K0L"#566  K 	;'' +29o+N+N  +$%67
 
 
  Y(94@@N%%(-$]33 .
 
 
 $$&- .
 
 

 """#<<(8%@@
 
 
 %)'%! #,,':EBB/"#67n-L)   r   z1.3c                    d }|S )zGDecorator to run the fit methods of estimators within context managers.c                F     t          j                    fd            }|S )Nc                D    |                                    | g|R i |S N)_validate_params)r   argskwargs
fit_methods      r   wrapperz0_fit_context.<locals>.decorator.<locals>.wrapper   s5    **,,,!z)=d===f===r   )	functoolswraps)ra   rb   s   ` r   	decoratorz_fit_context.<locals>.decorator   s8    _Z((> > > > )(> Nr   r   )prefer_skip_nested_validationre   s     r   _fit_contextrg      s    	 	 	 r   c               $    ddl m}  ||           S )z(Validate the parameters of an estimator.r   validate_params)sklearn.utils._param_validationrj   )parameter_constraintsrf   rj   s      r   rj   rj      s%    CCCCCC4555r   )rg   ri   z1.4c                    |6t          |t          t          f          s|g} | fd|D                       S t           d          r                                 S d t                     D             }t          |          dk    S )a  Determine if an estimator is fitted

        Parameters
        ----------
        estimator : estimator instance
            Estimator instance for which the check is performed.

        attributes : str, list or tuple of str, default=None
            Attribute name(s) given as string or a list/tuple of strings
            Eg.: ``["coef_", "estimator_", ...], "coef_"``

            If `None`, `estimator` is considered fitted if there exist an
            attribute that ends with a underscore and does not start with double
            underscore.

        all_or_any : callable, {all, any}, default=all
            Specify whether all or any of the given attributes must exist.

        Returns
        -------
        fitted : bool
            Whether the estimator is fitted.
        Nc                0    g | ]}t          |          S r   )rQ   ).0attrr   s     r   
<listcomp>z_is_fitted.<locals>.<listcomp>   s#    OOODwy$77OOOr   __sklearn_is_fitted__c                f    g | ].}|                     d           |                    d          ,|/S )___)endswith
startswith)ro   vs     r   rq   z_is_fitted.<locals>.<listcomp>   sK     
 
 
!**S//
BC,,tBTBT

 
 
r   r   )
isinstancelisttuplerQ   rr   varslen)r   
attributes
all_or_anyfitted_attrss   `   r   
_is_fittedr      s    0 !j4-88 *(\
:OOOOJOOOPPP9566 	522444
 
I
 
 
 <  1$$r   c               &    ddl m}  || |fddi|S )z$Validate and route input parameters.r   )process_routingother_paramsN) sklearn.utils._metadata_requestsr   )_obj_methodr`   r   s       r   r   r      s3    DDDDDDtWJJ4J6JJJr   c                    ddl m} |r|j        j         d| n|j        j        } |            s$| r$t	          d| dt          |                      dS dS )zHRaise an error if metadata routing is not enabled and params are passed.r   )_routing_enabled.z#Passing extra keyword arguments to z is only supported if enable_metadata_routing=True, which you can set using `sklearn.set_config`. See the User Guide <https://scikit-learn.org/stable/metadata_routing.html> for more details. Extra parameters passed are: N)r   r   	__class____name__
ValueErrorset)paramsownermethodr   callers        r   _raise_for_paramsr      s    EEEEEE *u'22&222) 	
  !! 	f 	Hf H H ;>f++	H H  	 	 	 	r   c                v    	 t           j        d         }n# t          $ r Y dS w xY wt          | |j                  S )z+Return True if the X is a pandas dataframe.pandasF)r   modulesKeyErrorry   	DataFrame)Xpds     r   _is_pandas_dfr      sI    	X&BB 	 	 	55	!R\***s    
##)r   r   )r   r   z1.5)	_IS_32BIT_approximate_mode#_in_unstable_openblas_configurationgen_batchesgen_even_slicesget_chunk_n_rowssafe_sqr)_chunk_generator)wasm32wasm64)_determine_key_type_get_column_indices_print_elapsed_time_safe_assign_safe_indexing_to_object_arrayaxis0_safe_slicecheck_matplotlib_supportcheck_pandas_supportindices_to_maskis_scalar_nanresample	safe_maskshuffle)_is_pandas_na)chunk_generatorr   r   r   )r   r   r   r   r   r   )r   r   r   )is_pandas_nar   )r   r   )r   )r   r   )r   _IS_WASMr   )r   z1.6_construct_instance F)raise_unknownc               R     ddl m}  fd} |           } ||          S )Nr   type_of_targetc                N    r!| dk    rrnd}t          d| d          | S )zlDepending on the value of raise_unknown, either raise an error or
            return 'unknown'.
            unknowndatazUnknown label type for z: )r   )target_typeinput
input_namer   ys     r   _raise_or_returnz(type_of_target.<locals>._raise_or_returnx  sJ      #	!9!9&0<

f !I5!I!IA!I!IJJJ""r   )r   )sklearn.utils.multiclassr   )r   r   r   r   r   r   s   ```   r   r   r   t  sa    ;;;;;;	# 	# 	# 	# 	# 	# 	# %nQ:>>>,,,r   c              #  ,   K   t          |           V  d S r]   r   )	Estimators    r   _construct_instancesr     s       !),,,,,,,r   rD   Tc          	     H   |rrt          | ||           t          | ||           t          |t                    o|dk    }|du pt          |t                    o|dk    }|s|r|}	n|r|s|}	n||f}	|	S d|v r|                    d          }
nd}
 | j        d|||||
d|S )a  Validate input data and set or check feature names and counts of the input.

        See the original scikit-learn documentation:
        https://scikit-learn.org/stable/modules/generated/sklearn.utils.validation.validate_data.html#sklearn.utils.validation.validate_data
        resetrD   Nensure_all_finiteT)r   r   r   validate_separatelyforce_all_finiter   )_check_n_features_check_feature_namesry   strpop_validate_data)
_estimatorr   r   r   r   skip_check_arrayr`   no_val_Xno_val_youtr   s              r   validate_datar     s     	j!59999 Qe<<<<!!S))Ba?.BHDyOJq#$6$6$O1;OH   ( dJ"f,,#)::.A#B#B  #' ,:, $7!1    r   c               0    |                      ||          S )zHSet the `n_features_in_` attribute, or check against it on an estimator.r   )r   r   r   r   s      r   r   r     s    **1E*:::r   c               0    |                      ||          S )z4Check `input_features` and generate names if needed.r   )r   r   s      r   r   r     s    --au-===r   numeric   )accept_large_sparsedtypeordercopyforce_writeabler   ensure_non_negative	ensure_2dallow_ndensure_min_samplesensure_min_featuresr   r   c                   ddl m} ||}nd}t          j        |          j        }i }d|v r||d<   d|v r||d<    || f|||||||	|
||||d|S )zInput validation on an array, list, sparse matrix or similar.

        Check the original documentation for more details:
        https://scikit-learn.org/stable/modules/generated/sklearn.utils.check_array.html
        r   )check_arrayNTr   r   )accept_sparser   r   r   r   r   r   r   r   r   r   r   )sklearn.utils.validationr   inspect	signature
parameters)arrayr   r   r   r   r   r   r   r   r   r   r   r   r   r   _check_arrayr   check_array_paramsr`   s                      r   r   r     s    . 	IHHHHH(0#$.|<<G 222(7F$% $666,?F()|
' 3-1 3!
 
 
 
 	
r   c                      e Zd ZU dZdZded<   dZded<   dZded<   dZded<   dZ	ded	<   dZ
ded
<   dZded<   dZded<   dZded<   dZded<   dZded<   dS )rO   a5  Tags for the input data.

        Parameters
        ----------
        one_d_array : bool, default=False
            Whether the input can be a 1D array.

        two_d_array : bool, default=True
            Whether the input can be a 2D array. Note that most common
            tests currently run only if this flag is set to ``True``.

        three_d_array : bool, default=False
            Whether the input can be a 3D array.

        sparse : bool, default=False
            Whether the input can be a sparse matrix.

        categorical : bool, default=False
            Whether the input can be categorical.

        string : bool, default=False
            Whether the input can be an array-like of strings.

        dict : bool, default=False
            Whether the input can be a dictionary.

        positive_only : bool, default=False
            Whether the estimator requires positive X.

        allow_nan : bool, default=False
            Whether the estimator supports data with missing values encoded as `np.nan`.

        pairwise : bool, default=False
            This boolean attribute indicates whether the data (`X`),
            :term:`fit` and similar methods consists of pairwise measures
            over samples rather than a feature representation for each
            sample.  It is usually `True` where an estimator has a
            `metric` or `affinity` or `kernel` parameter with value
            'precomputed'. Its primary purpose is to support a
            :term:`meta-estimator` or a cross validation procedure that
            extracts a sub-sample of data intended for a pairwise
            estimator, where the data needs to be indexed on both axes.
            Specifically, this tag is used by
            `sklearn.utils.metaestimators._safe_split` to slice rows and
            columns.
        Fboolr'   Tr(   r)   r   r    r!   r"   r*   r$   r%   r&   N)r   
__module____qualname____doc__r'   __annotations__r(   r)   r   r    r!   r"   r*   r$   r%   r&   r   r   r   rO   rO     s         -	 -	^ "!!!!     #####!!!!!#####		r   rO   c                  d    e Zd ZU dZded<   dZded<   dZded<   dZded<   dZded<   d	Z	ded
<   dS )rP   a  Tags for the target data.

        Parameters
        ----------
        required : bool
            Whether the estimator requires y to be passed to `fit`,
            `fit_predict` or `fit_transform` methods. The tag is ``True``
            for estimators inheriting from `~sklearn.base.RegressorMixin`
            and `~sklearn.base.ClassifierMixin`.

        one_d_labels : bool, default=False
            Whether the input is a 1D labels (y).

        two_d_labels : bool, default=False
            Whether the input is a 2D labels (y).

        positive_only : bool, default=False
            Whether the estimator requires a positive y (only applicable
            for regression).

        multi_output : bool, default=False
            Whether a regressor supports multi-target outputs or a classifier supports
            multi-class multi-output.

        single_output : bool, default=True
            Whether the target can be single-output. This can be ``False`` if the
            estimator supports only multi-output cases.
        r   r1   Fr2   r3   r*   r4   Tr5   N)
r   r   r   r   r   r2   r3   r*   r4   r5   r   r   r   rP   rP   /  s|         	 	: 	""""""""""#####""""""""""""r   rP   c                  8    e Zd ZU dZ ed           Zded<   dS )rR   a  Tags for the transformer.

        Parameters
        ----------
        preserves_dtype : list[str], default=["float64"]
            Applies only on transformers. It corresponds to the data types
            which will be preserved such that `X_trans.dtype` is the same
            as `X.dtype` after calling `transformer.transform(X)`. If this
            list is empty, then the transformer is not expected to
            preserve the data type. The first value in the list is
            considered as the default data type, corresponding to the data
            type of the output when the input data type is not going to be
            preserved.
        c                     dgS )Nfloat64r   r   r   r   <lambda>zTransformerTags.<lambda>f  s    I; r   default_factoryz	list[str]r8   N)r   r   r   r   r   r8   r   r   r   r   rR   rR   U  s@         	 	 &+U;N;N%O%O%OOOOOOOr   rR   c                  >    e Zd ZU dZdZded<   dZded<   dZded<   dS )	rT   ap  Tags for the classifier.

        Parameters
        ----------
        poor_score : bool, default=False
            Whether the estimator fails to provide a "reasonable" test-set
            score, which currently for classification is an accuracy of
            0.83 on ``make_blobs(n_samples=300, random_state=0)``. The
            datasets and values are based on current estimators in scikit-learn
            and might be replaced by something more systematic.

        multi_class : bool, default=True
            Whether the classifier can handle multi-class
            classification. Note that all classifiers support binary
            classification. Therefore this flag indicates whether the
            classifier is a binary-classifier-only or not.

        multi_label : bool, default=False
            Whether the classifier supports multi-label output.
        Fr   r;   Tr>   r?   N)r   r   r   r   r;   r   r>   r?   r   r   r   rT   rT   h  sQ         	 	* !
         !!!!!!!r   rT   c                  0    e Zd ZU dZdZded<   dZded<   dS )rU   a}  Tags for the regressor.

        Parameters
        ----------
        poor_score : bool, default=False
            Whether the estimator fails to provide a "reasonable" test-set
            score, which currently for regression is an R2 of 0.5 on
            ``make_regression(n_samples=200, n_features=10,
            n_informative=1, bias=5.0, noise=20, random_state=42)``. The
            dataset and values are based on current estimators in scikit-learn
            and might be replaced by something more systematic.

        multi_label : bool, default=False
            Whether the regressor supports multilabel output.
        Fr   r;   r?   N)r   r   r   r   r;   r   r?   r   r   r   rU   rU     s@         	 	  !
    !!!!!!!r   rU   c                  "    e Zd ZU dZdZded<   dS )rV   zTags for the sampler.

        Parameters
        ----------
        sample_indices : bool, default=False
            Whether the sampler returns the indices of the samples that were
            selected.
        Fr   rB   N)r   r   r   r   rB   r   r   r   r   rV   rV     s/         	 	  %$$$$$$r   rV   c                      e Zd ZU dZded<   ded<   dZded<   dZd	ed
<   dZded<   dZded<   dZ	ded<   dZ
ded<   dZded<   dZded<    ee          Zded<   dZded<   dS )rX   aF  Tags for the estimator.

        See :ref:`estimator_tags` for more information.

        Parameters
        ----------
        estimator_type : str or None
            The type of the estimator. Can be one of:
            - "classifier"
            - "regressor"
            - "transformer"
            - "clusterer"
            - "outlier_detector"
            - "density_estimator"

        target_tags : :class:`TargetTags`
            The target(y) tags.

        transformer_tags : :class:`TransformerTags` or None
            The transformer tags.

        classifier_tags : :class:`ClassifierTags` or None
            The classifier tags.

        regressor_tags : :class:`RegressorTags` or None
            The regressor tags.

        array_api_support : bool, default=False
            Whether the estimator supports Array API compatible inputs.

        no_validation : bool, default=False
            Whether the estimator skips input-validation. This is only meant for
            stateless and dummy transformers!

        non_deterministic : bool, default=False
            Whether the estimator is not deterministic given a fixed ``random_state``.

        requires_fit : bool, default=True
            Whether the estimator requires to be fitted before calling one of
            `transform`, `predict`, `predict_proba`, or `decision_function`.

        _skip_test : bool, default=False
            Whether to skip common tests entirely. Don't use this unless
            you have a *very good* reason.

        input_tags : :class:`InputTags`
            The input data(X) tags.
        z
str | NonerH   rP   rI   NzTransformerTags | NonerJ   zClassifierTags | NonerK   zRegressorTags | NonerL   Fr   rC   rD   rE   TrF   rG   r   rO   rN   SamplerTags | NonerM   )r   r   r   r   r   rJ   rK   rL   rC   rD   rE   rF   rG   r   rO   rN   rM   r   r   r   rX   rX     s         /	 /	b 	#"""377777155555/33333"'''''#####"'''''!!!!! 
     %i @ @ @
@@@@+///////r   rX   c                z    | j         j        fd}|| j         _        t          j        ||           | _        | S )Nc                L     |           }|                     di           |S )zEInstance-level _more_tags that combines class tags with _xfail_checks_xfail_checks)update)selftagsexpected_failed_checksoriginal_class_more_tagss     r   patched_instance_more_tagsz6_patched_more_tags.<locals>.patched_instance_more_tags  s2     ,+D11DKK*@ABBBKr   )r   
_more_tagstypes
MethodType)r   r  r  r  s    ` @r   _patched_more_tagsr    sX    #,#6#A 	 	 	 	 	 	 *D	&$/0JIVV	r   warnraise)legacyr  on_skipon_failcallbackr  r   r  dict[str, str] | Noner  Literal['warn'] | Noner  Literal['raise', 'warn'] | Noner  Callable | Nonec               D    ddl m}  |t          | |          |          S )Nr   )check_estimator)generate_only)sklearn.utils.estimator_checksr  r  )r   r   r  r  r  r  r  r  s           r   r  r    sA     	CBBBBBy*@AA'
 
 
 	
r   )r  r  c               B    ddl m} fd| D             }  ||           S )Nr   )parametrize_with_checksc                B    g | ]}t          | |                    S r   )r  )ro   r   r  s     r   rq   z+parametrize_with_checks.<locals>.<listcomp>  s?     
 
 
 y*@*@*K*KLL
 
 
r   )r!  r#  )
estimatorsr  r  r#  s     ` r   r#  r#    sS     	KJJJJJ
 
 
 
'
 
 


 '&z222r   )rT   rO   rU   rX   rP   rR   c                      e Zd ZU dZded<   dS )rO   Tr   r&   N)r   r   r   r&   r   r   r   r   rO   rO   #  s#         	r   c                      e Zd ZU dZded<   dS )rV   Fr   rB   N)r   r   r   rB   r   r   r   r   rV   rV   '  s#         $$$$$$$r   c                      e Zd ZU dZded<   dS )rX   Nr  rM   )r   r   r   rM   r   r   r   r   rX   rX   +  s#         +///////r   )r   )r  r#  r   )r   r   r   r   r]   )r   )rD   rD   TFF)Fr   )NF)
r  r   r  r  r  r  r  r  r  r  )r  r   r  r  )Yr   
__future__r   rc   r   platformr   r  dataclassesr   r   typingr   r   sklearnsklearn.utils.fixesr   __version__base_versionsklearn_versionr   r   r   rg   rj   sklearn.baserk   allr   r   r   r   sklearn.utils.metadata_routingr   sklearn.utilsr   r   r   r   r   r   r   r   r   machiner   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   sklearn.utils._chunkingsklearn.utils._indexingsklearn.utils._masksklearn.utils._missing$sklearn.utils._optional_dependenciessklearn.utils._user_interfacesklearn.utils.extmathr!  r   r   r   r   r   r   r   rO   rP   rR   rT   rU   rV   rX   r  r  r#  -sklearn.utils._test_common.instance_generatorr   r   r   r   <module>r?     sS
  	 	 # " " " " "       



  ( ( ( ( ( ( ( ( $ $ $ $ $ $ $ $  - - - - - --g.A B B OPP  > > ><F F F FZ ]]5))))  6 6 6 6 *)))))?????? ]]5)))))-# #% #% #% #%JK K K  $+ + + +               ]]5))))                  BAAAAAx!!%99H                                 <;;;;;;                                                  BAAAAA                 :99999 ]]5))))BBBBBB-% - - - - -"- - - 
!( ( ( (T; ; ;> > > 4
 !!!4
 4
 4
 4
 4
n Y##""##:  :  :  :  :  :  :  $#: x Y##""#### ## ## ## ## ## ## $###J Y##""##P P P P P P P $#P$ Y##""##" " " " " " " $#"4 Y##""##" " " " " " " $#"( Y##""##
% 
% 
% 
% 
% 
% 
% $#
% Y##""##=0 =0 =0 =0 =0 =0 =0 $#=0~  " 
 8<*03:$(
 
 
 
 
 
* 26	3 3 3 3 3 3 3 3&                Y##""##    I   $# Y##""##% % % % % % % $#% Y##""##0 0 0 0 0t 0 0 $#0             877777             r   