ó
    ¦ñ:i¨x  ã                   óh  • S SK r S SKrS SKrS SKJr  S SKJr  S SK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  SSKJrJr  SS	KJrJr  SS
KJr  SSKJrJrJ r   / SQr! " S S\\SS9r" " S S\\SS9r#\" SS/S/\" \SSSS9/\" \SSSS9/S/S.SS9S SSS.S j5       r$S r%S r& " S  S!\\SS9r'g)"é    N)Údefaultdict)ÚIntegralé   )ÚBaseEstimatorÚTransformerMixinÚ_fit_context)Úcolumn_or_1d)Ú_encodeÚ_unique)ÚIntervalÚvalidate_params)Útype_of_targetÚunique_labels)Úmin_max_axis)Ú_num_samplesÚcheck_arrayÚcheck_is_fitted)Úlabel_binarizeÚLabelBinarizerÚLabelEncoderÚMultiLabelBinarizerc                   ó6   • \ rS rSrSrS rS rS rS rS r	Sr
g	)
r   é"   a  Encode target labels with value between 0 and n_classes-1.

This transformer should be used to encode target values, *i.e.* `y`, and
not the input `X`.

Read more in the :ref:`User Guide <preprocessing_targets>`.

.. versionadded:: 0.12

Attributes
----------
classes_ : ndarray of shape (n_classes,)
    Holds the label for each class.

See Also
--------
OrdinalEncoder : Encode categorical features using an ordinal encoding
    scheme.
OneHotEncoder : Encode categorical features as a one-hot numeric array.

Examples
--------
`LabelEncoder` can be used to normalize labels.

>>> from sklearn.preprocessing import LabelEncoder
>>> le = LabelEncoder()
>>> le.fit([1, 2, 2, 6])
LabelEncoder()
>>> le.classes_
array([1, 2, 6])
>>> le.transform([1, 1, 2, 6])
array([0, 0, 1, 2]...)
>>> le.inverse_transform([0, 0, 1, 2])
array([1, 1, 2, 6])

It can also be used to transform non-numerical labels (as long as they are
hashable and comparable) to numerical labels.

>>> le = LabelEncoder()
>>> le.fit(["paris", "paris", "tokyo", "amsterdam"])
LabelEncoder()
>>> list(le.classes_)
[np.str_('amsterdam'), np.str_('paris'), np.str_('tokyo')]
>>> le.transform(["tokyo", "tokyo", "paris"])
array([2, 2, 1]...)
>>> list(le.inverse_transform([2, 2, 1]))
[np.str_('tokyo'), np.str_('tokyo'), np.str_('paris')]
c                 ó:   • [        USS9n[        U5      U l        U $ )z±Fit label encoder.

Parameters
----------
y : array-like of shape (n_samples,)
    Target values.

Returns
-------
self : returns an instance of self.
    Fitted label encoder.
T©Úwarn©r	   r   Úclasses_©ÚselfÚys     Ú_/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/sklearn/preprocessing/_label.pyÚfitÚLabelEncoder.fitT   s    € ô ˜ Ñ&ˆÜ ›
ˆŒØˆó    c                 ó>   • [        USS9n[        USS9u  U l        nU$ )zÆFit label encoder and return encoded labels.

Parameters
----------
y : array-like of shape (n_samples,)
    Target values.

Returns
-------
y : array-like of shape (n_samples,)
    Encoded labels.
Tr   ©Úreturn_inverser   r   s     r"   Úfit_transformÚLabelEncoder.fit_transforme   s(   € ô ˜ Ñ&ˆÜ" 1°TÑ:ÑˆŒ�qØˆr%   c                 óÄ   • [        U 5        [        XR                  R                  SS9n[	        U5      S:X  a  [
        R                  " / 5      $ [        XR                  S9$ )zÒTransform labels to normalized encoding.

Parameters
----------
y : array-like of shape (n_samples,)
    Target values.

Returns
-------
y : array-like of shape (n_samples,)
    Labels as normalized encodings.
T)Údtyper   r   )Úuniques)r   r	   r   r,   r   ÚnpÚarrayr
   r   s     r"   Ú	transformÚLabelEncoder.transformv   sK   € ô 	˜ÔÜ˜§-¡-×"5Ñ"5¸DÑAˆä˜‹?˜aÓÜ—8’8˜B“<Ðä�q§-¡-Ñ0Ð0r%   c                 óŠ  • [        U 5        [        USS9n[        U5      S:X  a  [        R                  " / 5      $ [        R
                  " U[        R                  " [        U R                  5      5      5      n[        U5      (       a  [        S[        U5      -  5      e[        R                  " U5      nU R                  U   $ )zÂTransform labels back to original encoding.

Parameters
----------
y : ndarray of shape (n_samples,)
    Target values.

Returns
-------
y : ndarray of shape (n_samples,)
    Original encoding.
Tr   r   z'y contains previously unseen labels: %s)r   r	   r   r.   r/   Ú	setdiff1dÚarangeÚlenr   Ú
ValueErrorÚstrÚasarray)r    r!   Údiffs      r"   Úinverse_transformÚLabelEncoder.inverse_transform‹   sŽ   € ô 	˜ÔÜ˜ Ñ&ˆä˜‹?˜aÓÜ—8’8˜B“<Ðä�|Š|˜AœrŸyšy¬¨T¯]©]Ó);Ó<Ó=ˆÜˆt�9‰9ÜÐFÌÈTËÑRÓSÐSÜ�JŠJ�q‹MˆØ�}‰}˜QÑÐr%   c                 ó   • SS/0$ ©NÚX_typesÚ1dlabels© ©r    s    r"   Ú
_more_tagsÚLabelEncoder._more_tags¤   ó   € Ø˜J˜<Ð(Ð(r%   )r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r#   r)   r0   r:   rB   Ú__static_attributes__r@   r%   r"   r   r   "   s!   † ñ/òbò"ò"1ò* õ2)r%   r   )Úauto_wrap_output_keysc                   ó|   • \ rS rSr% Sr\/\/S/S.r\\S'   SSSS.S	 jr	\
" S
S9S 5       rS rS rSS jrS rSrg)r   é¨   a³	  Binarize labels in a one-vs-all fashion.

Several regression and binary classification algorithms are
available in scikit-learn. A simple way to extend these algorithms
to the multi-class classification case is to use the so-called
one-vs-all scheme.

At learning time, this simply consists in learning one regressor
or binary classifier per class. In doing so, one needs to convert
multi-class labels to binary labels (belong or does not belong
to the class). `LabelBinarizer` makes this process easy with the
transform method.

At prediction time, one assigns the class for which the corresponding
model gave the greatest confidence. `LabelBinarizer` makes this easy
with the :meth:`inverse_transform` method.

Read more in the :ref:`User Guide <preprocessing_targets>`.

Parameters
----------
neg_label : int, default=0
    Value with which negative labels must be encoded.

pos_label : int, default=1
    Value with which positive labels must be encoded.

sparse_output : bool, default=False
    True if the returned array from transform is desired to be in sparse
    CSR format.

Attributes
----------
classes_ : ndarray of shape (n_classes,)
    Holds the label for each class.

y_type_ : str
    Represents the type of the target data as evaluated by
    :func:`~sklearn.utils.multiclass.type_of_target`. Possible type are
    'continuous', 'continuous-multioutput', 'binary', 'multiclass',
    'multiclass-multioutput', 'multilabel-indicator', and 'unknown'.

sparse_input_ : bool
    `True` if the input data to transform is given as a sparse matrix,
     `False` otherwise.

See Also
--------
label_binarize : Function to perform the transform operation of
    LabelBinarizer with fixed classes.
OneHotEncoder : Encode categorical features using a one-hot aka one-of-K
    scheme.

Examples
--------
>>> from sklearn.preprocessing import LabelBinarizer
>>> lb = LabelBinarizer()
>>> lb.fit([1, 2, 6, 4, 2])
LabelBinarizer()
>>> lb.classes_
array([1, 2, 4, 6])
>>> lb.transform([1, 6])
array([[1, 0, 0, 0],
       [0, 0, 0, 1]])

Binary targets transform to a column vector

>>> lb = LabelBinarizer()
>>> lb.fit_transform(['yes', 'no', 'no', 'yes'])
array([[1],
       [0],
       [0],
       [1]])

Passing a 2D matrix for multilabel classification

>>> import numpy as np
>>> lb.fit(np.array([[0, 1, 1], [1, 0, 0]]))
LabelBinarizer()
>>> lb.classes_
array([0, 1, 2])
>>> lb.transform([0, 1, 2, 1])
array([[1, 0, 0],
       [0, 1, 0],
       [0, 0, 1],
       [0, 1, 0]])
Úboolean©Ú	neg_labelÚ	pos_labelÚsparse_outputÚ_parameter_constraintsr   é   Fc                ó(   • Xl         X l        X0l        g ©NrO   )r    rP   rQ   rR   s       r"   Ú__init__ÚLabelBinarizer.__init__  s   € Ø"ŒØ"ŒØ*Õr%   T©Úprefer_skip_nested_validationc                 ó  • U R                   U R                  :¼  a&  [        SU R                    SU R                   S35      eU R                  (       aE  U R                  S:X  d  U R                   S:w  a%  [        SU R                   SU R                    35      e[	        USS9U l        S	U R
                  ;   a  [        S
5      e[        U5      S:X  a  [        SU-  5      e[        R                  " U5      U l	        [        U5      U l        U $ )a  Fit label binarizer.

Parameters
----------
y : ndarray of shape (n_samples,) or (n_samples, n_classes)
    Target values. The 2-d matrix should only contain 0 and 1,
    represents multilabel classification.

Returns
-------
self : object
    Returns the instance itself.
z
neg_label=z& must be strictly less than pos_label=Ú.r   z`Sparse binarization is only supported with non zero pos_label and zero neg_label, got pos_label=z and neg_label=r!   )Ú
input_nameÚmultioutputú@Multioutput target data is not supported with label binarizationúy has 0 samples: %r)rP   rQ   r6   rR   r   Úy_type_r   ÚspÚissparseÚsparse_input_r   r   r   s     r"   r#   ÚLabelBinarizer.fit  sý   € ð �>‰>˜TŸ^™^Ó+ÜØ˜TŸ^™^Ð,ð -Ø!Ÿ^™^Ð,¨Að/óð ð
 ×× 4§>¡>°QÓ#6¸$¿.¹.ÈAÓ:MÜðà!Ÿ^™^Ð,¨O¸D¿N¹NÐ;KðMóð ô & a°CÑ8ˆŒà˜DŸL™LÓ(ÜØRóð ô ˜‹?˜aÓÜÐ2°QÑ6Ó7Ð7äŸ[š[¨›^ˆÔÜ% aÓ(ˆŒØˆr%   c                 óB   • U R                  U5      R                  U5      $ )aQ  Fit label binarizer/transform multi-class labels to binary labels.

The output of transform is sometimes referred to as
the 1-of-K coding scheme.

Parameters
----------
y : {ndarray, sparse matrix} of shape (n_samples,) or                 (n_samples, n_classes)
    Target values. The 2-d matrix should only contain 0 and 1,
    represents multilabel classification. Sparse matrix can be
    CSR, CSC, COO, DOK, or LIL.

Returns
-------
Y : {ndarray, sparse matrix} of shape (n_samples, n_classes)
    Shape will be (n_samples, 1) for binary problems. Sparse matrix
    will be of CSR format.
)r#   r0   r   s     r"   r)   ÚLabelBinarizer.fit_transform5  s   € ð( �x‰x˜‹{×$Ñ$ QÓ'Ð'r%   c                 ó  • [        U 5        [        U5      R                  S5      nU(       a+  U R                  R                  S5      (       d  [	        S5      e[        UU R                  U R                  U R                  U R                  S9$ )aK  Transform multi-class labels to binary labels.

The output of transform is sometimes referred to by some authors as
the 1-of-K coding scheme.

Parameters
----------
y : {array, sparse matrix} of shape (n_samples,) or                 (n_samples, n_classes)
    Target values. The 2-d matrix should only contain 0 and 1,
    represents multilabel classification. Sparse matrix can be
    CSR, CSC, COO, DOK, or LIL.

Returns
-------
Y : {ndarray, sparse matrix} of shape (n_samples, n_classes)
    Shape will be (n_samples, 1) for binary problems. Sparse matrix
    will be of CSR format.
Ú
multilabelz0The object was not fitted with multilabel input.)ÚclassesrQ   rP   rR   )
r   r   Ú
startswithra   r6   r   r   rQ   rP   rR   )r    r!   Úy_is_multilabels      r"   r0   ÚLabelBinarizer.transformK  sr   € ô( 	˜Ôä(¨Ó+×6Ñ6°|ÓDˆÞ 4§<¡<×#:Ñ#:¸<×#HÑ#HÜÐOÓPÐPäØØ—M‘MØ—n‘nØ—n‘nØ×,Ñ,ñ
ð 	
r%   Nc                 ó�  • [        U 5        Uc  U R                  U R                  -   S-  nU R                  S:X  a  [	        XR
                  5      nO![        XR                  U R
                  U5      nU R                  (       a  [        R                  " U5      nU$ [        R                  " U5      (       a  UR                  5       nU$ )aÜ  Transform binary labels back to multi-class labels.

Parameters
----------
Y : {ndarray, sparse matrix} of shape (n_samples, n_classes)
    Target values. All sparse matrices are converted to CSR before
    inverse transformation.

threshold : float, default=None
    Threshold used in the binary and multi-label cases.

    Use 0 when ``Y`` contains the output of :term:`decision_function`
    (classifier).
    Use 0.5 when ``Y`` contains the output of :term:`predict_proba`.

    If None, the threshold is assumed to be half way between
    neg_label and pos_label.

Returns
-------
y : {ndarray, sparse matrix} of shape (n_samples,)
    Target values. Sparse matrix will be of CSR format.

Notes
-----
In the case when the binary labels are fractional
(probabilistic), :meth:`inverse_transform` chooses the class with the
greatest value. Typically, this allows to use the output of a
linear model's :term:`decision_function` method directly as the input
of :meth:`inverse_transform`.
g       @Ú
multiclass)r   rQ   rP   ra   Ú_inverse_binarize_multiclassr   Ú_inverse_binarize_thresholdingrd   rb   Ú
csr_matrixrc   Útoarray)r    ÚYÚ	thresholdÚy_invs       r"   r:   Ú LabelBinarizer.inverse_transformm  sž   € ô@ 	˜ÔàÑØŸ™¨$¯.©.Ñ8¸CÑ?ˆIà�<‰<˜<Ó'Ü0°·M±MÓB‰Eä2Ø—<‘< §¡°	óˆEð ××Ü—M’M %Ó(ˆEð ˆô �[Š[˜×ÑØ—M‘M“OˆEàˆr%   c                 ó   • SS/0$ r=   r@   rA   s    r"   rB   ÚLabelBinarizer._more_tags   rD   r%   )r   rP   rQ   rd   rR   ra   rV   )rE   rF   rG   rH   rI   r   rS   ÚdictÚ__annotations__rW   r   r#   r)   r0   r:   rB   rJ   r@   r%   r"   r   r   ¨   sg   ‡ ñVðr �ZØ�ZØ#˜ñ$Ð˜Dó ð %&°À%õ +ñ
 °Ñ5ñ&ó 6ð&òP(ò, 
ôD1õf)r%   r   ú
array-likezsparse matrixÚneither)ÚclosedrN   )r!   rj   rP   rQ   rR   TrY   rT   FrO   c                óø  • [        U [        5      (       d  [        U SSSSS9n O[        U 5      S:X  a  [	        SU -  5      eX#:¼  a  [	        SR                  X#5      5      eU(       a&  US:X  d  US:w  a  [	        S	R                  X25      5      eUS:H  nU(       a  U* n[        U 5      nS
U;   a  [	        S5      eUS:X  a  [	        S5      e[        R                  " U 5      (       a  U R                  S   O
[        U 5      n[        U5      n[        R                  " U5      nUS:X  ac  US:X  aL  U(       a  [        R                  " US4[        S9$ [        R                  " [        U 5      S4[        S9n	X’-  n	U	$ [        U5      S:¼  a  Sn[        R                   " U5      n
US:X  ab  [#        U S5      (       a  U R                  S   O[        U S   5      nUR$                  U:w  a$  [	        SR                  U['        U 5      5      5      eUS;   a§  [)        U 5      n [        R*                  " X5      nX   n[        R,                  " X­5      n[        R.                  " S[        R0                  " U5      45      n[        R2                  " U5      nUR5                  U5        [        R                  " UXï4Xx4S9n	OiUS:X  aU  [        R                  " U 5      n	US:w  a8  [        R2                  " U	R6                  5      nUR5                  U5        UU	l        O[	        SU-  5      eU(       d@  U	R9                  5       n	U	R;                  [        SS9n	US:w  a  X)U	S:H  '   U(       a  SX™U:H  '   O#U	R6                  R;                  [        SS9U	l        [        R<                  " X:g  5      (       a  [        R,                  " X¡5      nU	SS2U4   n	US:X  a2  U(       a  U	R?                  S5      n	U	$ U	SS2S4   RA                  S5      n	U	$ )an  Binarize labels in a one-vs-all fashion.

Several regression and binary classification algorithms are
available in scikit-learn. A simple way to extend these algorithms
to the multi-class classification case is to use the so-called
one-vs-all scheme.

This function makes it possible to compute this transformation for a
fixed set of class labels known ahead of time.

Parameters
----------
y : array-like or sparse matrix
    Sequence of integer labels or multilabel data to encode.

classes : array-like of shape (n_classes,)
    Uniquely holds the label for each class.

neg_label : int, default=0
    Value with which negative labels must be encoded.

pos_label : int, default=1
    Value with which positive labels must be encoded.

sparse_output : bool, default=False,
    Set to true if output binary array is desired in CSR sparse format.

Returns
-------
Y : {ndarray, sparse matrix} of shape (n_samples, n_classes)
    Shape will be (n_samples, 1) for binary problems. Sparse matrix will
    be of CSR format.

See Also
--------
LabelBinarizer : Class used to wrap the functionality of label_binarize and
    allow for fitting to classes independently of the transform operation.

Examples
--------
>>> from sklearn.preprocessing import label_binarize
>>> label_binarize([1, 6], classes=[1, 2, 4, 6])
array([[1, 0, 0, 0],
       [0, 0, 0, 1]])

The class ordering is preserved:

>>> label_binarize([1, 6], classes=[1, 6, 4, 2])
array([[1, 0, 0, 0],
       [0, 1, 0, 0]])

Binary targets transform to a column vector

>>> label_binarize(['yes', 'no', 'no', 'yes'], classes=['no', 'yes'])
array([[1],
       [0],
       [0],
       [1]])
r!   ÚcsrFN)r]   Úaccept_sparseÚ	ensure_2dr,   r   r`   z7neg_label={0} must be strictly less than pos_label={1}.zuSparse binarization is only supported with non zero pos_label and zero neg_label, got pos_label={0} and neg_label={1}r^   r_   Úunknownz$The type of target data is not knownÚbinaryrT   ©r,   é   ro   úmultilabel-indicatorÚshapez:classes {0} mismatch with the labels {1} found in the data)r„   ro   ©rˆ   z7%s target data is not supported with label binarization)Úcopyéÿÿÿÿ)r‹   rT   )!Ú
isinstanceÚlistr   r   r6   Úformatr   rb   rc   rˆ   r5   r.   r8   rr   ÚintÚzerosÚsortÚhasattrÚsizer   r	   ÚisinÚsearchsortedÚhstackÚcumsumÚ
empty_likeÚfillÚdatars   ÚastypeÚanyÚgetcolÚreshape)r!   rj   rP   rQ   rR   Ú
pos_switchÚy_typeÚ	n_samplesÚ	n_classesrt   Úsorted_classÚy_n_classesÚy_in_classesÚy_seenÚindicesÚindptrrš   s                    r"   r   r   ¤  sŽ  € ôL �aœ×Ñô Ø˜#¨U¸eÈ4ñ
‰ô ˜‹?˜aÓÜÐ2°QÑ6Ó7Ð7ØÓÜØE×LÑLØóó
ð 	
ö ˜) q›.¨I¸«NÜð÷ ‰v�iÓ+ó	
ð 	
ð ˜a‘€JÞØ�Jˆ	ä˜AÓ€FØ˜ÓÜØNó
ð 	
ð �ÓÜÐ?Ó@Ð@ä Ÿkšk¨!Ÿn™n�—‘˜’
´#°a³&€IÜ�G“€IÜ�jŠj˜Ó!€Gà�ÓØ˜‹>ÞÜ—}’} i° ^¼3Ñ?Ð?ä—H’Hœc !›f a˜[´Ñ4�Ø‘�Ø�Ü�‹\˜QÓØ!ˆFä—7’7˜7Ó#€LØÐ'Ó'Ü$+¨A¨w×$7Ñ$7�a—g‘g˜a’j¼SÀÀ1Á»YˆØ�<‰<˜;Ó&ÜØL×SÑSØœ]¨1Ó-óóð ð Ð)Ó)Ü˜‹Oˆô —w’w˜qÓ*ˆØ‘ˆÜ—/’/ ,Ó7ˆÜ—’˜AœrŸyšy¨Ó6Ð7Ó8ˆä�}Š}˜WÓ%ˆØ�	‰	�)ÔÜ�MŠM˜4 Ð1¸)Ð9OÑP‰Ø	Ð)Ó	)Ü�MŠM˜!ÓˆØ˜‹>Ü—=’= §¡Ó(ˆDØ�I‰I�iÔ ØˆAŒFøäØEÈÑNó
ð 	
ö Ø�I‰I‹KˆØ�H‰H”S˜uˆHÐ%ˆà˜‹>Ø!ˆa�1‰f‰IæØ !ˆA�9‰nÑøà—‘—‘œs¨�Ð/ˆŒô 
‡v‚vˆgÑ%×&Ñ&Ü—/’/ ,Ó8ˆØŠa�ˆj‰Mˆà�ÓÞØ—‘˜“ˆAð €Hð ’!�R�%‘× Ñ  Ó)ˆAà€Hr%   c                 ó"  • [         R                  " U5      n[        R                  " U 5      (       GaÁ  U R	                  5       n U R
                  u  p#[         R                  " U5      n[        U S5      S   n[         R                  " U R                  5      n[         R                  " XV5      n[         R                  " XpR                  :H  5      nUS   S:X  a+  [         R                  " U[        U R                  5      /5      n[         R                  " X€R                  SS 5      n	[         R                  " U R                   S/5      n
X¨U	      nSU[         R"                  " US:H  5      S   '   [         R                  " U5      US:„  UR%                  5       S:H  -     nU HM  nU R                   U R                  U   U R                  US-       nU[         R&                  " XN5         S   X½'   MO     X   $ UR)                  U R+                  SS9SS9$ )zuInverse label binarization transformation for multiclass.

Multiclass uses the maximal score instead of a threshold.
rT   r‹   r   N)ÚaxisÚclip)Úmode)r.   r8   rb   rc   Útocsrrˆ   r4   r   r9   r¨   ÚrepeatÚflatnonzerorš   Úappendr5   r•   r§   ÚwhereÚravelr3   ÚtakeÚargmax)r!   rj   r¡   Ú	n_outputsÚoutputsÚrow_maxÚrow_nnzÚy_data_repeated_maxÚy_i_all_argmaxÚindex_first_argmaxÚ	y_ind_extÚ
y_i_argmaxÚsamplesÚiÚinds                  r"   rp   rp   Y  s«  € ô
 �jŠj˜Ó!€Gä	‡{‚{�1‡~‚~ð �G‰G‹IˆØ Ÿw™wÑˆ	Ü—)’)˜IÓ&ˆÜ˜q !Ó$ QÑ'ˆÜ—'’'˜!Ÿ(™(Ó#ˆä Ÿiši¨Ó9ÐäŸšÐ(;¿v¹vÑ(EÓFˆð �2‰;˜!ÓÜŸYšY ~¼¸A¿F¹F»°}ÓEˆNô  Ÿ_š_¨^¿X¹XÀcÀr¸]ÓKÐä—I’I˜aŸi™i¨!¨Ó-ˆ	ØÐ.@ÑAÑBˆ
à01ˆ
”2—8’8˜G q™LÓ)¨!Ñ,Ñ-ô —)’)˜IÓ&¨°!©¸¿¹»È1Ñ8LÑ'MÑNˆÛˆAØ—)‘)˜AŸH™H Q™K¨!¯(©(°1°q±5©/Ð:ˆCØ#¤B§L¢L°Ó$>Ñ?ÀÑBˆJ‹Mñ ð Ñ"Ð"à�|‰|˜AŸH™H¨!˜HÐ,°6ˆ|Ð:Ð:r%   c                 ó2  • US:X  aG  U R                   S:X  a7  U R                  S   S:”  a$  [        SR                  U R                  5      5      eUS:w  a'  U R                  S   [	        U5      :w  a  [        S5      e[
        R                  " U5      n[        R                  " U 5      (       a�  US:”  a\  U R                  S;  a  U R                  5       n [
        R                  " U R                  U:„  [        S9U l        U R                  5         OF[
        R                  " U R                  5       U:„  [        S9n O[
        R                  " X:„  [        S9n US:X  a�  [        R                  " U 5      (       a  U R                  5       n U R                   S:X  a  U R                  S   S:X  a  X S	S	2S4      $ [	        U5      S:X  a#  [
        R                  " US   [	        U 5      5      $ X R!                  5          $ US
:X  a  U $ [        SR                  U5      5      e)z=Inverse label binarization transformation using thresholding.r„   r   rT   z'output_type='binary', but y.shape = {0}zAThe number of class is not equal to the number of dimension of y.r   )r€   Úcscr…   Nr‡   z{0} format is not supported)Úndimrˆ   r6   rŽ   r5   r.   r8   rb   rc   r­   r/   rš   r�   Úeliminate_zerosrs   r®   r²   )r!   Úoutput_typerj   ru   s       r"   rq   rq   „  s¢  € ð �hÓ 1§6¡6¨Q£;°1·7±7¸1±:À³>ÜÐB×IÑIÈ!Ï'É'ÓRÓSÐSà�hÓ 1§7¡7¨1¡:´°W³Ó#=ÜØOó
ð 	
ô �jŠj˜Ó!€Gô 
‡{‚{�1‡~�~Ø�q‹=Ø�x‰x˜~Ó-Ø—G‘G“I�Ü—X’X˜aŸf™f yÑ0¼Ñ<ˆAŒFØ×ÑÕä—’˜Ÿ™› yÑ0¼Ñ<‰Aä�HŠH�Q‘]¬#Ñ.ˆð �hÓÜ�;Š;�q�>‰>Ø—	‘	“ˆAØ�6‰6�Q‹;˜1Ÿ7™7 1™:¨›?ØšQ ˜T™7Ñ#Ð#ä�7‹|˜qÓ Ü—y’y ¨¡¬S°«VÓ4Ð4àŸw™w›yÑ)Ð)à	Ð.Ó	.Øˆô Ð6×=Ñ=¸kÓJÓKÐKr%   c                   ó’   • \ rS rSr% SrSS/S/S.r\\S'   SSS.S	 jr\	" S
S9S 5       r
\	" S
S9S 5       rS rS rS rS rS rSrg)r   i°  a<  Transform between iterable of iterables and a multilabel format.

Although a list of sets or tuples is a very intuitive format for multilabel
data, it is unwieldy to process. This transformer converts between this
intuitive format and the supported multilabel format: a (samples x classes)
binary matrix indicating the presence of a class label.

Parameters
----------
classes : array-like of shape (n_classes,), default=None
    Indicates an ordering for the class labels.
    All entries should be unique (cannot contain duplicate classes).

sparse_output : bool, default=False
    Set to True if output binary array is desired in CSR sparse format.

Attributes
----------
classes_ : ndarray of shape (n_classes,)
    A copy of the `classes` parameter when provided.
    Otherwise it corresponds to the sorted set of classes found
    when fitting.

See Also
--------
OneHotEncoder : Encode categorical features using a one-hot aka one-of-K
    scheme.

Examples
--------
>>> from sklearn.preprocessing import MultiLabelBinarizer
>>> mlb = MultiLabelBinarizer()
>>> mlb.fit_transform([(1, 2), (3,)])
array([[1, 1, 0],
       [0, 0, 1]])
>>> mlb.classes_
array([1, 2, 3])

>>> mlb.fit_transform([{'sci-fi', 'thriller'}, {'comedy'}])
array([[0, 1, 1],
       [1, 0, 0]])
>>> list(mlb.classes_)
['comedy', 'sci-fi', 'thriller']

A common mistake is to pass in a list, which leads to the following issue:

>>> mlb = MultiLabelBinarizer()
>>> mlb.fit(['sci-fi', 'thriller', 'comedy'])
MultiLabelBinarizer()
>>> mlb.classes_
array(['-', 'c', 'd', 'e', 'f', 'h', 'i', 'l', 'm', 'o', 'r', 's', 't',
    'y'], dtype=object)

To correct this, the list of labels should be passed in as:

>>> mlb = MultiLabelBinarizer()
>>> mlb.fit([['sci-fi', 'thriller', 'comedy']])
MultiLabelBinarizer()
>>> mlb.classes_
array(['comedy', 'sci-fi', 'thriller'], dtype=object)
r|   NrN   ©rj   rR   rS   Fc                ó   • Xl         X l        g rV   rÇ   )r    rj   rR   s      r"   rW   ÚMultiLabelBinarizer.__init__ô  s   € ØŒØ*Õr%   TrY   c                 óÒ  • SU l         U R                  c2  [        [        [        R
                  R                  U5      5      5      nOL[        [        U R                  5      5      [        U R                  5      :  a  [        S5      eU R                  n[        S U 5       5      (       a  [        O[        n[        R                  " [        U5      US9U l        X R                  SS& U $ )a,  Fit the label sets binarizer, storing :term:`classes_`.

Parameters
----------
y : iterable of iterables
    A set of labels (any orderable and hashable object) for each
    sample. If the `classes` parameter is set, `y` will not be
    iterated.

Returns
-------
self : object
    Fitted estimator.
NztThe classes argument contains duplicate classes. Remove these duplicates before passing them to MultiLabelBinarizer.c              3   óB   #   • U  H  n[        U[        5      v •  M     g 7frV   ©rŒ   r�   ©Ú.0Úcs     r"   Ú	<genexpr>Ú*MultiLabelBinarizer.fit.<locals>.<genexpr>  s   é € Ð?²w°!œ: a¬×-Ð-²wùó   ‚r…   )Ú_cached_dictrj   ÚsortedÚsetÚ	itertoolsÚchainÚfrom_iterabler5   r6   Úallr�   Úobjectr.   Úemptyr   )r    r!   rj   r,   s       r"   r#   ÚMultiLabelBinarizer.fitø  s®   € ð  !ˆÔà�<‰<ÑÜœS¤§¡×!>Ñ!>¸qÓ!AÓBÓC‰GÜ”�T—\‘\Ó"Ó#¤c¨$¯,©,Ó&7Ó7Üð/óð ð —l‘lˆGÜÑ?±wÓ?×?Ñ?•ÄVˆÜŸš¤ W£°UÑ;ˆŒØ"�‰‘aÐØˆr%   c                 óp  • U R                   b   U R                  U5      R                  U5      $ SU l        [	        [
        5      nUR                  Ul        U R                  X5      n[        X"R                  S9n[        S U 5       5      (       a  [
        O[        n[        R                  " [        U5      US9nXBSS& [        R                   " USS9u  U l        n[        R$                  " XcR&                     UR&                  R(                  S9Ul        U R*                  (       d  UR-                  5       nU$ )aå  Fit the label sets binarizer and transform the given label sets.

Parameters
----------
y : iterable of iterables
    A set of labels (any orderable and hashable object) for each
    sample. If the `classes` parameter is set, `y` will not be
    iterated.

Returns
-------
y_indicator : {ndarray, sparse matrix} of shape (n_samples, n_classes)
    A matrix such that `y_indicator[i, j] = 1` iff `classes_[j]`
    is in `y[i]`, and 0 otherwise. Sparse matrix will be of CSR
    format.
N©Úkeyc              3   óB   #   • U  H  n[        U[        5      v •  M     g 7frV   rÌ   rÍ   s     r"   rÐ   Ú4MultiLabelBinarizer.fit_transform.<locals>.<genexpr>9  s   é € Ð;²s°!œ: a¬×-Ð-²sùrÒ   r…   Tr'   )rj   r#   r0   rÓ   r   r�   Ú__len__Údefault_factoryÚ
_transformrÔ   ÚgetrÙ   rÚ   r.   rÛ   r5   Úuniquer   r8   r§   r,   rR   rs   )r    r!   Úclass_mappingÚytÚtmpr,   Úinverses          r"   r)   Ú!MultiLabelBinarizer.fit_transform  sñ   € ð$ �<‰<Ñ#Ø—8‘8˜A“;×(Ñ(¨Ó+Ð+à ˆÔô $¤CÓ(ˆØ(5×(=Ñ(=ˆÔ%Ø�_‰_˜QÓ.ˆô �]×(9Ñ(9Ñ:ˆô Ñ;±sÓ;×;Ñ;•ÄˆÜŸš¤ S£°Ñ7ˆØ‘aÐÜ!#§¢¨=ÈÑ!NÑˆŒ�wä—Z’Z ¯
©
Ñ 3¸2¿:¹:×;KÑ;KÑLˆŒ
à×!×!Ø—‘“ˆBàˆ	r%   c                 ó    • [        U 5        U R                  5       nU R                  X5      nU R                  (       d  UR	                  5       nU$ )a”  Transform the given label sets.

Parameters
----------
y : iterable of iterables
    A set of labels (any orderable and hashable object) for each
    sample. If the `classes` parameter is set, `y` will not be
    iterated.

Returns
-------
y_indicator : array or CSR matrix, shape (n_samples, n_classes)
    A matrix such that `y_indicator[i, j] = 1` iff `classes_[j]` is in
    `y[i]`, and 0 otherwise.
)r   Ú_build_cacherä   rR   rs   )r    r!   Úclass_to_indexrè   s       r"   r0   ÚMultiLabelBinarizer.transformE  sA   € ô  	˜Ôà×*Ñ*Ó,ˆØ�_‰_˜QÓ/ˆà×!×!Ø—‘“ˆBàˆ	r%   c           
      ó´   • U R                   c@  [        [        U R                  [	        [        U R                  5      5      5      5      U l         U R                   $ rV   )rÓ   rz   Úzipr   Úranger5   rA   s    r"   rí   Ú MultiLabelBinarizer._build_cache_  s@   € Ø×ÑÑ$Ü $¤S¨¯©¼¼cÀ$Ç-Á-Ó>PÓ8QÓ%RÓ SˆDÔà× Ñ Ð r%   c           	      ó|  • [         R                   " S5      n[         R                   " SS/5      n[        5       nU HU  n[        5       nU H  n UR                  X(   5        M     UR	                  U5        UR                  [        U5      5        MW     U(       a1  [        R                  " SR                  [        U[        S95      5        [        R                  " [        U5      [        S9n	[        R                   " X“U4[        U5      S-
  [        U5      4S9$ ! [         a    UR                  U5         Mð  f = f)aÇ  Transforms the label sets with a given mapping.

Parameters
----------
y : iterable of iterables
    A set of labels (any orderable and hashable object) for each
    sample. If the `classes` parameter is set, `y` will not be
    iterated.

class_mapping : Mapping
    Maps from label to column index in label indicator matrix.

Returns
-------
y_indicator : sparse matrix of shape (n_samples, n_classes)
    Label indicator matrix. Will be of CSR format.
r¿   r   z%unknown class(es) {0} will be ignoredrÞ   r…   rT   r‰   )r/   rÕ   ÚaddÚKeyErrorÚextendr°   r5   Úwarningsr   rŽ   rÔ   r7   r.   Úonesr�   rb   rr   )
r    r!   rç   r§   r¨   rƒ   ÚlabelsÚindexÚlabelrš   s
             r"   rä   ÚMultiLabelBinarizer._transforme  sÿ   € ô$ —+’+˜cÓ"ˆÜ—’˜S 1 #Ó&ˆÜ“%ˆÛˆFÜ“EˆEÛ�ð'Ø—I‘I˜mÑ2Ö3ñ  ð
 �N‰N˜5Ô!Ø�M‰Mœ#˜g›,Ö'ñ ö Ü�MŠMØ7×>Ñ>¼vÀgÔSVÑ?WÓXôô �wŠw”s˜7“|¬3Ñ/ˆä�}Š}Ø˜FÐ#¬C°«K¸!©O¼SÀÓ=OÐ+Pñ
ð 	
øô  ó 'Ø—K‘K ×&ð'ús   ÁDÄD;Ä:D;c                 ó®  • [        U 5        UR                  S   [        U R                  5      :w  a;  [	        SR                  [        U R                  5      UR                  S   5      5      e[        R                  " U5      (       aÍ  UR                  5       n[        UR                  5      S:w  a;  [        [        R                  " UR                  SS/5      5      S:”  a  [	        S5      e[        UR                  SS UR                  SS 5       VVs/ s H5  u  p#[        U R                  R                  UR                   X# 5      5      PM7     snn$ [        R                  " USS/5      n[        U5      S:”  a  [	        SR                  U5      5      eU Vs/ s H'  n[        U R                  R#                  U5      5      PM)     sn$ s  snnf s  snf )aG  Transform the given indicator matrix into label sets.

Parameters
----------
yt : {ndarray, sparse matrix} of shape (n_samples, n_classes)
    A matrix containing only 1s ands 0s.

Returns
-------
y : list of tuples
    The set of labels for each sample such that `y[i]` consists of
    `classes_[j]` for each `yt[i, j] == 1`.
rT   z/Expected indicator for {0} classes, but got {1}r   z+Expected only 0s and 1s in label indicator.Nr‹   z8Expected only 0s and 1s in label indicator. Also got {0})r   rˆ   r5   r   r6   rŽ   rb   rc   r­   rš   r.   r3   rñ   r¨   Útupler³   r§   Úcompress)r    rè   ÚstartÚendÚ
unexpectedÚ
indicatorss         r"   r:   Ú%MultiLabelBinarizer.inverse_transform�  s�  € ô 	˜Ôà�8‰8�A‰;œ#˜dŸm™mÓ,Ó,ÜØA×HÑHÜ˜Ÿ™Ó&¨¯©°©óóð ô �;Š;�r�?‰?Ø—‘“ˆBÜ�2—7‘7‹|˜qÓ ¤S¬¯ª°b·g±gÀÀ1¸vÓ)FÓ%GÈ!Ó%KÜ Ð!NÓOÐOô #& b§i¡i°° n°b·i±iÀÀ°mÔ"Dôâ"D‘J�Eô �d—m‘m×(Ñ(¨¯©°EÐ)>Ó?Ö@Ù"Dòð ô
 Ÿš b¨1¨a¨&Ó1ˆJÜ�:‹ Ó"Ü ØN×UÑUØ"óóð ñ
 QSÓSÒPRÀ*”E˜$Ÿ-™-×0Ñ0°Ó<Ö=ÑPRÑSÐSùóùò Ts   Ä<GÆ.Gc                 ó   • SS/0$ )Nr>   Ú2dlabelsr@   rA   s    r"   rB   ÚMultiLabelBinarizer._more_tags¶  rD   r%   )rÓ   rj   r   rR   )rE   rF   rG   rH   rI   rS   rz   r{   rW   r   r#   r)   r0   rí   rä   r:   rB   rJ   r@   r%   r"   r   r   °  s‚   ‡ ñ<ð~ ! $Ð'Ø#˜ñ$Ð˜Dó ð
 #'°eõ +ñ °Ñ5ñó 6ðñ@ °Ñ5ñ)ó 6ð)òVò4!ò&
òP'TõR)r%   r   )(r/   rÖ   rø   Úcollectionsr   Únumbersr   Únumpyr.   Úscipy.sparseÚsparserb   Úbaser   r   r   Úutilsr	   Úutils._encoder
   r   Úutils._param_validationr   r   Úutils.multiclassr   r   Úutils.sparsefuncsr   Úutils.validationr   r   r   Ú__all__r   r   r   rp   rq   r   r@   r%   r"   Ú<module>r     sê   ðó Û Û Ý #Ý ã Ý ç @Ñ @Ý  ß ,ß ?ß <Ý ,ß IÑ Iò€ôC)Ð# ]È$ò C)ôLy)Ð% }ÈDò y)ñx à˜OÐ,Ø �>Ù˜x¨¨t¸IÑFÐGÙ˜x¨¨t¸IÑFÐGØ#˜ñð #'ñ	ð -.¸È%ô hó	ðhòV(;òV)LôXG)Ð*¨MÐQUó G)r%   