ó
    Ñ]ji ã                   ó  • S SK r S SKrS SK Jr  S SKrS SKJr  S SKJrJ	r	J
r
Jr  S SKJrJr  S SKJrJrJrJr  S SKJr  S SKJr  S S	KJrJrJr  S S
KJr  S SKJrJ r J!r!  SS/r" " S S\
\5      r# " S S\#5      r$ " S S\	\#5      r%g)é    N)ÚIntegral)Úsparse)ÚBaseEstimatorÚOneToOneFeatureMixinÚTransformerMixinÚ_fit_context)Ú_safe_indexingÚcheck_array)Ú_check_unknownÚ_encodeÚ_get_countsÚ_unique)Ú	_get_mask)Úis_scalar_nan)ÚIntervalÚ
RealNotIntÚ
StrOptions)Ú_get_output_config)Ú_check_feature_names_inÚcheck_is_fittedÚvalidate_dataÚOneHotEncoderÚOrdinalEncoderc                   ó‚   ^ • \ rS rSrSrSS jr    SS jr    SS jr\S 5       r	S r
S rS	 rS
 rU 4S jrSrU =r$ )Ú_BaseEncoderé    za
Base class for encoders that includes the code to categorize and
transform the input features.

c                 ó®  • [        US5      (       a  [        USS5      S:X  de  [        USUS9n[        US5      (       dD  [        R                  " UR
                  [        R                  5      (       a  [        U[        US9nOUnSnOUnUR                  u  pV/ n[        U5       H*  n[        XS	S
9n	[        U	SSUS9n	UR                  U	5        M,     XuU4$ )a�  
Perform custom check_array:
- convert list of strings to object dtype
- check for missing values for object dtype data (check_array does
  not do that)
- return list of features (arrays): this list of features is
  constructed feature by feature to preserve the data types
  of pandas DataFrame columns, as otherwise information is lost
  and cannot be used, e.g. for the `categories_` attribute.

ÚilocÚndimr   é   N)ÚdtypeÚensure_all_finiter!   Fé   )ÚindicesÚaxis)Ú	ensure_2dr!   r"   )ÚhasattrÚgetattrr
   ÚnpÚ
issubdtyper!   Ústr_ÚobjectÚshapeÚranger	   Úappend)
ÚselfÚXr"   ÚX_tempÚneeds_validationÚ	n_samplesÚ
n_featuresÚ	X_columnsÚiÚXis
             Ú\/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sklearn/preprocessing/_encoders.pyÚ_check_XÚ_BaseEncoder._check_X'   sÔ   € ô ˜˜6×"Ñ"¤w¨q°&¸!Ó'<ÀÓ'Aä  ¨$ÐBSÑTˆFÜ˜1˜g×&Ñ&¬2¯=ª=¸¿¹ÄrÇwÁw×+OÑ+OÜ ¬ÐCTÑU‘à�Ø$Ñð  1Ðà !§¡Ñˆ	Øˆ	ä�zÖ"ˆAÜ °1Ñ5ˆBÜØ˜e¨4ÐCSñˆBð ×Ñ˜RÖ ñ #ð  ZÐ/Ð/ó    c                 ó   • U R                  5         [        XSSS9  U R                  XS9u  pgnX€l        U R                  S:w  a$  [        U R                  5      U:w  a  [        S5      e/ U l        / n	U=(       d    U R                  n
[        U5       GHp  nXk   nU R                  S:X  a+  [        XÊS9nU
(       a  Uu  pïU	R                  U5        GOUnGO[        R                  " UR                  [        R                  5      (       a  [         nOUR                  n[        R"                  " U R                  U   US9nUR                  [         :X  a\  [%        US   [&        5      (       aD  UR                  R(                  S	:w  a*  S
U S[+        US   5      R,                   S3n[        U5      eUS S  H$  n[/        U5      (       d  M  [        SU SU 35      e   UR0                  [        [        U5      5      :w  a  S
U S3n[        U5      eUR                  R(                  S;  ai  [        R2                  " U5      nSn[        R4                  " US   5      (       a  SOS n[        R6                  " US U US U :g  5      (       a  [        U5      eUS:X  a/  [9        XÎ5      nU(       a  SR;                  UU5      n[        U5      eU
(       a  U	R                  [=        XÎ5      5        U R                  R                  U5        GMs     SU0nU(       a  U	US'   0 nU(       aK  [?        U R                  5       H-  u  nn[/        US   5      (       d  M  UR0                  S-
  UU'   M/     UUS'   U R                  (       a  U RA                  UU	U5        U$ )NT©r1   ÚresetÚskip_check_array©r"   ÚautozOShape mismatch: if categories is an array, it has to be of shape (n_features,).)Úreturn_counts©r!   r   ÚSz
In column zY, the predefined categories have type 'bytes' which is incompatible with values of type 'z'.éÿÿÿÿzKNan should be the last element in user provided categories, see categories z in column #z7, the predefined categories contain duplicate elements.ÚOUSz>Unsorted categories are not supported for numerical categoriesÚerrorz5Found unknown categories {0} in column {1} during fitr4   Úcategory_countsr#   Úmissing_indices)!Ú_check_infrequent_enabledr   r:   Ún_features_in_Ú
categoriesÚlenÚ
ValueErrorÚcategories_Ú_infrequent_enabledr.   r   r/   r)   r*   r!   r+   r,   ÚarrayÚ
isinstanceÚbytesÚkindÚtypeÚ__name__r   ÚsizeÚsortÚisnanÚanyr   Úformatr   Ú	enumerateÚ _fit_infrequent_category_mapping)r0   r1   Úhandle_unknownr"   rC   Ú(return_and_ignore_missing_for_infrequentÚX_listr4   r5   rI   Úcompute_countsr7   r8   ÚresultÚcatsÚcountsÚXi_dtypeÚmsgÚcategoryÚsorted_catsÚ	error_msgÚstop_idxÚdiffÚoutputrJ   Úfeature_idxÚcategories_for_idxs                              r9   Ú_fitÚ_BaseEncoder._fitL   s_  € ð 	×&Ñ&Ô(Ü�d t¸dÒCØ(,¯©Øð )6ð )
Ñ%ˆ˜:ð )Ôà�?‰?˜fÓ$Ü�4—?‘?Ó# zÓ1Ü ð<óð ð
 ˆÔØˆØ&×B¨$×*BÑ*Bˆä�z×"ˆAØ‘ˆBà�‰ &Ó(Ü  ÑB�Þ!Ø#)‘L�DØ#×*Ñ*¨6Ö2à!’Dä—=’= §¡¬2¯7©7×3Ñ3ô  &‘Hà!Ÿx™x�Hä—x’x §¡°Ñ 2¸(ÑC�à—J‘J¤&Ó(Ü" 4¨¡7¬E×2Ñ2ØŸ™Ÿ™¨Ó,ð % Q Cð (ä! " Q¡%›[×1Ñ1Ð2°"ð6ð ô
 % S›/Ð)ð !% S b£	�HÜ$ X×.Ó.Ü(ðDØDHÀ6Ø*¨1¨#ð/óð ñ !*ð —9‘9¤¤G¨D£MÓ 2Ó2à$ Q Cð (7ð 7ð ô % S›/Ð)à—8‘8—=‘=¨Ó-Ü"$§'¢'¨$£-�KàXð ô &(§X¢X¨k¸"©o×%>Ñ%>™rÀD�HÜ—v’v˜k¨)¨8Ð4¸¸Y¸h¸ÑG×HÑHÜ(¨Ó3Ð3à! WÓ,Ü)¨"Ó3�DÞð*ß*0©&°°q«/ð ô )¨›oÐ-Þ!Ø#×*Ñ*¬;°rÓ+@ÔAà×Ñ×#Ñ# D×)ñK #ðN ˜yÐ)ˆÞØ(7ˆFÐ$Ñ%àˆÞ3Ü3<¸T×=MÑ=MÖ3NÑ/�Ð/Ü Ð!3°BÑ!7×8Ó8à3E×3JÑ3JÈQÑ3N�O KÓ0ñ 4Oð )8ˆFÐ$Ñ%à×#×#Ø×1Ñ1ØØØôð
 ˆr<   c                 ót  • U R                  XS9u  pgn[        XSSS9  [        R                  " Xx4[        S9n	[        R
                  " Xx4[        S9n
/ n[        U5       GHŒ  nXl   n[        XÐR                  U   SS9u  pï[        R                  " U5      (       Gd1  US:X  a  SR                  Xì5      n[        U5      eU(       a  UR                  U5        XúS S 2U4'   U R                  U   R                  R                  S	;   aP  U R                  U   R                   UR                   :”  a)  UR#                  U R                  U   R                  5      nOcU R                  U   R                  R                  S
:X  a,  UR                  R                  S:X  a  UR#                  S
5      nOUR%                  5       nU R                  U   S   Xß) '   ['        XÐR                  U   SS9U	S S 2U4'   GM�     U(       a.  US:X  a  SU S3nOSU S3n[(        R*                  " U[,        5        U R/                  XšU5        Xš4$ )NrA   FTr>   rD   )Úreturn_maskrH   z;Found unknown categories {0} in column {1} during transform)ÚUrE   ÚOrt   r   )ÚuniquesÚcheck_unknownÚinfrequent_if_existz$Found unknown categories in columns zW during transform. These unknown categories will be encoded as the infrequent category.zH during transform. These unknown categories will be encoded as all zeros)r:   r   r)   ÚzerosÚintÚonesÚboolr.   r   rP   Úallr\   rO   r/   r!   rU   ÚitemsizeÚastypeÚcopyr   ÚwarningsÚwarnÚUserWarningÚ_map_infrequent_categories)r0   r1   r_   r"   Úwarn_on_unknownÚignore_category_indicesra   r4   r5   ÚX_intÚX_maskÚcolumns_with_unknownr7   r8   rl   Ú
valid_maskrg   s                    r9   Ú
_transformÚ_BaseEncoder._transformÁ   s,  € ð )-¯©Øð )6ð )
Ñ%ˆ˜:ô 	�d u¸tÒDä—’˜)Ð0¼Ñ<ˆÜ—’˜)Ð0¼Ñ=ˆà!ÐÜ�z×"ˆAØ‘ˆBÜ-¨b×2BÑ2BÀ1Ñ2EÐSWÑXÑˆDä—6’6˜*×%Ò%Ø! WÓ,ð,ß,2©F°4«Oð ô % S›/Ð)æ&Ø,×3Ñ3°AÔ6ð $.š1˜a˜4‘Lð ×(Ñ(¨Ñ+×1Ñ1×6Ñ6¸*ÓDØ ×,Ñ,¨QÑ/×8Ñ8¸2¿;¹;ÓFàŸY™Y t×'7Ñ'7¸Ñ':×'@Ñ'@ÓA™Ø×)Ñ)¨!Ñ,×2Ñ2×7Ñ7¸3Ó>À2Ç8Á8Ç=Á=ÐTWÓCWð  ŸY™Y s›^™àŸW™W›Y˜à&*×&6Ñ&6°qÑ&9¸!Ñ&<�B�{‘Oô " "×.>Ñ.>¸qÑ.AÐQVÑWˆE’!�Q�$ŒKñI #öJ  ØÐ!6Ó6à:Ø+Ð,ð -+ð+ñ ð ;Ø+Ð,ð -FðFð ô
 �MŠM˜#œ{Ô+à×'Ñ'¨Ð7NÔOØˆ}Ðr<   c                 óŠ   • U R                   n[        U R                  U5       VVs/ s H  u  p#Uc  SOX#   PM     snn$ s  snnf )z'Infrequent categories for each feature.N)Ú_infrequent_indicesÚziprP   )r0   Úinfrequent_indicesrh   r$   s       r9   Úinfrequent_categories_Ú#_BaseEncoder.infrequent_categories_
  sT   € ð "×5Ñ5Ðô &)¨×)9Ñ)9Ð;MÔ%Nô
â%NÑ!�ð ‘O‰D¨Ñ):Ò:Ù%Nò
ð 	
ùó 
s   ¦?c                 óx   • [        U SS5      n[        U SS5      nUSL=(       a    US:¬  =(       d    USLU l        g)z‹
This functions checks whether _infrequent_enabled is True or False.
This has to be called after parameter validation in the fit function.
Úmax_categoriesNÚmin_frequencyr#   )r(   rQ   )r0   r”   r•   s      r9   rK   Ú&_BaseEncoder._check_infrequent_enabled  sH   € ô
 ! Ð'7¸Ó>ˆÜ  o°tÓ<ˆà $Ð&×>¨>¸QÑ+>÷$'à $Ð&ð 	Õ r<   c                 ót  • [        U R                  [        R                  5      (       a  XR                  :  nOb[        U R                  [        R                  5      (       a  X R                  -  nX:  nO&[
        R                  " UR                  S   [        S9nUR                  UR                  5       -
  S-   nU R                  bH  U R                  U:  a8  U R                  S-
  nUS:X  a  SUSS& O[
        R                  " USS9SU*  nSXH'   [
        R                  " U5      n	U	R                  S:”  a  U	$ S$ )a¦  Compute the infrequent indices.

Parameters
----------
category_count : ndarray of shape (n_cardinality,)
    Category counts.

n_samples : int
    Number of samples.

col_idx : int
    Index of the current category. Only used for the error message.

Returns
-------
output : ndarray of shape (n_infrequent_categories,) or None
    If there are infrequent categories, indices of infrequent
    categories. Otherwise None.
r   rD   r#   NTÚ	mergesort)rU   )rS   r•   Únumbersr   ÚRealr)   ry   r-   r|   rX   Úsumr”   ÚargsortÚflatnonzero)
r0   Úcategory_countr4   Úcol_idxÚinfrequent_maskÚmin_frequency_absÚn_current_featuresÚfrequent_category_countÚsmallest_levelsrm   s
             r9   Ú_identify_infrequentÚ!_BaseEncoder._identify_infrequent  s  € ô( �d×(Ñ(¬'×*:Ñ*:×;Ñ;Ø,×/AÑ/AÑA‰OÜ˜×*Ñ*¬G¯L©L×9Ñ9Ø )×,>Ñ,>Ñ >ÐØ,Ñ@‰Oä Ÿhšh ~×';Ñ';¸AÑ'>ÄdÑKˆOà+×0Ñ0°?×3FÑ3FÓ3HÑHÈ1ÑLÐØ×ÑÑ*¨t×/BÑ/BÐEWÓ/Wà&*×&9Ñ&9¸AÑ&=Ð#Ø&¨!Ó+à%)�¡Ñ"ô #%§*¢*¨^À+Ñ"NØ-Ð-Ð-ð#�ð 48�Ñ0ä—’ Ó0ˆØŸ™ q›ˆvÐ2¨dÐ2r<   c           	      ó6  • U(       aW  / n[        U5       HE  u  pVXS;   a*  UR                  [        R                  " XcU   5      5        M4  UR                  U5        MG     OUn[        U5       VVs/ s H  u  pxU R	                  X�U5      PM     snnU l        / U l        [        U R
                  5       HÞ  u  pYU R                  U   n
U	c  U R                  R                  S5        M4  [        U
5      nXS;   a  US-  n[        R                  " U[        R                  S9nU	R                  nX½-
  nXìU	'   [        R                  " [        R                  " U5      U	5      n[        R                  " U5      XÏ'   U R                  R                  U5        Mà     gs  snnf )a   Fit infrequent categories.

Defines the private attribute: `_default_to_infrequent_mappings`. For
feature `i`, `_default_to_infrequent_mappings[i]` defines the mapping
from the integer encoding returned by `super().transform()` into
infrequent categories. If `_default_to_infrequent_mappings[i]` is None,
there were no infrequent categories in the training set.

For example if categories 0, 2 and 4 were frequent, while categories
1, 3, 5 were infrequent for feature 7, then these categories are mapped
to a single output:
`_default_to_infrequent_mappings[7] = array([0, 3, 1, 3, 2, 3])`

Defines private attribute: `_infrequent_indices`. `_infrequent_indices[i]`
is an array of indices such that
`categories_[i][_infrequent_indices[i]]` are all the infrequent category
labels. If the feature `i` has no infrequent categories
`_infrequent_indices[i]` is None.

.. versionadded:: 1.1

Parameters
----------
n_samples : int
    Number of samples in training set.
category_counts: list of ndarray
    `category_counts[i]` is the category counts corresponding to
    `self.categories_[i]`.
missing_indices : dict
    Dict mapping from feature_idx to category index with a missing value.
Nr#   rD   )r]   r/   r)   Údeleter¥   rŽ   Ú_default_to_infrequent_mappingsrP   rN   ÚemptyÚint64rX   Ú	setdiff1dÚarange)r0   r4   rI   rJ   Úcategory_counts_rn   ÚcountrŸ   rž   Ú
infreq_idxrd   Ún_catsÚmappingÚn_infrequent_catsÚn_frequent_catsÚfrequent_indicess                   r9   r^   Ú-_BaseEncoder._fit_infrequent_category_mappingL  sv  € öF Ø!ÐÜ&/°Ö&@Ñ"�ØÓ1Ø$×+Ñ+ÜŸ	š	 %¸Ñ)EÓFöð %×+Ñ+¨EÖ2ò 'Að  /Ðô ,5Ð5EÔ+Fô$
â+FÑ'�ð ×%Ñ% nÀÖIÙ+Fò$
ˆÔ ð 02ˆÔ,ä'0°×1IÑ1IÖ'JÑ#ˆKØ×#Ñ# KÑ0ˆDàÑ!Ø×4Ñ4×;Ñ;¸DÔAÙä˜“YˆFØÓ-ð ˜!‘�ô —h’h˜v¬R¯X©XÑ6ˆGØ *§¡Ðð %Ñ8ˆOØ"1�JÑä!Ÿ|š|¬B¯IªI°fÓ,=¸zÓJÐÜ(*¯	ª	°/Ó(BˆGÑ%à×0Ñ0×7Ñ7¸Ö@ò3 (Kùó$
s   Á/Fc                 ó¼  • U R                   (       d  gU=(       d    0 n[        UR                  S   5       HC  nU R                  U   nUc  M  US   XSS2U4   ) U4'   U R                  S;   d  M:  SUSS2U4'   ME     [        U R                  5       HG  u  pgUc  M
  Xc;   a  USS2U4   X6   :g  nO[        S5      n[        R                  " XqX†4   5      XU4'   MI     g)au  Map infrequent categories to integer representing the infrequent category.

This modifies X_int in-place. Values that were invalid based on `X_mask`
are mapped to the infrequent category if there was an infrequent
category for that feature.

Parameters
----------
X_int: ndarray of shape (n_samples, n_features)
    Integer encoded categories.

X_mask: ndarray of shape (n_samples, n_features)
    Bool mask for valid values in `X_int`.

ignore_category_indices : dict
    Dictionary mapping from feature_idx to category index to ignore.
    Ignored indexes will not be grouped and the original ordinal encoding
    will remain.
Nr#   r   ©rx   r‚   T)
rQ   r.   r-   rŽ   r_   r]   r©   Úslicer)   Útake)	r0   r‡   rˆ   r†   rŸ   Úinfrequent_idxr7   r²   Úrows_to_updates	            r9   r„   Ú'_BaseEncoder._map_infrequent_categoriesž  sí   € ð( ×'×'Øà"9×"?¸RÐä˜UŸ[™[¨™^Ö,ˆGØ!×5Ñ5°gÑ>ˆNØÑ%Ùà2@ÀÑ2CˆEš!˜W˜*Ñ%Ð% wÐ.Ñ/Ø×"Ñ"Ð&EÕEð
 &*�’q˜'�zÓ"ñ -ô $ D×$HÑ$HÖI‰JˆAØ‰ÙàÓ+à!&¢q¨! t¡Ð0GÑ0JÑ!J‘ä!& t£�ä')§w¢w¨w¸nÐ>OÑ8PÓ'QˆE !Ð#Ó$ò Jr<   c                 óh   >• [         TU ]  5       nSUR                  l        SUR                  l        U$ )NT)ÚsuperÚ__sklearn_tags__Ú
input_tagsÚcategoricalÚ	allow_nan)r0   ÚtagsÚ	__class__s     €r9   rÀ   Ú_BaseEncoder.__sklearn_tags__Ò  s-   ø€ Ü‰wÑ'Ó)ˆØ&*ˆ�‰Ô#Ø$(ˆ�‰Ô!Øˆr<   )r©   rQ   rŽ   rP   rL   ©T)rH   TFF)rH   TFN)rW   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r:   rp   r‹   Úpropertyr‘   rK   r¥   r^   r„   rÀ   Ú__static_attributes__Ú__classcell__)rÅ   s   @r9   r   r       sp   ø† ñô#0ðP ØØØ16ôsðp ØØØ $ôGðR ñ
ó ð
ò	'ò+3òZPAòd2R÷hó r<   r   c                   óF  • \ rS rSr% Sr\" S15      \/\" SS15      SS/S\" 1 S	k5      /\" \S
SSS9S/\" \S
SSS9\" \	SS
SS9S/S/\" S15      \
/S.r\\S'   SSS\R                  SSSSS.S jrS rS rS#S jrS rS r\" SS9S$S j5       rS rS rS$S  jrS! rS"rg)%r   iÙ  as+  
Encode categorical features as a one-hot numeric array.

The input to this transformer should be an array-like of integers or
strings, denoting the values taken on by categorical (discrete) features.
The features are encoded using a one-hot (aka 'one-of-K' or 'dummy')
encoding scheme. This creates a binary column for each category and
returns a sparse matrix or dense array (depending on the ``sparse_output``
parameter).

By default, the encoder derives the categories based on the unique values
in each feature. Alternatively, you can also specify the `categories`
manually.

This encoding is needed for feeding categorical data to many scikit-learn
estimators, notably linear models and SVMs with the standard kernels.

Note: a one-hot encoding of y labels should use a LabelBinarizer
instead.

Read more in the :ref:`User Guide <preprocessing_categorical_features>`.
For a comparison of different encoders, refer to:
:ref:`sphx_glr_auto_examples_preprocessing_plot_target_encoder.py`.

Parameters
----------
categories : 'auto' or a list 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 ith
      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 can be found in the ``categories_`` attribute.

    .. versionadded:: 0.20

drop : {'first', 'if_binary'} or an array-like of shape (n_features,),             default=None
    Specifies a methodology to use to drop one of the categories per
    feature. This is useful in situations where perfectly collinear
    features cause problems, such as when feeding the resulting data
    into an unregularized linear regression model.

    However, dropping one category breaks the symmetry of the original
    representation and can therefore induce a bias in downstream models,
    for instance for penalized linear classification or regression models.

    - None : retain all features (the default).
    - 'first' : drop the first category in each feature. If only one
      category is present, the feature will be dropped entirely.
    - 'if_binary' : drop the first category in each feature with two
      categories. Features with 1 or more than 2 categories are
      left intact.
    - array : ``drop[i]`` is the category in feature ``X[:, i]`` that
      should be dropped.

    When `max_categories` or `min_frequency` is configured to group
    infrequent categories, the dropping behavior is handled after the
    grouping.

    .. versionadded:: 0.21
       The parameter `drop` was added in 0.21.

    .. versionchanged:: 0.23
       The option `drop='if_binary'` was added in 0.23.

    .. versionchanged:: 1.1
        Support for dropping infrequent categories.

sparse_output : bool, default=True
    When ``True``, it returns a :class:`scipy.sparse.csr_matrix`,
    i.e. a sparse matrix in "Compressed Sparse Row" (CSR) format.

    .. versionadded:: 1.2
       `sparse` was renamed to `sparse_output`

dtype : number type, default=np.float64
    Desired dtype of output.

handle_unknown : {'error', 'ignore', 'infrequent_if_exist', 'warn'},                      default='error'
    Specifies the way unknown categories are handled during :meth:`transform`.

    - 'error' : Raise an error if an unknown category is present during transform.
    - 'ignore' : When an unknown category is encountered during
      transform, the resulting one-hot encoded columns for this feature
      will be all zeros. In the inverse transform, an unknown category
      will be denoted as None.
    - 'infrequent_if_exist' : When an unknown category is encountered
      during transform, the resulting one-hot encoded columns for this
      feature will map to the infrequent category if it exists. The
      infrequent category will be mapped to the last position in the
      encoding. During inverse transform, an unknown category will be
      mapped to the category denoted `'infrequent'` if it exists. If the
      `'infrequent'` category does not exist, then :meth:`transform` and
      :meth:`inverse_transform` will handle an unknown category as with
      `handle_unknown='ignore'`. Infrequent categories exist based on
      `min_frequency` and `max_categories`. Read more in the
      :ref:`User Guide <encoder_infrequent_categories>`.
    - 'warn' : When an unknown category is encountered during transform
      a warning is issued, and the encoding then proceeds as described for
      `handle_unknown="infrequent_if_exist"`.

    .. versionchanged:: 1.1
        `'infrequent_if_exist'` was added to automatically handle unknown
        categories and infrequent categories.

    .. versionadded:: 1.6
       The option `"warn"` was added in 1.6.

min_frequency : int or float, default=None
    Specifies the minimum frequency below which a category will be
    considered infrequent.

    - If `int`, categories with a smaller cardinality will be considered
      infrequent.

    - If `float`, categories with a smaller cardinality than
      `min_frequency * n_samples`  will be considered infrequent.

    .. versionadded:: 1.1
        Read more in the :ref:`User Guide <encoder_infrequent_categories>`.

max_categories : int, default=None
    Specifies an upper limit to the number of output features for each input
    feature when considering infrequent categories. If there are infrequent
    categories, `max_categories` includes the category representing the
    infrequent categories along with the frequent categories. If `None`,
    there is no limit to the number of output features.

    .. versionadded:: 1.1
        Read more in the :ref:`User Guide <encoder_infrequent_categories>`.

feature_name_combiner : "concat" or callable, default="concat"
    Callable with signature `def callable(input_feature, category)` that returns a
    string. This is used to create feature names to be returned by
    :meth:`get_feature_names_out`.

    `"concat"` concatenates encoded feature name and category with
    `feature + "_" + str(category)`.E.g. feature X with values 1, 6, 7 create
    feature names `X_1, X_6, X_7`.

    .. versionadded:: 1.3

Attributes
----------
categories_ : list of arrays
    The categories of each feature determined during fitting
    (in order of the features in X and corresponding with the output
    of ``transform``). This includes the category specified in ``drop``
    (if any).

drop_idx_ : array of shape (n_features,)
    - ``drop_idx_[i]`` is the index in ``categories_[i]`` of the category
      to be dropped for each feature.
    - ``drop_idx_[i] = None`` if no category is to be dropped from the
      feature with index ``i``, e.g. when `drop='if_binary'` and the
      feature isn't binary.
    - ``drop_idx_ = None`` if all the transformed features will be
      retained.

    If infrequent categories are enabled by setting `min_frequency` or
    `max_categories` to a non-default value and `drop_idx[i]` corresponds
    to an infrequent category, then the entire infrequent category is
    dropped.

    .. versionchanged:: 0.23
       Added the possibility to contain `None` values.

infrequent_categories_ : list of ndarray
    Defined only if infrequent categories are enabled by setting
    `min_frequency` or `max_categories` to a non-default value.
    `infrequent_categories_[i]` are the infrequent categories for feature
    `i`. If the feature `i` has no infrequent categories
    `infrequent_categories_[i]` is None.

    .. versionadded:: 1.1

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

    .. versionadded:: 1.0

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.

    .. versionadded:: 1.0

feature_name_combiner : callable or None
    Callable with signature `def callable(input_feature, category)` that returns a
    string. This is used to create feature names to be returned by
    :meth:`get_feature_names_out`.

    .. versionadded:: 1.3

See Also
--------
OrdinalEncoder : Performs an ordinal (integer)
  encoding of the categorical features.
TargetEncoder : Encodes categorical features using the target.
sklearn.feature_extraction.DictVectorizer : Performs a one-hot encoding of
  dictionary items (also handles string-valued features).
sklearn.feature_extraction.FeatureHasher : Performs an approximate one-hot
  encoding of dictionary items or strings.
LabelBinarizer : Binarizes labels in a one-vs-all
  fashion.
MultiLabelBinarizer : Transforms between iterable of
  iterables and a multilabel format, e.g. a (samples x classes) binary
  matrix indicating the presence of a class label.

Examples
--------
Given a dataset with two features, we let the encoder find the unique
values per feature and transform the data to a binary one-hot encoding.

>>> from sklearn.preprocessing import OneHotEncoder

One can discard categories not seen during `fit`:

>>> enc = OneHotEncoder(handle_unknown='ignore')
>>> X = [['Male', 1], ['Female', 3], ['Female', 2]]
>>> enc.fit(X)
OneHotEncoder(handle_unknown='ignore')
>>> enc.categories_
[array(['Female', 'Male'], dtype=object), array([1, 2, 3], dtype=object)]
>>> enc.transform([['Female', 1], ['Male', 4]]).toarray()
array([[1., 0., 1., 0., 0.],
       [0., 1., 0., 0., 0.]])
>>> enc.inverse_transform([[0, 1, 1, 0, 0], [0, 0, 0, 1, 0]])
array([['Male', 1],
       [None, 2]], dtype=object)
>>> enc.get_feature_names_out(['gender', 'group'])
array(['gender_Female', 'gender_Male', 'group_1', 'group_2', 'group_3'], ...)

One can always drop the first column for each feature:

>>> drop_enc = OneHotEncoder(drop='first').fit(X)
>>> drop_enc.categories_
[array(['Female', 'Male'], dtype=object), array([1, 2, 3], dtype=object)]
>>> drop_enc.transform([['Female', 1], ['Male', 2]]).toarray()
array([[0., 0., 0.],
       [1., 1., 0.]])

Or drop a column for feature only having 2 categories:

>>> drop_binary_enc = OneHotEncoder(drop='if_binary').fit(X)
>>> drop_binary_enc.transform([['Female', 1], ['Male', 2]]).toarray()
array([[0., 1., 0., 0.],
       [1., 0., 1., 0.]])

One can change the way feature names are created.

>>> def custom_combiner(feature, category):
...     return str(feature) + "_" + type(category).__name__ + "_" + str(category)
>>> custom_fnames_enc = OneHotEncoder(feature_name_combiner=custom_combiner).fit(X)
>>> custom_fnames_enc.get_feature_names_out()
array(['x0_str_Female', 'x0_str_Male', 'x1_int_1', 'x1_int_2', 'x1_int_3'],
      dtype=object)

Infrequent categories are enabled by setting `max_categories` or `min_frequency`.

>>> import numpy as np
>>> X = np.array([["a"] * 5 + ["b"] * 20 + ["c"] * 10 + ["d"] * 3], dtype=object).T
>>> ohe = OneHotEncoder(max_categories=3, sparse_output=False).fit(X)
>>> ohe.infrequent_categories_
[array(['a', 'd'], dtype=object)]
>>> ohe.transform([["a"], ["b"]])
array([[0., 0., 1.],
       [1., 0., 0.]])
rB   ÚfirstÚ	if_binaryz
array-likeNÚno_validation>   r‚   rH   Úignorerx   r#   Úleft©Úclosedr   ÚneitherÚbooleanÚconcat)rM   Údropr!   r_   r”   r•   Úsparse_outputÚfeature_name_combinerÚ_parameter_constraintsTrH   )rM   rÚ   rÛ   r!   r_   r•   r”   rÜ   c                ód   • Xl         X0l        X@l        XPl        X l        X`l        Xpl        X€l        g ©N)rM   rÛ   r!   r_   rÚ   r•   r”   rÜ   )	r0   rM   rÚ   rÛ   r!   r_   r•   r”   rÜ   s	            r9   Ú__init__ÚOneHotEncoder.__init__þ  s1   € ð %ŒØ*ÔØŒ
Ø,ÔØŒ	Ø*ÔØ,ÔØ%:Õ"r<   c                 óê   • U R                   (       d  U$ U R                  U   nUc  U$ U R                  U   nUb7  X$;   a2  U R                  U   n[	        SXR   R                  5       < SU S35      eX2   $ )z×Convert `drop_idx` into the index for infrequent categories.

If there are no infrequent categories, then `drop_idx` is
returned. This method is called in `_set_drop_idx` when the `drop`
parameter is an array-like.
zUnable to drop category z from feature z because it is infrequent)rQ   r©   rŽ   rP   rO   Úitem)r0   rn   Údrop_idxÚdefault_to_infrequentr�   rM   s         r9   Ú_map_drop_idx_to_infrequentÚ)OneHotEncoder._map_drop_idx_to_infrequent  sœ   € ð ×'×'ØˆOà $× DÑ DÀ[Ñ QÐØ Ñ(ØˆOð "×5Ñ5°kÑBÐØÑ)¨hÓ.LØ×)Ñ)¨+Ñ6ˆJÜØ*¨:Ñ+?×+DÑ+DÓ+FÑ*Ið JØ'˜=Ð(AðCóð ð %Ñ.Ð.r<   c                 ó†  • U R                   c  SnGOú[        U R                   [        5      (       aô  U R                   S:X  a.  [        R                  " [        U R                  5      [        S9nGO�U R                   S:X  a¤  U R                   Vs/ s H  n[        U5      PM     nnU R                  (       a<  [        U R                  5       H#  u  pEUc  M
  X4==   UR                  S-
  -  ss'   M%     [        R                  " U Vs/ s H  nUS:X  a  SOSPM     sn[        S9nGOç[        R                  " U R                   [        S9n[        U5      nU[        U R                  5      :w  a0  Sn	[        U	R                  [        U R                  5      U5      5      e/ n
/ n[        [!        XpR                  5      5       HÐ  u  nu  pÞ[#        U5      (       dd  [        R$                  " Xí:H  5      S   nUR                  (       a$  UR'                  U R)                  XÏS   5      5        OU
R'                  XÍ45        M|  [#        US	   5      (       a/  UR'                  U R)                  XÎR                  S-
  5      5        M¾  U
R'                  XÍ45        MÒ     [+        U
5      (       aQ  S
R                  SR-                  U
 VVs/ s H  u  nnSR                  UU5      PM     snn5      5      n	[        U	5      e[        R                  " U[        S9nWU l        U R                  (       a  Uc  U R.                  U l        g/ n[        U5       HJ  u  pÏU R2                  U   nUb  Uc  UnO[        R4                  " UU:H  5      S   nUR'                  U5        ML     [        R                  " U[        S9U l        gs  snf s  snf s  snnf )aŒ  Compute the drop indices associated with `self.categories_`.

If `self.drop` is:
- `None`, No categories have been dropped.
- `'first'`, All zeros to drop the first category.
- `'if_binary'`, All zeros if the category is binary and `None`
  otherwise.
- array-like, The indices of the categories that match the
  categories in `self.drop`. If the dropped category is an infrequent
  category, then the index for the infrequent category is used. This
  means that the entire infrequent category is dropped.

This methods defines a public `drop_idx_` and a private
`_drop_idx_after_grouping`.

- `drop_idx_`: Public facing API that references the drop category in
  `self.categories_`.
- `_drop_idx_after_grouping`: Used internally to drop categories *after* the
  infrequent categories are grouped together.

If there are no infrequent categories or drop is `None`, then
`drop_idx_=_drop_idx_after_grouping`.
NrÐ   rD   rÑ   r#   r    r   zF`drop` should have length equal to the number of features ({}), got {}rF   zaThe following categories were supposed to be dropped, but were not found in the training data.
{}Ú
zCategory: {}, Feature: {})rÚ   rS   Ústrr)   ry   rN   rP   r,   rQ   r]   rŽ   rX   rR   ÚasarrayrO   r\   r�   r   Úwherer/   ræ   r[   ÚjoinÚ_drop_idx_after_groupingÚ	drop_idx_r©   r�   )r0   Údrop_idx_after_groupingÚcatÚn_features_out_no_dropr7   r°   Ún_features_outÚ
drop_arrayÚdroplenrg   Úmissing_dropsÚdrop_indicesrn   Údrop_valÚcat_listrä   ÚcÚvrï   rå   Úorig_drop_idxs                        r9   Ú_set_drop_idxÚOneHotEncoder._set_drop_idx+  sc  € ð0 �9‰9ÑØ&*Ò#Ü˜Ÿ	™	¤3×'Ñ'Ø�y‰y˜GÓ#Ü*,¯(ª(´3°t×7GÑ7GÓ3HÔPVÑ*WÒ'Ø—‘˜kÓ)Ø>B×>NÒ>NÓ)OÒ>N°s¬#¨c®(Ñ>NÐ&Ð)OØ×+×+Ü)2°4×3KÑ3KÖ)L™˜Ø%Ñ-Ù$Ø.Ó1°Z·_±_ÀqÑ5HÑHÕ1ñ *Mô
 +-¯(ª(ñ /Eóâ.D˜Nð ,¨qÓ0™°dÒ:Ù.Dñô !ñ+Ð'ùô Ÿš D§I¡I´VÑ<ˆJÜ˜*“oˆGàœ#˜d×.Ñ.Ó/Ó/ð/ð ô ! §¡¬C°×0@Ñ0@Ó,AÀ7Ó!KÓLÐLØˆMØˆLÜ5>Ü�J× 0Ñ 0Ó1ö6Ñ1�Ñ1˜hô % X×.Ñ.Ü!Ÿxšx¨Ñ(<Ó=¸aÑ@�HØ—}—}Ø$×+Ñ+Ø ×<Ñ<¸[ÐSTÉ+ÓVõð &×,Ñ,¨kÐ-DÔEÙô ! ¨"¡×.Ñ.Ø ×'Ñ'Ø×8Ñ8¸ÇmÁmÐVWÑFWÓXöð "×(Ñ(¨+Ð)@ÖAñ'6ô* �=×!Ñ!ð ç &¡ØŸ	™	ñ -:ôâ,9¡D A qð !<× BÑ BÀ1ÀaÖ HÙ,9òóó!ð ô ! “oÐ%Ü&(§h¢h¨|Ä6Ñ&JÐ#ð
 )@ˆÔ%à×'×'Ð+BÑ+JØ!×:Ñ:ˆD�NàˆIÜ)2Ð3JÖ)KÑ%�Ø(,×(LÑ(LØñ)Ð%ð Ñ#Ð'<Ñ'DØ$,‘Mä$&§N¢NÐ3HÈHÑ3TÓ$UÐVWÑ$X�Mà× Ñ  Ö/ñ *Lô  ŸZšZ¨	¼Ñ@ˆD�Nùòi *Pùòùó\s   ÂN3ÄN8Ê=N=c                 ó&  • U R                   U   nU R                  (       aX  U R                  U   nUbF  XDR                  5       :  nSn[        R
                  " X5   [        R                  " U/[        S945      nU(       a  U R                  X15      nU$ )zÅCompute the transformed categories used for column `i`.

1. If there are infrequent categories, the category is named
'infrequent_sklearn'.
2. Dropped columns are removed when remove_dropped=True.
Úinfrequent_sklearnrD   )	rP   rQ   r©   Úmaxr)   ÚconcatenaterR   r,   Ú_remove_dropped_categories)r0   r7   Úremove_droppedrd   Ú
infreq_mapÚfrequent_maskÚinfrequent_cats          r9   Ú_compute_transformed_categoriesÚ-OneHotEncoder._compute_transformed_categoriesŸ  sˆ   € ð ×Ñ Ñ"ˆà×#×#Ø×=Ñ=¸aÑ@ˆJØÑ%Ø *¯^©^Ó-=Ñ =�Ø!5�ä—~’~ØÑ(¬"¯(ª(°NÐ3CÌ6Ñ*RÐSó�ö Ø×2Ñ2°4Ó;ˆDØˆr<   c                 ó†   • U R                   b3  U R                   U   b#  [        R                  " XR                   U   5      $ U$ )zRemove dropped categories.)rî   r)   r¨   )r0   rM   r7   s      r9   r  Ú(OneHotEncoder._remove_dropped_categories¶  sA   € ð ×)Ñ)Ñ5Ø×-Ñ-¨aÑ0Ñ<ä—9’9˜Z×)FÑ)FÀqÑ)IÓJÐJØÐr<   c                 óp  • U R                    Vs/ s H  n[        U5      PM     nnU R                  b/  [        U R                  5       H  u  p4Uc  M
  X#==   S-  ss'   M     U R                  (       d  U$ [        U R
                  5       H#  u  p5Uc  M
  X#==   UR                  S-
  -  ss'   M%     U$ s  snf )z2Compute the n_features_out for each input feature.r#   )rP   rN   rî   r]   rQ   rŽ   rX   )r0   rd   rm   r7   rä   r°   s         r9   Ú_compute_n_features_outsÚ&OneHotEncoder._compute_n_features_outs¿  s«   € à(,×(8Ò(8Ó9Ò(8 ”#�d–)Ñ(8ˆÐ9à×(Ñ(Ñ4Ü(¨×)FÑ)FÖG‘�ØÓ'Ø“I ‘N•Iñ  Hð ×'×'ØˆMô ' t×'?Ñ'?Ö@‰MˆAØÑ!ÙØ‹I˜Ÿ™¨1Ñ,Ñ,�Iñ Að
 ˆùò# :s   �B3©Úprefer_skip_nested_validationc                 ó†   • U R                  UU R                  SS9  U R                  5         U R                  5       U l        U $ )a6  
Fit OneHotEncoder to X.

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

y : None
    Ignored. This parameter exists only for compatibility with
    :class:`~sklearn.pipeline.Pipeline`.

Returns
-------
self
    Fitted encoder.
ú	allow-nan)r_   r"   )rp   r_   rý   r  Ú_n_features_outs)r0   r1   Úys      r9   ÚfitÚOneHotEncoder.fitÔ  sH   € ð& 	�	‰	ØØ×.Ñ.Ø)ð 	ñ 	
ð
 	×ÑÔØ $× =Ñ =Ó ?ˆÔØˆr<   c                 ó˜  • [        U 5        [        SU S9S   nUS:w  a5  U R                  (       a$  UR                  5       n[	        U SU SU S35      eU R
                  S:X  a  S	u  pEO0U R                  S
L=(       a    U R
                  S;   nU R
                  nU R                  UUSUS9u  pgUR                  u  p‰U R                  bu  U R                  R                  5       n
Xj:g  n[        U R                  5       H  u  pÍX¬   b  M  [        U5      X¬'   M     U
R                  SS5      n
XfU
:„  ==   S-  ss'   X{-  nUR                  5       n[         R"                  " S/U R$                  -   5      nXoS
S -   R                  5       U   n[         R&                  " US-   [(        S9nSUS'   [         R*                  " USUSS
 UR,                  S9  [         R"                  " USS
 USS
 S9  [         R.                  " US   5      n[0        R2                  " UUU4X�S   4U R,                  S9nU R                  (       d  UR5                  5       $ U$ )a_  
Transform X using one-hot encoding.

If `sparse_output=True` (default), it returns an instance of
:class:`scipy.sparse._csr.csr_matrix` (CSR format).

If there are infrequent categories for a feature, set by specifying
`max_categories` or `min_frequency`, the infrequent categories are
grouped into a single category.

Parameters
----------
X : array-like of shape (n_samples, n_features)
    The data to encode.

Returns
-------
X_out : {ndarray, sparse matrix} of shape                 (n_samples, n_encoded_features)
    Transformed input. If `sparse_output=True`, a sparse matrix will be
    returned.
Ú	transform)Ú	estimatorÚdenseÚdefaultzH output does not support sparse data. Set sparse_output=False to output z dataframes or disable z1 output via` ohe.set_output(transform="default").r‚   )Trx   N>   rÓ   rx   r  )r_   r"   r…   r#   rF   r   rD   )r%   Úoutr!   )r  )r-   r!   )r   r   rÛ   Ú
capitalizerO   r_   rÚ   r‹   r-   rî   r€   r]   rP   rN   ÚreshapeÚravelr)   Úcumsumr  rª   rz   r›   r!   r{   r   Ú
csr_matrixÚtoarray)r0   r1   Útransform_outputÚcapitalize_transform_outputr…   r_   r‡   rˆ   r4   r5   Úto_dropÚ
keep_cellsr7   rd   ÚmaskÚfeature_indicesr$   ÚindptrÚdatar  s                       r9   r  ÚOneHotEncoder.transformð  s]  € ô. 	˜ÔÜ-¨kÀTÑJÈ7ÑSÐØ˜yÓ(¨T×-?×-?Ø*:×*EÑ*EÓ*GÐ'ÜØ.Ð/ð 06Ø6FÐ5Gð HØ7Ð8ð 99ð9óð ð ×Ñ &Ó(Ø.IÑ+ˆO˜^à"Ÿi™i¨tÐ3÷ ¸×8KÑ8Kð Pñ 9ˆOð "×0Ñ0ˆNØŸ™ØØ)Ø)Ø+ð	 (ð 
‰ˆð !&§¡Ñˆ	à×(Ñ(Ñ4Ø×3Ñ3×8Ñ8Ó:ˆGð Ñ)ˆJÜ$ T×%5Ñ%5Ö6‘�à‘:Ó%ä!$ T£�G“Jñ	 7ð —o‘o a¨Ó,ˆGØ˜'‘/Ó" aÑ'Ó"ØÑ ˆFà�|‰|‹~ˆÜŸ)š) Q C¨$×*?Ñ*?Ñ$?Ó@ˆØ¨3¨BÐ/Ñ/×6Ñ6Ó8¸Ñ>ˆä—’˜) a™-¬sÑ3ˆØˆˆq‰	Ü
�Šˆv˜A 6¨!¨" :°V·\±\ÒBÜ
�	Š	�&˜˜�* &¨¨ *Ò-Ü�wŠw�v˜b‘zÓ"ˆä×ÒØ�7˜FÐ#Ø¨bÑ1Ð2Ø—*‘*ñ
ˆð
 ×!×!Ø—;‘;“=Ð àˆJr<   c           	      ó2  • [        U 5        [        USS9nUR                  u  p#[        U R                  5      n[
        R                  " U R                  5      nSnUR                  S   U:w  a'  [        UR                  XQR                  S   5      5      e[        U R                  5       VVs/ s H  u  psU R                  USS9PM     nnn[
        R                  " U V	s/ s H  o™R                  PM     sn	6 n
[
        R                  " X$4U
S9nSn0 nU R                  (       a  U R                   nOS	/U-  n[#        U5       GHô  nU R%                  X‡   U5      nUR                  S   nUS:X  a-  U R                  U   U R&                  U      US	S	2U4'   UU-  nMZ  US	S	2XÌU-   24   n[
        R(                  " UR+                  SS
95      R-                  5       nUU   US	S	2U4'   U R.                  S:X  d  U R.                  S;   a•  Xç   c�  [
        R(                  " UR                  SS
9S:H  5      R-                  5       nUR1                  5       (       aF  U R&                  b  U R&                  U   c  UX×'   O»U R                  U   U R&                  U      UUU4'   O–[
        R(                  " UR                  SS
9S:H  5      R-                  5       nUR1                  5       (       aM  U R&                  c%  [
        R2                  " U5      n[        SU S35      eU R&                  U   nX‡   U   UUU4'   UU-  nGM÷     U(       aJ  UR                  [4        :w  a  UR7                  [4        5      nUR9                  5        H  u  nnS	UUU4'   M     U$ s  snnf s  sn	f )a•  
Convert the data back to the original representation.

When unknown categories are encountered (all zeros in the
one-hot encoding), ``None`` is used to represent this category. If the
feature with the unknown category has a dropped category, the dropped
category will be its inverse.

For a given input feature, if there is an infrequent category,
'infrequent_sklearn' will be used to represent the infrequent category.

Parameters
----------
X : {array-like, sparse matrix} of shape                 (n_samples, n_encoded_features)
    The transformed data.

Returns
-------
X_original : ndarray of shape (n_samples, n_features)
    Inverse transformed array.
Úcsr)Úaccept_sparseúIShape of the passed X data is not correct. Expected {0} columns, got {1}.r#   F)r  rD   r   N)r%   rÓ   r¸   zSamples z] can not be inverted when drop=None and handle_unknown='error' because they contain all zeros)r   r
   r-   rN   rP   r)   r›   r  rO   r\   r]   r  Úresult_typer!   rª   rQ   rŽ   r.   r  rî   rë   ÚargmaxÚflattenr_   r[   r�   r,   r   Úitems)r0   r1   r4   Ú_r5   ró   rg   r7   Útransformed_featuresrñ   ÚdtÚX_trÚjÚfound_unknownr�   Úcats_wo_droppedÚn_categoriesÚsubÚlabelsÚunknownÚdroppedÚall_zero_samplesrä   Úidxr'  s                            r9   Úinverse_transformÚOneHotEncoder.inverse_transformG  sˆ  € ô. 	˜ÔÜ˜¨Ñ/ˆà—w‘w‰ˆ	Ü˜×)Ñ)Ó*ˆ
äŸš × 5Ñ 5Ó6ˆð Xð 	ð �7‰7�1‰:˜Ó'Ü˜SŸZ™Z¨¿¹À¹
ÓCÓDÐDô " $×"2Ñ"2Ô3ô 
â3‘�ð ×0Ñ0°À5Ð0ÓIÙ3ð 	ñ  
ô �^Š^Ñ3GÓHÒ3G¨CŸiœiÑ3GÑHÐIˆÜ�xŠx˜Ð/°rÑ:ˆàˆØˆà×#×#Ø!%×!9Ñ!9Ñà"& ¨*Ñ!4Ðä�z×"ˆAØ"×=Ñ=Ø$Ñ'¨óˆOð +×0Ñ0°Ñ3ˆLð
 ˜qÓ Ø!×-Ñ-¨aÑ0°×1NÑ1NÈqÑ1QÑR�’Q˜�T‘
Ø�\Ñ!�ÙØ’A�q˜|Ñ+Ð+Ð+Ñ,ˆCä—Z’Z §
¡
° 
Ð 2Ó3×;Ñ;Ó=ˆFØ(¨Ñ0ˆD’�A�‰Jà×"Ñ" hÓ.Ø×#Ñ#Ð'FÓFØ&Ñ)Ñ1äŸ*š* S§W¡W°! W _¸Ñ%9Ó:×BÑBÓD�à—;‘;—=‘=ð ×5Ñ5Ñ=Ø×8Ñ8¸Ñ;ÑCà+2˜Ò(à+/×+;Ñ+;¸AÑ+>Ø ×9Ñ9¸!Ñ<ñ,˜˜W a˜ZÑ(øô Ÿ*š* S§W¡W°! W _¸Ñ%9Ó:×BÑBÓD�Ø—;‘;—=‘=Ø×4Ñ4Ñ<Ü+-¯>ª>¸'Ó+BÐ(Ü(Ø&Ð'7Ð&8ð 9=ð =óð ð  $×<Ñ<¸QÑ?�HØ';Ñ'>¸xÑ'H�D˜ !˜Ñ$à�Ñ‹Añg #ön Ø�z‰zœVÓ#Ø—{‘{¤6Ó*�à*×0Ñ0Ö2‘	��TØ"&��T˜3�Y“ñ 3ð ˆùó_ 
ùò Is   Â-NÃ Nc                 óš  • [        U 5        [        X5      n[        U R                  5       VVs/ s H  u  p#U R	                  U5      PM     nnnU R                  5       n/ n[        [        U5      5       H0  nXB    Vs/ s H  ou" X   U5      PM     nnUR                  U5        M2     [        R                  " U[        S9$ s  snnf s  snf )ao  Get output feature names for transformation.

Parameters
----------
input_features : array-like of str or None, default=None
    Input features.

    - If `input_features` is `None`, then `feature_names_in_` is
      used as feature names in. If `feature_names_in_` is not defined,
      then the following input feature names are generated:
      `["x0", "x1", ..., "x(n_features_in_ - 1)"]`.
    - If `input_features` is an array-like, then `input_features` must
      match `feature_names_in_` if `feature_names_in_` is defined.

Returns
-------
feature_names_out : ndarray of str objects
    Transformed feature names.
rD   )r   r   r]   rP   r  Ú _check_get_feature_name_combinerr.   rN   Úextendr)   rR   r,   )	r0   Úinput_featuresr7   r4  rd   Úname_combinerÚfeature_namesÚtÚnamess	            r9   Úget_feature_names_outÚ#OneHotEncoder.get_feature_names_out¾  sÄ   € ô( 	˜ÔÜ0°ÓFˆô " $×"2Ñ"2Ô3ô
â3‘�ð ×0Ñ0°Ö3Ù3ð 	ñ 
ð
 ×=Ñ=Ó?ˆØˆÜ”s˜4“yÖ!ˆAØBFÂ'ÓJÂ'¸Q�] >Ñ#4°aÖ8Á'ˆEÐJØ× Ñ  Ö'ñ "ô �xŠx˜¬VÑ4Ð4ùó
ùò Ks   ¯CÁ>Cc                 ó¾   • U R                   S:X  a  S $ U R                  SS5      n[        U[        5      (       d  [        S[	        U5       S35      eU R                   $ )NrÙ   c                 ó$   • U S-   [        U5      -   $ )Nr4  )rê   )Úfeaturerh   s     r9   Ú<lambda>Ú@OneHotEncoder._check_get_feature_name_combiner.<locals>.<lambda>ã  s   € ¨W°s©]¼SÀ»]Ò-Jr<   rP  rh   zRWhen `feature_name_combiner` is a callable, it should return a Python string. Got z	 instead.)rÜ   rS   rê   Ú	TypeErrorrV   )r0   Údry_run_combiners     r9   rE  Ú.OneHotEncoder._check_get_feature_name_combinerá  sk   € Ø×%Ñ%¨Ó1ÙJÐJà#×9Ñ9¸)ÀZÓPÐÜÐ.´×4Ñ4Üð*Ü*.Ð/?Ó*@Ð)AÀðLóð ð ×-Ñ-Ð-r<   )rî   r  rM   rÚ   rï   r!   rÜ   r_   r”   r•   rÛ   rÇ   rß   )rW   rÈ   rÉ   rÊ   rË   r   Úlistr   r   r   ÚcallablerÝ   ÚdictÚ__annotations__r)   Úfloat64rà   ræ   rý   r  r  r  r   r  r  rB  rL  rE  rÍ   © r<   r9   r   r   Ù  s  ‡ ñQñh " 6 (Ó+¨TÐ2Ù˜W kÐ2Ó3°\À4ÐHØ áÒIÓJð
ñ $ H¨a°¸fÑEÀtÐLá�X˜q $¨vÑ6Ù�Z  A¨iÑ8Øð
ð
 $˜Ù",¨h¨ZÓ"8¸(Ð!Cñ$Ð˜Dó ð( ØØØ�j‰jØØØØ&õ;ò*/ò0rAôhò.òñ* °Ñ5óó 6ðò6Uònuôn!5õF
.r<   c                   óD  • \ rS rSr% Sr\" S15      \/S\\" \	R                  5      /\" SS15      /\\" \	R                  5      S/\" \SSS	S
9S/\" \SSS	S
9\" \SSSS
9S/S.r\\S'   S\	R                   SS\	R                  SSS.S jr\" SS9SS j5       rS rS rSrg)r   iî  a×  
Encode categorical features as an integer array.

The input to this transformer should be an array-like of integers or
strings, denoting the values taken on by categorical (discrete) features.
The features are converted to ordinal integers. This results in
a single column of integers (0 to n_categories - 1) per feature.

Read more in the :ref:`User Guide <preprocessing_categorical_features>`.
For a comparison of different encoders, refer to:
:ref:`sphx_glr_auto_examples_preprocessing_plot_target_encoder.py`.

.. versionadded:: 0.20

Parameters
----------
categories : 'auto' or a list 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 ith
      column. The passed categories should not mix strings and numeric
      values, and should be sorted in case of numeric values.

    The used categories can be found in the ``categories_`` attribute.

dtype : number type, default=np.float64
    Desired dtype of output.

handle_unknown : {'error', 'use_encoded_value'}, default='error'
    When set to 'error' an error will be raised in case an unknown
    categorical feature is present during transform. When set to
    'use_encoded_value', the encoded value of unknown categories will be
    set to the value given for the parameter `unknown_value`. In
    :meth:`inverse_transform`, an unknown category will be denoted as None.

    .. versionadded:: 0.24

unknown_value : int or np.nan, default=None
    When the parameter handle_unknown is set to 'use_encoded_value', this
    parameter is required and will set the encoded value of unknown
    categories. It has to be distinct from the values used to encode any of
    the categories in `fit`. If set to np.nan, the `dtype` parameter must
    be a float dtype.

    .. versionadded:: 0.24

encoded_missing_value : int or np.nan, default=np.nan
    Encoded value of missing categories. If set to `np.nan`, then the `dtype`
    parameter must be a float dtype.

    .. versionadded:: 1.1

min_frequency : int or float, default=None
    Specifies the minimum frequency below which a category will be
    considered infrequent.

    - If `int`, categories with a smaller cardinality will be considered
      infrequent.

    - If `float`, categories with a smaller cardinality than
      `min_frequency * n_samples`  will be considered infrequent.

    .. versionadded:: 1.3
        Read more in the :ref:`User Guide <encoder_infrequent_categories>`.

max_categories : int, default=None
    Specifies an upper limit to the number of output categories for each input
    feature when considering infrequent categories. If there are infrequent
    categories, `max_categories` includes the category representing the
    infrequent categories along with the frequent categories. If `None`,
    there is no limit to the number of output features.

    `max_categories` do **not** take into account missing or unknown
    categories. Setting `unknown_value` or `encoded_missing_value` to an
    integer will increase the number of unique integer codes by one each.
    This can result in up to `max_categories + 2` integer codes.

    .. versionadded:: 1.3
        Read more in the :ref:`User Guide <encoder_infrequent_categories>`.

Attributes
----------
categories_ : list of arrays
    The categories of each feature determined during ``fit`` (in order of
    the features in X and corresponding with the output of ``transform``).
    This does not include categories that weren't seen during ``fit``.

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

    .. versionadded:: 1.0

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.

    .. versionadded:: 1.0

infrequent_categories_ : list of ndarray
    Defined only if infrequent categories are enabled by setting
    `min_frequency` or `max_categories` to a non-default value.
    `infrequent_categories_[i]` are the infrequent categories for feature
    `i`. If the feature `i` has no infrequent categories
    `infrequent_categories_[i]` is None.

    .. versionadded:: 1.3

See Also
--------
OneHotEncoder : Performs a one-hot encoding of categorical features. This encoding
    is suitable for low to medium cardinality categorical variables, both in
    supervised and unsupervised settings.
TargetEncoder : Encodes categorical features using supervised signal
    in a classification or regression pipeline. This encoding is typically
    suitable for high cardinality categorical variables.
LabelEncoder : Encodes target labels with values between 0 and
    ``n_classes-1``.

Examples
--------
Given a dataset with two features, we let the encoder find the unique
values per feature and transform the data to an ordinal encoding.

>>> from sklearn.preprocessing import OrdinalEncoder
>>> enc = OrdinalEncoder()
>>> X = [['Male', 1], ['Female', 3], ['Female', 2]]
>>> enc.fit(X)
OrdinalEncoder()
>>> enc.categories_
[array(['Female', 'Male'], dtype=object), array([1, 2, 3], dtype=object)]
>>> enc.transform([['Female', 3], ['Male', 1]])
array([[0., 2.],
       [1., 0.]])

>>> enc.inverse_transform([[1, 0], [0, 1]])
array([['Male', 1],
       ['Female', 2]], dtype=object)

By default, :class:`OrdinalEncoder` is lenient towards missing values by
propagating them.

>>> import numpy as np
>>> X = [['Male', 1], ['Female', 3], ['Female', np.nan]]
>>> enc.fit_transform(X)
array([[ 1.,  0.],
       [ 0.,  1.],
       [ 0., nan]])

You can use the parameter `encoded_missing_value` to encode missing values.

>>> enc.set_params(encoded_missing_value=-1).fit_transform(X)
array([[ 1.,  0.],
       [ 0.,  1.],
       [ 0., -1.]])

Infrequent categories are enabled by setting `max_categories` or `min_frequency`.
In the following example, "a" and "d" are considered infrequent and grouped
together into a single category, "b" and "c" are their own categories, unknown
values are encoded as 3 and missing values are encoded as 4.

>>> X_train = np.array(
...     [["a"] * 5 + ["b"] * 20 + ["c"] * 10 + ["d"] * 3 + [np.nan]],
...     dtype=object).T
>>> enc = OrdinalEncoder(
...     handle_unknown="use_encoded_value", unknown_value=3,
...     max_categories=3, encoded_missing_value=4)
>>> _ = enc.fit(X_train)
>>> X_test = np.array([["a"], ["b"], ["c"], ["d"], ["e"], [np.nan]], dtype=object)
>>> enc.transform(X_test)
array([[2.],
       [0.],
       [1.],
       [2.],
       [3.],
       [4.]])
rB   rÒ   rH   Úuse_encoded_valueNr#   rÔ   rÕ   r   r×   )rM   r!   Úencoded_missing_valuer_   Úunknown_valuer”   r•   rÝ   ©rM   r!   r_   r_  r^  r•   r”   c                óX   • Xl         X l        X0l        X@l        XPl        X`l        Xpl        g rß   r`  )r0   rM   r!   r_   r_  r^  r•   r”   s           r9   rà   ÚOrdinalEncoder.__init__¯  s,   € ð %ŒØŒ
Ø,ÔØ*ÔØ%:Ô"Ø*ÔØ,Õr<   Tr  c                 óv  • U R                   S:X  a¥  [        U R                  5      (       aH  [        R                  " U R                  5      R
                  S:w  a  [        SU R                   S35      eOi[        U R                  [        R                  5      (       d  [        SU R                   S35      eO&U R                  b  [        SU R                   S35      eU R                  UU R                   SSS	9nUS
   U l        U R                   Vs/ s H  n[        U5      PM     nnU R                  (       a8  [!        U R"                  5       H  u  pgUc  M
  XV==   [        U5      -  ss'   M!     [!        U R                  5       H&  u  p‰[        U	S   5      (       d  M  XX==   S-  ss'   M(     U R                   S:X  a=  U H7  n
SU R                  s=::  a  U
:  d  M  O  M   [        SU R                   S35      e   U R                  (       Ga   [        R                  " U R                  5      R
                  S:w  aI  [        U R$                  5      (       a/  [        S['        U R                  5       SU R                   S35      e[        U R$                  5      (       d�  [!        U5       VV
s/ s H5  u  pŠX€R                  ;   d  M  SU R$                  s=::  a  U
:  d  M/  O  M3  UPM7     nnn
U(       a;  [)        U S5      (       a  U R*                  U   n[        SU R$                   SU 35      eU $ s  snf s  sn
nf )aD  
Fit the OrdinalEncoder to X.

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

y : None
    Ignored. This parameter exists only for compatibility with
    :class:`~sklearn.pipeline.Pipeline`.

Returns
-------
self : object
    Fitted encoder.
r]  ÚfzOWhen unknown_value is np.nan, the dtype parameter should be a float dtype. Got Ú.z]unknown_value should be an integer or np.nan when handle_unknown is 'use_encoded_value', got zQunknown_value should only be set when handle_unknown is 'use_encoded_value', got r  T)r_   r"   r`   rJ   rF   r#   r   z!The used value for unknown_value zD is one of the values already used for encoding the seen categories.z%There are missing values in features z:. For OrdinalEncoder to encode missing values with dtype: zG, set encoded_missing_value to a non-nan value, or set dtype to a floatÚfeature_names_in_zencoded_missing_value (z:) is already used to encode a known category in features: )r_   r   r_  r)   r!   rU   rO   rS   r™   r   rS  rp   Ú_missing_indicesrP   rN   rQ   r]   r‘   r^  rV  r'   rf  )r0   r1   r  Úfit_resultsrM   Úcardinalitiesrn   Ú
infrequentÚcat_idxro   ÚcardinalityÚinvalid_featuress               r9   r  ÚOrdinalEncoder.fitÂ  sS  € ð& ×ÑÐ"5Ó5Ü˜T×/Ñ/×0Ñ0Ü—8’8˜DŸJ™JÓ'×,Ñ,°Ó3Ü$ð.à.2¯j©j¨\¸ð<óð ð 4ô   × 2Ñ 2´G×4DÑ4D×EÑEÜðð  ×-Ñ-Ð.¨að1óð ð Fð ×ÑÑ+Üðà×)Ñ)Ð*¨!ð-óð ð —i‘iØØ×.Ñ.Ø)Ø59ð	  ð 
ˆð !,Ð,=Ñ >ˆÔà;?×;KÒ;KÓLÒ;K¨Zœ˜ZžÑ;KˆÐLØ×#×#ô ,5°T×5PÑ5PÖ+QÑ'�ØÓ)Ø!Ó.´#°j³/ÑAÕ.ñ ,Rô ,5°T×5EÑ5EÖ+FÑ'ˆGÜÐ/°Ñ3×4Ó4ØÓ&¨!Ñ+Õ&ñ ,Gð ×ÑÐ"5Ó5Û,�Ø˜×*Ñ*Õ8¨[×8Ñ8Ü$Ø;Ø×-Ñ-Ð.ð /+ð+óð ñ  -ð × × Ð Ü�xŠx˜Ÿ
™
Ó#×(Ñ(¨CÓ/´MØ×*Ñ*÷5ñ 5ô !Ø;Ü˜D×1Ñ1Ó2Ð3ð 49Ø9=¿¹¸ð E+ð+óð ô ! ×!;Ñ!;×<Ñ<ô 1:¸-Ô0Hô$â0HÑ,˜Ø×"7Ñ"7Ñ7ó ð ˜T×7Ñ7ÕE¸+ÑEó ñ Fõ Ù0Hð !ñ $ö $ä˜tÐ%8×9Ñ9Ø+/×+AÑ+AÐBRÑ+SÐ(Ü$Ø1°$×2LÑ2LÐ1Mð NSà+Ð,ð.óð ð ˆùòs MùóP$s   ÄL0Ê-L5ËL5ËL5Ë#L5c                 ó^  • [        U S5        U R                  UU R                  SU R                  S9u  p#UR	                  U R
                  SS9nU R                  R                  5        H!  u  pVUSS2U4   U:H  nU R                  XGU4'   M#     U R                  S:X  a  U R                  XC) '   U$ )z×
Transform X to ordinal codes.

Parameters
----------
X : array-like of shape (n_samples, n_features)
    The data to encode.

Returns
-------
X_out : ndarray of shape (n_samples, n_features)
    Transformed input.
rP   r  )r_   r"   r†   F©r€   Nr]  )	r   r‹   r_   rg  r   r!   r3  r^  r_  )r0   r1   r‡   rˆ   ÚX_transrk  Úmissing_idxÚX_missing_masks           r9   r  ÚOrdinalEncoder.transform/  s¼   € ô 	˜˜mÔ,ØŸ™ØØ×.Ñ.Ø)Ø$(×$9Ñ$9ð	 (ð 
‰ˆð —,‘,˜tŸz™z°�,Ð6ˆà$(×$9Ñ$9×$?Ñ$?Ö$AÑ ˆGØ"¢1 g :Ñ.°+Ñ=ˆNØ/3×/IÑ/IˆG GÐ+Ó,ñ %Bð
 ×ÑÐ"5Ó5Ø#×1Ñ1ˆG�GÑØˆr<   c                 óð  • [        U 5        [        USS9nUR                  u  p#[        U R                  5      nSnUR                  S   U:w  a'  [        UR                  XAR                  S   5      5      e[        R                  " U R                   Vs/ s H  ofR                  PM     sn6 n[        R                  " X$4US9n0 n	0 n
[        U SS5      n[        U5       GH  nUSS2U4   nXÀR                  ;   a&  [        XÐR                  5      nU R                  U   XÞ'   [!        S5      nU R                  U   nUbO  X¼   bJ  [        U5      [        X¼   5      -
  nUU:H  X¬'   X¬   ) n[        R"                  " U[$        S9nSUX¼   '   UU   nU R&                  S	:X  aC  [        XÐR(                  5      nUXœ'   U) n[+        U[        R,                  5      (       a  UU-  nOUnXß   R/                  S
SS9nUU   X�U4'   GM     U	(       d  U
(       a  UR/                  [0        SS9nU	(       a!  U	R3                  5        H  u  nnSUUU4'   M     U
(       a!  U
R3                  5        H  u  nnSUUU4'   M     U$ s  snf )a  
Convert the data back to the original representation.

Parameters
----------
X : array-like of shape (n_samples, n_encoded_features)
    The transformed data.

Returns
-------
X_original : ndarray of shape (n_samples, n_features)
    Inverse transformed array.
r  rA   r/  r#   rD   rŽ   NFr]  r«   rp  r   )r   r
   r-   rN   rP   rO   r\   r)   r0  r!   rª   r(   r.   rg  r   r^  r¹   Ú	ones_liker|   r_   r_  rS   Úndarrayr   r,   r3  )r0   r1   r4   r4  r5   rg   rñ   r6  r7  r9  Úinfrequent_masksr�   r7   r=  ÚX_i_maskr¼   rM   Úinfrequent_encoding_valueÚfrequent_categories_maskÚunknown_labelsÚknown_labelsÚ
labels_intrA  r'  s                           r9   rB  Ú OrdinalEncoder.inverse_transformO  s‹  € ô 	˜ÔÜ˜¨[Ñ9ˆà—w‘w‰ˆ	Ü˜×)Ñ)Ó*ˆ
ð Xð 	ð �7‰7�1‰:˜Ó#Ü˜SŸZ™Z¨
·G±G¸A±JÓ?Ó@Ð@ô �^Š^°4×3CÒ3CÓDÒ3C¨CŸiœiÑ3CÑDÐEˆÜ�xŠx˜Ð/°rÑ:ˆàˆØÐä$ TÐ+@À$ÓGÐä�z×"ˆAØ’q˜!�t‘WˆFð ×)Ñ)Ó)Ü$ V×-GÑ-GÓH�Ø#'×#8Ñ#8¸Ñ#;�Ñ ä" 4›[ˆNØ×)Ñ)¨!Ñ,ˆJà!Ñ-Ð2DÑ2GÑ2Sä,/°
«O¼cÐBTÑBWÓ>XÑ,XÐ)Ø&,Ð0IÑ&IÐ Ñ#Ø"2Ñ"5Ð!5�ô ,.¯<ª<¸
Ì$Ñ+OÐ(ØBGÐ(Ð);Ñ)>Ñ?Ø'Ð(@ÑA�
à×"Ñ"Ð&9Ó9Ü!*¨6×3EÑ3EÓ!F�Ø#1�Ñ à .˜�Ü˜n¬b¯j©j×9Ñ9Ø" lÑ2‘Nà%1�NàÑ/×6Ñ6°wÀUÐ6ÐKˆJØ&0°Ñ&<ˆD Ð"Ô#ñE #öH Ö,Ø—;‘;œv¨E�;Ð2ˆDö Ø*×0Ñ0Ö2‘	��TØ"&��T˜3�Y“ñ 3ö Ø-×3Ñ3Ö5‘	��TØ"6��T˜3�Y“ñ 6ð ˆùòq Es   ÂI3)rg  rM   r!   r^  r_   r”   r•   r_  rß   )rW   rÈ   rÉ   rÊ   rË   r   rV  r   rV   r)   Únanr   r   rÝ   rX  rY  rZ  rà   r   r  r  rB  rÍ   r[  r<   r9   r   r   î  sâ   ‡ ñpñf " 6 (Ó+¨TÐ2Ø Ø"*©D°·±«LÐ!9Ù% wÐ0CÐ&DÓEÐFØ"¡D¨¯©£L°$Ð7Ù# H¨a°¸fÑEÀtÐLá�X˜q $¨vÑ6Ù�Z  A¨iÑ8Øð
ñ$Ð˜Dó ð" Ø�j‰jØØØ Ÿf™fØØõ-ñ& °Ñ5ójó 6ðjòXõ@Tr<   )&r™   r�   r   Únumpyr)   Úscipyr   Úsklearn.baser   r   r   r   Úsklearn.utilsr	   r
   Úsklearn.utils._encoder   r   r   r   Úsklearn.utils._maskr   Úsklearn.utils._missingr   Úsklearn.utils._param_validationr   r   r   Úsklearn.utils._set_outputr   Úsklearn.utils.validationr   r   r   Ú__all__r   r   r   r[  r<   r9   Ú<module>rŒ     sƒ   ðó Û Ý ã Ý ÷ó ÷ 6ß OÓ OÝ )Ý 0ß LÑ LÝ 8÷ñ ð Ð,Ð
-€ôvÐ# ]ô vôrR.�Lô R.ôjuÐ)¨<õ ur<   