Ë
    ÜÍ:j‹h  ã                   óÄ   — d dl Z d dlmZ d dlZd dlmZmZ d dlm	Z	 d dl
mZmZ d dlmZmZ d dlmZmZmZmZmZ d dlmZmZ d d	lmZ d d
lmZmZmZmZ  G d„ dee	«      Z y)é    N)ÚReal)ÚOneToOneFeatureMixinÚ_fit_context)Ú_BaseEncoder)Ú_fit_encoding_fastÚ_fit_encoding_fast_auto_smooth)ÚBunchÚ	indexable)ÚMetadataRouterÚMethodMappingÚ_raise_for_paramsÚ_routing_enabledÚprocess_routing)ÚIntervalÚ
StrOptions)Útype_of_target)Ú_check_feature_names_inÚ_check_yÚcheck_consistent_lengthÚcheck_is_fittedc            	       ó,  ‡ — e Zd ZU dZ edh«      eg eh d£«      g edh«       eeddd¬«      gdgd	 ed
h«      gd ed
h«      gdœZe	e
d<   	 	 	 	 	 	 dd„Z ed¬«      d„ «       Z ed¬«      d„ «       Zd„ Zd„ Zd„ Zd„ Zd„ Zdd„Zd„ Zˆ fd„Zˆ xZS )ÚTargetEncoderu{#  Target Encoder for regression and classification targets.

    Each category is encoded based on a shrunk estimate of the average target
    values for observations belonging to the category. The encoding scheme mixes
    the global target mean with the target mean conditioned on the value of the
    category (see [MIC]_).

    When the target type is "multiclass", encodings are based
    on the conditional probability estimate for each class. The target is first
    binarized using the "one-vs-all" scheme via
    :class:`~sklearn.preprocessing.LabelBinarizer`, then the average target
    value for each class and each category is used for encoding, resulting in
    `n_features` * `n_classes` encoded output features.

    :class:`TargetEncoder` considers missing values, such as `np.nan` or `None`,
    as another category and encodes them like any other category. Categories
    that are not seen during :meth:`fit` are encoded with the target mean, i.e.
    `target_mean_`.

    For a demo on the importance of the `TargetEncoder` internal :term:`cross fitting`,
    see
    :ref:`sphx_glr_auto_examples_preprocessing_plot_target_encoder_cross_val.py`.
    For a comparison of different encoders, refer to
    :ref:`sphx_glr_auto_examples_preprocessing_plot_target_encoder.py`. Read
    more in the :ref:`User Guide <target_encoder>`.

    .. note::
        `fit(X, y).transform(X)` does not equal `fit_transform(X, y)` because a
        :term:`cross fitting` scheme is used in `fit_transform` for encoding.
        See the :ref:`User Guide <target_encoder>` for details.

    .. versionadded:: 1.3

    Parameters
    ----------
    categories : "auto" or list of shape (n_features,) of array-like, default="auto"
        Categories (unique values) per feature:

        - `"auto"` : Determine categories automatically from the training data.
        - list : `categories[i]` holds the categories expected in the i-th column. The
          passed categories should not mix strings and numeric values within a single
          feature, and should be sorted in case of numeric values.

        The used categories are stored in the `categories_` fitted attribute.

    target_type : {"auto", "continuous", "binary", "multiclass"}, default="auto"
        Type of target.

        - `"auto"` : Type of target is inferred with
          :func:`~sklearn.utils.multiclass.type_of_target`.
        - `"continuous"` : Continuous target
        - `"binary"` : Binary target
        - `"multiclass"` : Multiclass target

        .. note::
            The type of target inferred with `"auto"` may not be the desired target
            type used for modeling. For example, if the target consisted of integers
            between 0 and 100, then :func:`~sklearn.utils.multiclass.type_of_target`
            will infer the target as `"multiclass"`. In this case, setting
            `target_type="continuous"` will specify the target as a regression
            problem. The `target_type_` attribute gives the target type used by the
            encoder.

        .. versionchanged:: 1.4
           Added the option 'multiclass'.

    smooth : "auto" or float, default="auto"
        The amount of mixing of the target mean conditioned on the value of the
        category with the global target mean. A larger `smooth` value will put
        more weight on the global target mean.
        If `"auto"`, then `smooth` is set to an empirical Bayes estimate.

    cv : int, cross-validation generator or an iterable, default=None
        Determines the splitting strategy used in the internal :term:`cross fitting`
        during :meth:`fit_transform`. Splitters where each sample index doesn't appear
        in the validation fold exactly once, raise a `ValueError`.
        Possible inputs for cv are:

        - `None`, to use a 5-fold cross-validation chosen internally based on
            `target_type`,
        - integer, to specify the number of folds for the cross-validation chosen
            internally based on `target_type`,
        - :term:`CV splitter` that does not repeat samples across validation folds,
        - an iterable yielding (train, test) splits as arrays of indices.

        For integer/None inputs, if `target_type` is `"continuous"`, :class:`KFold` is
        used, otherwise :class:`StratifiedKFold` is used.

        Refer :ref:`User Guide <cross_validation>` for more information on
        cross-validation strategies.

        .. versionchanged:: 1.9
            Cross-validation generators and iterables can also be passed as `cv`.

    shuffle : bool, default=True
        Whether to shuffle the data in :meth:`fit_transform` before splitting into
        folds. Note that the samples within each split will not be shuffled. Only
        applies if `cv` is an int or `None`. If `cv` is a cross-validation generator or
        an iterable, `shuffle` is ignored.

        .. deprecated:: 1.9
            `shuffle` is deprecated and will be removed in 1.11. Pass a cross-validation
            generator as `cv` argument to specify the shuffling instead.

    random_state : int, RandomState instance or None, default=None
        When `shuffle` is True, `random_state` affects the ordering of the
        indices, which controls the randomness of each fold. Otherwise, this
        parameter has no effect.
        Pass an int for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

        .. deprecated:: 1.9
            `random_state` is deprecated and will be removed in 1.11. Pass a
            cross-validation generator as `cv` argument to specify the random state of
            the shuffling instead.

    Attributes
    ----------
    encodings_ : list of shape (n_features,) or (n_features * n_classes) of                     ndarray
        Encodings learnt on all of `X`.
        For feature `i`, `encodings_[i]` are the encodings matching the
        categories listed in `categories_[i]`. When `target_type_` is
        "multiclass", the encoding for feature `i` and class `j` is stored in
        `encodings_[j + (i * len(classes_))]`. E.g., for 2 features (f) and
        3 classes (c), encodings are ordered:
        f0_c0, f0_c1, f0_c2, f1_c0, f1_c1, f1_c2,

    categories_ : list of shape (n_features,) of ndarray
        The categories of each input feature determined during fitting or
        specified in `categories`
        (in order of the features in `X` and corresponding with the output
        of :meth:`transform`).

    target_type_ : str
        Type of target.

    target_mean_ : float
        The overall mean of the target. This value is only used in :meth:`transform`
        to encode categories.

    n_features_in_ : int
        Number of features seen during :term:`fit`.

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Defined only when `X`
        has feature names that are all strings.

    classes_ : ndarray or None
        If `target_type_` is 'binary' or 'multiclass', holds the label for each class,
        otherwise `None`.

    See Also
    --------
    OrdinalEncoder : Performs an ordinal (integer) encoding of the categorical features.
        Contrary to TargetEncoder, this encoding is not supervised. Treating the
        resulting encoding as a numerical features therefore lead arbitrarily
        ordered values and therefore typically lead to lower predictive performance
        when used as preprocessing for a classifier or regressor.
    OneHotEncoder : Performs a one-hot encoding of categorical features. This
        unsupervised encoding is better suited for low cardinality categorical
        variables as it generate one new feature per unique category.

    References
    ----------
    .. [MIC] :doi:`Micci-Barreca, Daniele. "A preprocessing scheme for high-cardinality
       categorical attributes in classification and prediction problems"
       SIGKDD Explor. Newsl. 3, 1 (July 2001), 27â€“32. <10.1145/507533.507538>`

    Examples
    --------
    With `smooth="auto"`, the smoothing parameter is set to an empirical Bayes estimate:

    >>> import numpy as np
    >>> from sklearn.preprocessing import TargetEncoder
    >>> X = np.array([["dog"] * 20 + ["cat"] * 30 + ["snake"] * 38], dtype=object).T
    >>> y = [90.3] * 5 + [80.1] * 15 + [20.4] * 5 + [20.1] * 25 + [21.2] * 8 + [49] * 30
    >>> enc_auto = TargetEncoder(smooth="auto")
    >>> X_trans = enc_auto.fit_transform(X, y)

    >>> # A high `smooth` parameter puts more weight on global mean on the categorical
    >>> # encodings:
    >>> enc_high_smooth = TargetEncoder(smooth=5000.0).fit(X, y)
    >>> enc_high_smooth.target_mean_
    np.float64(44.3)
    >>> enc_high_smooth.encodings_
    [array([44.1, 44.4, 44.3])]

    >>> # On the other hand, a low `smooth` parameter puts more weight on target
    >>> # conditioned on the value of the categorical:
    >>> enc_low_smooth = TargetEncoder(smooth=1.0).fit(X, y)
    >>> enc_low_smooth.encodings_
    [array([21, 80.8, 43.2])]
    Úauto>   r   ÚbinaryÚ
continuousÚ
multiclassr   NÚleft)ÚclosedÚ	cv_objectÚbooleanÚ
deprecatedÚrandom_state)Ú
categoriesÚtarget_typeÚsmoothÚcvÚshuffler"   Ú_parameter_constraintsc                 óX   — || _         || _        || _        || _        || _        || _        y ©N)r#   r%   r$   r&   r'   r"   )Úselfr#   r$   r%   r&   r'   r"   s          úz/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/sklearn/preprocessing/_target_encoder.pyÚ__init__zTargetEncoder.__init__ï   s0   € ð %ˆŒØˆŒØ&ˆÔØˆŒØˆŒØ(ˆÕó    T)Úprefer_skip_nested_validationc                 ó*   — | j                  ||«       | S )a  Fit the :class:`TargetEncoder` to X and y.

        It is discouraged to use this method because it can introduce data leakage.
        Use `fit_transform` on training data instead.

        .. note::
            `fit(X, y).transform(X)` does not equal `fit_transform(X, y)` because a
            :term:`cross fitting` scheme is used in `fit_transform` for encoding.
            See the :ref:`User Guide <target_encoder>` for details.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            The data to determine the categories of each feature.

        y : array-like of shape (n_samples,)
            The target data used to encode the categories.

        Returns
        -------
        self : object
            Fitted encoder.
        )Ú_fit_encodings_all)r+   ÚXÚys      r,   ÚfitzTargetEncoder.fitÿ   s   € ð2 	×Ñ  1Ô%Øˆr.   c           	      ó¾  — ddl m}m}m}m} ddlm} t        || d«       | j                  ||«      \  }	}
}}| j                  dk7  s| j                  dk7  rt        j                  dt        «       | j                  dk(  rdn| j                  }d|i}| j                  dk7  r| j                  |d	<    || j                  |fd
| j                  dk7  i|¤Ž}t!        «       r*|d   �t#        |||d   «      \  }}|d<   t%        | dfi |¤Ž}nt'        t'        i ¬«      ¬«      }t)        |||||f«      s‚t+        j,                  |j.                  d   «      } |j0                  ||fi |j2                  j0                  ¤ŽD ]  \  }}||xx   dz  cc<   Œ t+        j4                  |dk(  «      st7        d«      ‚| j                  dk(  rXt+        j8                  |	j.                  d   |	j.                  d   t;        | j<                  «      z  ft*        j>                  ¬«      }n%t+        j@                  |	t*        j>                  ¬«      } |j0                  ||fi |j2                  j0                  ¤ŽD ]y  \  }}|	|dd…f   ||   }}t+        jB                  |d¬«      }| j                  dk(  r| jE                  ||||«      }n| jG                  ||||«      }| jI                  ||	|
 |||«       Œ{ |S )a—  Fit :class:`TargetEncoder` and transform `X` with the target encoding.

        This method uses a :term:`cross fitting` scheme to prevent target leakage
        and overfitting in downstream predictors. It is the recommended method for
        encoding training data.

        .. note::
            `fit(X, y).transform(X)` does not equal `fit_transform(X, y)` because a
            :term:`cross fitting` scheme is used in `fit_transform` for encoding.
            See the :ref:`User Guide <target_encoder>` for details.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            The data to determine the categories of each feature.

        y : array-like of shape (n_samples,)
            The target data used to encode the categories.

        **params : dict
            Parameters to route to the internal CV object.

            Can only be used in conjunction with a cross-validation generator as CV
            object.

            For instance, `groups` (array-like of shape `(n_samples,)`) can be routed to
            a CV splitter that accepts `groups`, such as :class:`GroupKFold` or
            :class:`StratifiedGroupKFold`.

            .. versionadded:: 1.9
                Only available if `enable_metadata_routing=True`, which can be
                set by using ``sklearn.set_config(enable_metadata_routing=True)``.
                See :ref:`Metadata Routing User Guide <metadata_routing>` for
                more details.

        Returns
        -------
        X_trans : ndarray of shape (n_samples, n_features) or                     (n_samples, (n_features * n_classes))
            Transformed input.
        r   )Ú
GroupKFoldÚKFoldÚStratifiedGroupKFoldÚStratifiedKFold)Úcheck_cvÚfit_transformr!   zÚ`TargetEncoder.shuffle` and `TargetEncoder.random_state` are deprecated in version 1.9 and will be removed in version 1.11. Pass a cross-validation generator as `cv` argument to specify the shuffling behaviour instead.Tr'   r"   Ú
classifierr   ÚgroupsN)Úsplit)Úsplitteré   z½Validation indices from `cv` must cover each sample index exactly once with no overlap. Pass a splitter with non-overlapping validation folds as `cv` or refer to the docs for other options.r   ©Údtype©Úaxis)%Úsklearn.model_selectionr6   r7   r8   r9   Úsklearn.model_selection._splitr:   r   r1   r'   r"   ÚwarningsÚwarnÚFutureWarningr&   Útarget_type_r   r
   r   r	   Ú
isinstanceÚnpÚzerosÚshaper>   r?   ÚallÚ
ValueErrorÚemptyÚlenÚclasses_Úfloat64Ú
empty_likeÚmeanÚ_fit_encoding_multiclassÚ"_fit_encoding_binary_or_continuousÚ_transform_X_ordinal)r+   r2   r3   Úparamsr6   r7   r8   r9   r:   Ú	X_ordinalÚX_known_maskÚ	y_encodedÚn_categoriesr'   Ú	cv_kwargsr&   Úrouted_paramsÚ
seen_countÚ_Útest_idxÚX_outÚ	train_idxÚX_trainÚy_trainÚy_train_meanÚ	encodingss                             r,   r;   zTargetEncoder.fit_transform  sö  € ÷X	
ó 	
õ 	<ä˜& $¨Ô8à;?×;RÑ;RÐSTÐVWÓ;XÑ8ˆ	�< ¨Lð �<‰<˜<Ò'¨4×+<Ñ+<ÀÒ+LÜ�M‰Mð%ô ôð Ÿ,™,¨,Ò6‘$¸D¿L¹LˆØ Ð(ˆ	Ø×Ñ Ò,Ø(,×(9Ñ(9ˆI�nÑ%ñ Ø�G‰GØñ
ð ×(Ñ(¨LÑ8ð
ð ñ	
ˆô ÔØ�hÑÐ+Ü)2°1°a¸ÀÑ9IÓ)JÑ&��1�f˜XÑ&Ü+¨D°/ÑLÀVÑL‰Mä!¬5°r¬?Ô;ˆMô
 Ø�˜U OÐ5IÐJô
ô Ÿ™ !§'¡'¨!¡*Ó-ˆJØ'˜rŸx™x¨¨1ÑM°×0FÑ0F×0LÑ0LÑMò *‘��8Ø˜8Ó$¨Ñ)Ô$ð*ä—6‘6˜*¨™/Ô*Ü ðWóð ð ×Ñ Ò,Ü—H‘HØ—‘ Ñ# Y§_¡_°QÑ%7¼#¸d¿m¹mÓ:LÑ%LÐMÜ—j‘jô‰Eô
 —M‘M )´2·:±:Ô>ˆEà#+ 2§8¡8¨A¨qÑ#Q°M×4JÑ4J×4PÑ4PÑ#Qò 	ÑˆI�xØ(¨²A¨Ñ6¸	À)Ñ8L�WˆGÜŸ7™7 7°Ô3ˆLà× Ñ  LÒ0Ø ×9Ñ9ØØØ Ø ó	‘	ð !×CÑCØØØ Ø ó	�	ð ×%Ñ%ØØØ�ØØØõð%	ð4 ˆr.   c                 ó´  — | j                  |dd¬«      \  }}| j                  dk(  rXt        j                  |j                  d   |j                  d   t        | j                  «      z  ft        j                  ¬«      }n%t        j                  |t        j                  ¬«      }| j                  ||| t        d«      | j                  | j                  «       |S )	a  Transform X with the target encoding.

        This method internally uses the `encodings_` attribute learnt during
        :meth:`TargetEncoder.fit_transform` to transform test data.

        .. note::
            `fit(X, y).transform(X)` does not equal `fit_transform(X, y)` because a
            :term:`cross fitting` scheme is used in `fit_transform` for encoding.
            See the :ref:`User Guide <target_encoder>` for details.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            The data to determine the categories of each feature.

        Returns
        -------
        X_trans : ndarray of shape (n_samples, n_features) or                     (n_samples, (n_features * n_classes))
            Transformed input.
        Úignoreú	allow-nan©Úhandle_unknownÚensure_all_finiter   r   r@   rA   N)Ú
_transformrJ   rL   rQ   rN   rR   rS   rT   rU   rY   ÚsliceÚ
encodings_Útarget_mean_)r+   r2   r[   r\   rd   s        r,   Ú	transformzTargetEncoder.transform¨  s½   € ð, #'§/¡/Ø˜h¸+ð #2ó #
Ñˆ	�<ð
 ×Ñ Ò,Ü—H‘HØ—‘ Ñ# Y§_¡_°QÑ%7¼#¸d¿m¹mÓ:LÑ%LÐMÜ—j‘jô‰Eô
 —M‘M )´2·:±:Ô>ˆEà×!Ñ!ØØØˆMÜ�$‹KØ�O‰OØ×Ñô	
ð ˆr.   c                 ó¦  — ddl m}m} t        ||«       | j	                  |dd¬«       | j
                  dk(  r-d}t        |d¬	«      }||vrt        d
|›d|› d�«      ‚|| _        n| j
                  | _        d| _	        | j                  dk(  r* |«       }|j                  |«      }|j                  | _	        nG| j                  dk(  r* |«       }|j                  |«      }|j                  | _	        nt        |d| ¬«      }t        j                  |d¬«      | _        | j                  |dd¬«      \  }	}
t        j                   d„ | j"                  D «       t        j$                  t'        | j"                  «      ¬«      }| j                  dk(  r| j)                  |	||| j                  «      }n| j+                  |	||| j                  «      }|| _        |	|
||fS )z(Fit a target encoding with all the data.r   )ÚLabelBinarizerÚLabelEncoderrk   rl   rm   r   )r   r   r   r3   )Ú
input_namez3Unknown label type: Target type was inferred to be z. Only z are supported.Nr   r   T)Ú	y_numericÚ	estimatorrC   c              3   ó2   K  — | ]  }t        |«      –— Œ y ­wr*   )rR   )Ú.0Úcategory_for_features     r,   ú	<genexpr>z3TargetEncoder._fit_encodings_all.<locals>.<genexpr>ü  s   è ø€ ÒTÐ+?ŒSÐ%×&ÑTùs   ‚)rB   Úcount)Úsklearn.preprocessingrv   rw   r   Ú_fitr$   r   rP   rJ   rS   r;   r   rL   rV   rs   rp   ÚfromiterÚcategories_Úint64rR   rW   rX   rr   )r+   r2   r3   rv   rw   Úaccepted_target_typesÚinferred_type_of_targetÚlabel_encoderÚlabel_binarizerr[   r\   r^   ri   s                r,   r1   z TargetEncoder._fit_encodings_allÕ  sÜ  € ÷ 	Gä  1Ô%Ø�	‰	�! HÀˆ	ÔLà×Ñ˜vÒ%Ø$JÐ!Ü&4°QÀ3Ô&GÐ#Ø&Ð.CÑCÜ ØIØ.Ð1°Ð9NÐ8Oð P!ð!óð ð
 !8ˆDÕà $× 0Ñ 0ˆDÔàˆŒØ×Ñ Ò(Ù(›NˆMØ×+Ñ+¨AÓ.ˆAØ)×2Ñ2ˆD�MØ×Ñ ,Ò.Ù,Ó.ˆOØ×-Ñ-¨aÓ0ˆAØ+×4Ñ4ˆD�Mä˜ d°dÔ;ˆAäŸG™G A¨AÔ.ˆÔà"&§/¡/Ø˜h¸+ð #2ó #
Ñˆ	�<ô —{‘{ÙTÀ4×CSÑCSÔTÜ—(‘(Ü�d×&Ñ&Ó'ô
ˆð
 ×Ñ Ò,Ø×5Ñ5ØØØØ×!Ñ!ó	‰Ið ×?Ñ?ØØØØ×!Ñ!ó	ˆIð $ˆŒà˜,¨¨<Ð7Ð7r.   c                 ó¢   — | j                   dk(  r&t        j                  |«      }t        |||||«      }|S t	        |||| j                   |«      }|S )zLearn target encodings.r   )r%   rL   Úvarr   r   )r+   r[   r3   r^   Útarget_meanÚ
y_varianceri   s          r,   rX   z0TargetEncoder._fit_encoding_binary_or_continuous  se   € ð �;‰;˜&Ò ÜŸ™ ›ˆJÜ6ØØØØØóˆIð Ðô +ØØØØ—‘ØóˆIð Ðr.   c                 ó(  ‡‡— | j                   Št        | j                  «      Šg }t        ‰«      D ]3  }|dd…|f   }| j	                  |||||   «      }|j                  |«       Œ5 ˆˆfd„t        ‰«      D «       }	|	D �
cg c]  }
||
   ‘Œ	 c}
S c c}
w )aD  Learn multiclass encodings.

        Learn encodings for each class (c) then reorder encodings such that
        the same features (f) are grouped together. `reorder_index` enables
        converting from:
        f0_c0, f1_c0, f0_c1, f1_c1, f0_c2, f1_c2
        to:
        f0_c0, f0_c1, f0_c2, f1_c0, f1_c1, f1_c2
        Nc              3   óL   •K  — | ]  }t        |‰‰z  ‰«      D ]  }|–— Œ Œ y ­wr*   )Úrange)r|   ÚstartÚidxÚ	n_classesÚ
n_featuress      €€r,   r~   z9TargetEncoder._fit_encoding_multiclass.<locals>.<genexpr>A  s<   øè ø€ ò 
àÜ˜U Y°Ñ%;¸jÓIò
ð ô ð
Øñ
ùs   ƒ!$)Ún_features_in_rR   rS   r�   rX   Úextend)r+   r[   r3   r^   r‹   ri   ÚiÚy_classÚencodingÚreorder_indexr‘   r’   r“   s              @@r,   rW   z&TargetEncoder._fit_encoding_multiclass)  s¢   ù€ ð ×(Ñ(ˆ
Ü˜Ÿ™Ó&ˆ	àˆ	Ü�yÓ!ò 	'ˆAØš˜1˜‘gˆGØ×>Ñ>ØØØØ˜A‘ó	ˆHð ×Ñ˜XÕ&ð	'ô
ä˜zÓ*ô
ˆð
 +8Ö8 3�	˜#“Ò8Ð8ùÒ8s   Â Bc                 ó(  — | j                   dk(  rSt        | j                  «      }t        |«      D ]/  \  }}	||z  }
||z  }|	|||
f      |||f<   ||   ||dd…|
f   |f<   Œ1 yt        |«      D ]"  \  }}	|	|||f      |||f<   |||dd…|f   |f<   Œ$ y)aù  Transform X_ordinal using encodings.

        In the multiclass case, `X_ordinal` and `X_unknown_mask` have column
        (axis=1) size `n_features`, while `encodings` has length of size
        `n_features * n_classes`. `feat_idx` deals with this by repeating
        feature indices by `n_classes` E.g., for 3 features, 2 classes:
        0,0,1,1,2,2

        Additionally, `target_mean` is of shape (`n_classes`,) so `mean_idx`
        cycles through 0 to `n_classes` - 1, `n_features` times.
        r   N)rJ   rR   rS   Ú	enumerate)r+   rd   r[   ÚX_unknown_maskÚrow_indicesri   r‹   r’   Úe_idxr˜   Úfeat_idxÚmean_idxs               r,   rY   z"TargetEncoder._transform_X_ordinalH  sÛ   € ð( ×Ñ Ò,Ü˜DŸM™MÓ*ˆIÜ#,¨YÓ#7ò R‘��xà  IÑ-�à  9Ñ,�Ø,4°Y¸{ÈHÐ?TÑ5UÑ,V��k 5Ð(Ñ)Ø<GÈÑ<Q��n¢Q¨ [Ñ1°5Ð8Ò9ñRô $-¨YÓ#7ò E‘��xØ,4°Y¸{ÈEÐ?QÑ5RÑ,S��k 5Ð(Ñ)Ø9D��n¢Q¨ XÑ.°Ð5Ò6ñEr.   c                 óä   — t        | d«       t        | |«      }| j                  dk(  rB|D ��cg c]  }| j                  D ]	  }|› d|› �‘Œ Œ }}}t	        j
                  |t        ¬«      S |S c c}}w )a“  Get output feature names for transformation.

        Parameters
        ----------
        input_features : array-like of str or None, default=None
            Not used, present here for API consistency by convention.

        Returns
        -------
        feature_names_out : ndarray of str objects
            Transformed feature names. `feature_names_in_` is used unless it is
            not defined, in which case the following input feature names are
            generated: `["x0", "x1", ..., "x(n_features_in_ - 1)"]`.
            When `type_of_target_` is "multiclass" the names are of the format
            '<feature_name>_<class_name>'.
        r”   r   rb   rA   )r   r   rJ   rS   rL   ÚasarrayÚobject)r+   Úinput_featuresÚfeature_namesÚfeature_nameÚ
class_names        r,   Úget_feature_names_outz#TargetEncoder.get_feature_names_outj  sŠ   € ô" 	˜Ð.Ô/Ü/°°nÓEˆØ×Ñ Ò,ð %2÷à Ø"&§-¡-òð ð  �.  * Ò.ðØ.ðˆMñ ô
 —:‘:˜m´6Ô:Ð:à Ð ùós   ­A,c                 óŠ   — t        | ¬«      }|j                  | j                  t        «       j                  dd¬«      ¬«       |S )aj  Get metadata routing of this object.

        Please check :ref:`User Guide <metadata_routing>` on how the routing
        mechanism works.

        .. versionadded:: 1.9

        Returns
        -------
        routing : MetadataRouter
            A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating
            routing information.
        )Úownerr;   r>   )ÚcallerÚcallee)r?   Úmethod_mapping)r   Úaddr&   r   )r+   Úrouters     r,   Úget_metadata_routingz"TargetEncoder.get_metadata_routing‡  sD   € ô   dÔ+ˆà�
‰
ð —W‘WÜ(›?×.Ñ.°oÈgÐ.ÓVð 	ô 	
ð ˆr.   c                 óF   •— t         ‰| �  «       }d|j                  _        |S )NT)ÚsuperÚ__sklearn_tags__Útarget_tagsÚrequired)r+   ÚtagsÚ	__class__s     €r,   r³   zTargetEncoder.__sklearn_tags__¢  s#   ø€ Ü‰wÑ'Ó)ˆØ$(ˆ×ÑÔ!Øˆr.   )r   r   r   é   r!   r!   r*   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úlistr   r   r(   ÚdictÚ__annotations__r-   r   r4   r;   rt   r1   rX   rW   rY   r¨   r°   r³   Ú__classcell__)r·   s   @r,   r   r   !   sò   ø… ñAñH " 6 (Ó+¨TÐ2Ù"Ò#QÓRÐSÙ˜v˜hÓ'©°$¸¸4ÈÔ)OÐPØˆmØ™z¨<¨.Ó9Ð:Ø'©°\°NÓ)CÐDñ$Ð˜Dó ð ØØØØØ!ó)ñ  °Ô5ñó 6ðñ6 °Ô5ñJó 6ðJòX+òZ;8òzò.9ò> EóD!ò:÷6ð r.   r   )!rG   Únumbersr   ÚnumpyrL   Úsklearn.baser   r   Úsklearn.preprocessing._encodersr   Ú*sklearn.preprocessing._target_encoder_fastr   r   Úsklearn.utilsr	   r
   Ú sklearn.utils._metadata_requestsr   r   r   r   r   Úsklearn.utils._param_validationr   r   Úsklearn.utils.multiclassr   Úsklearn.utils.validationr   r   r   r   r   © r.   r,   ú<module>rÌ      sN   ðó Ý ã ç ;Ý 8÷÷ +÷õ ÷ AÝ 3÷ó ôD
Ð(¨,õ D
r.   