ó
    Ñ]j,ˆ  ã                   óœ  • 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JrJrJrJrJrJr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"S jr/S"S jr0 " S  S!\\SS9r1g)#é    N)Údefaultdict)ÚIntegral)ÚBaseEstimatorÚTransformerMixinÚ_fit_context)Úcolumn_or_1d)	Ú_convert_to_numpyÚ_find_matching_floating_dtypeÚ_is_numpy_namespaceÚ_isinÚdeviceÚget_namespaceÚget_namespace_and_deviceÚindexing_dtypeÚxpx)Ú_encodeÚ_unique)ÚIntervalÚvalidate_params)Útype_of_targetÚunique_labels)Úmin_max_axis)Ú_num_samplesÚcheck_arrayÚcheck_is_fitted)ÚLabelBinarizerÚLabelEncoderÚMultiLabelBinarizerÚlabel_binarizec                   óD   ^ • \ rS rSrSrS rS rS rS rU 4S jr	Sr
U =r$ )	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     ÚY/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sklearn/preprocessing/_label.pyÚfitÚLabelEncoder.fitZ   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_transformk   s(   € ô ˜ Ñ&ˆÜ" 1°TÑ:ÑˆŒ�qØˆr-   c                 óÔ   • [        U 5        [        U5      u  p#[        XR                  R                  SS9n[        U5      S:X  a  U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&   r4   r   Úasarrayr   )r(   r)   ÚxpÚ_s       r*   Ú	transformÚLabelEncoder.transform|   sW   € ô 	˜ÔÜ˜aÓ ‰ˆÜ˜§-¡-×"5Ñ"5¸DÑAˆä˜‹?˜aÓØ—:‘:˜b“>Ð!ä�q§-¡-Ñ0Ð0r-   c           	      ó¼  • [        U 5        [        U5      u  p#[        USS9n[        U5      S:X  a  UR	                  / 5      $ [
        R                  " UUR                  U R                  R                  S   [        U5      S9US9nUR                  S   (       a  [        S[        U5      -  5      eUR	                  U5      nUR                  U R                  USS9$ )zÎTransform labels back to original encoding.

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

Returns
-------
y_original : ndarray of shape (n_samples,)
    Original encoding.
Tr#   r   ©r   ©r7   z'y contains previously unseen labels: %s©Úaxis)r   r   r   r   r6   r   Ú	setdiff1dÚaranger&   Úshaper   Ú
ValueErrorÚstrÚtake)r(   r)   r7   r8   Údiffs        r*   Úinverse_transformÚLabelEncoder.inverse_transform’   s½   € ô 	˜ÔÜ˜aÓ ‰ˆÜ˜ Ñ&ˆä˜‹?˜aÓØ—:‘:˜b“>Ð!ä�}Š}ØØ�I‰I�d—m‘m×)Ñ)¨!Ñ,´V¸A³YˆIÐ?Øñ
ˆð
 �:‰:�a�=ÜÐFÌÈTËÑRÓSÐSØ�J‰J�q‹MˆØ�w‰w�t—}‘} a¨aˆwÐ0Ð0r-   c                 óv   >• [         TU ]  5       nSUl        SUR                  l        SUR
                  l        U$ )NTF)ÚsuperÚ__sklearn_tags__Úarray_api_supportÚ
input_tagsÚtwo_d_arrayÚtarget_tagsÚone_d_labels©r(   ÚtagsÚ	__class__s     €r*   rK   ÚLabelEncoder.__sklearn_tags__°   s7   ø€ Ü‰wÑ'Ó)ˆØ!%ˆÔØ&+ˆ�‰Ô#Ø(,ˆ×ÑÔ%Øˆr-   )r&   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r+   r1   r9   rG   rK   Ú__static_attributes__Ú__classcell__©rS   s   @r*   r   r   (   s'   ø† ñ/òbò"ò"1ò,1÷<ó 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U 4S jrSrU =r$ )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 ©Nra   )r(   rb   rc   rd   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5      u  p#U(       a:  U R                  (       a)  [        U5      (       d  [        SUR                   S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=ú>`sparse_output=True` is not supported for array API namespace ú<. Use `sparse_output=False` to return a dense array instead.r)   )Ú
input_nameÚmultioutputú@Multioutput target data is not supported with label binarizationúy has 0 samples: %r)rb   rc   rC   rd   r   r   rU   r   Úy_type_r   ÚspÚissparseÚsparse_input_r   r&   )r(   r)   r7   Úis_array_apis       r*   r+   ÚLabelBinarizer.fit  sI  € ð �>‰>˜TŸ^™^Ó+ÜØ˜TŸ^™^Ð,ð -Ø!Ÿ^™^Ð,¨Að/óð ð
 ×× 4§>¡>°QÓ#6¸$¿.¹.ÈAÓ:MÜðà!Ÿ^™^Ð,¨O¸D¿N¹NÐ;KðMóð ô )¨Ó+Ñˆæ˜D×.×.Ô7JÈ2×7NÑ7NÜðØŸ[™[˜Mð *Mð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+   r9   r'   s     r*   r1   ÚLabelBinarizer.fit_transformN  s   € ð( �x‰x˜‹{×$Ñ$ QÓ'Ð'r-   c                 ó¶  • [        U 5        [        U5      u  p#U(       a:  U R                  (       a)  [        U5      (       d  [	        SUR
                   S35      e[        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.
ro   rp   Ú
multilabelz0The object was not fitted with multilabel input.)Úclassesrc   rb   rd   )r   r   rd   r   rC   rU   r   Ú
startswithru   r   r&   rc   rb   )r(   r)   r7   ry   Úy_is_multilabels        r*   r9   ÚLabelBinarizer.transformd  s¾   € ô( 	˜Ôä(¨Ó+Ñˆæ˜D×.×.Ô7JÈ2×7NÑ7NÜðØŸ[™[˜Mð *MðMóð ô )¨Ó+×6Ñ6°|ÓDˆÞ 4§<¡<×#:Ñ#:¸<×#HÑ#HÜÐOÓPÐPäØØ—M‘MØ—n‘nØ—n‘nØ×,Ñ,ñ
ð 	
r-   c                 ó&  • [        U 5        [        U5      u  p4U(       a:  U R                  (       a)  [        U5      (       d  [	        SUR
                   S35      eUc  U R                  U R                  -   S-  nU R                  S:X  a  [        XR                  US9nO[        XR                  U R                  X#S9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_original : {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`.
zY`LabelBinarizer` was fitted on a sparse matrix, and therefore cannot inverse transform a z array back to a sparse matrix.g       @Ú
multiclassr=   )r   r   rx   r   rC   rU   rc   rb   ru   Ú_inverse_binarize_multiclassr&   Ú_inverse_binarize_thresholdingrv   Ú
csr_matrixrw   Útoarray)r(   ÚYÚ	thresholdr7   ry   Úy_invs         r*   rG   Ú LabelBinarizer.inverse_transform�  sé   € ô@ 	˜Ôä(¨Ó+Ñˆæ˜D×.×.Ô7JÈ2×7NÑ7NÜð'Ø')§{¡{ mÐ3RðTóð ð
 ÑØŸ™¨$¯.©.Ñ8¸CÑ?ˆIà�<‰<˜<Ó'Ü0°·M±MÀbÑI‰Eä2Ø—<‘< §¡°	ñˆEð ××Ü—M’M %Ó(ˆEð ˆô �[Š[˜×ÑØ—M‘M“OˆEàˆr-   c                 óh   >• [         TU ]  5       nSUR                  l        SUR                  l        U$ ©NFT)rJ   rK   rM   rN   rO   rP   rQ   s     €r*   rK   ÚLabelBinarizer.__sklearn_tags__Ê  ó/   ø€ Ü‰wÑ'Ó)ˆØ&+ˆ�‰Ô#Ø(,ˆ×ÑÔ%Øˆr-   )r&   rb   rc   rx   rd   ru   rh   )rU   rV   rW   rX   rY   r   re   ÚdictÚ__annotations__ri   r   r+   r1   r9   rG   rK   rZ   r[   r\   s   @r*   r   r   ¸   sm   ø‡ ñVðr �ZØ�ZØ#˜ñ$Ð˜Dó ð %&°À%õ +ñ
 °Ñ5ñ/ó 6ð/òb(ò,)
ôV9÷vó r-   r   ú
array-likezsparse matrixÚneither)Úclosedr`   )r)   r   rb   rc   rd   Trk   rf   Fra   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[        U 5      u  pxn	U(       a0  U(       a)  [        U5      (       d  [	        SUR                   S35      e UR                  XS9n[        U S5      (       a  U R                  S   O
[        U 5      nUR                  S   n[        U S5      (       a.  UR                  U R                   S5      (       a  U R                   nO[#        U5      nUS:X  aH  US:X  a:  U(       a  [$        R&                  " US4[(        S9$ UR+                  US4US9nXâ-  nU$ US:¼  a  SnUR-                  U5      nUS:X  aX  [        U S5      (       a  U R                  S   O[        U S   5      nUU:w  a$  [	        SR                  U[/        U 5      5      5      eUS;   a×  [1        U 5      n [3        XUS9nU U   nUR5                  UU5      nUR7                  UU5      nUR9                  UR                  S/U	S9UR;                  USS945      nUR=                  UU5      n[$        R&                  " [?        UUS9[?        UUS9[?        UUS94X¼4S 9nU(       d  UR                  URA                  5       U	S9nO¤US:X  a�  U(       a@  [$        R&                  " U 5      nUS:w  a#  UR=                  URB                  U5      nUUl!        OW[$        RD                  " U 5      (       a  U RA                  5       n UR                  X	S!S"9nUS:w  a  X>US:g  '   O[	        S#U-  5      eU(       d,  US:w  a  X.US:H  '   U(       a  SXîU:H  '   UR7                  XíSS$9nO#URB                  R7                  [(        SS$9Ul!        URG                  X:g  5      (       a  UR5                  Xñ5      nUSS2U4   nUS:X  a,  U(       a  USS2S%/4   nU$ URI                  USS2S%4   S&5      nU$ ! [        [        4 a  n
[	        SUR                   S35      U
eSn
A
ff = f)'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)rq   Úaccept_sparseÚ	ensure_2dr4   r   rt   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}rr   rs   Úunknownz$The type of target data is not knownz?`sparse_output=True` is not supported for array API 'namespace z='. Use `sparse_output=False` to return a dense array instead.r<   z>`classes` contains unsupported dtype for array API namespace 'z'.rB   r4   ÚintegralÚbinaryrf   ©r4   é   r„   úmultilabel-indicatorz:classes {0} mismatch with the labels {1} found in the data)rœ   r„   r=   r>   ©rB   T)r   Úcopyz7%s target data is not supported with label binarization)r¡   éÿÿÿÿ)r¢   rf   )%Ú
isinstanceÚlistr   r   rC   Úformatr   r   r   rU   r6   Ú	TypeErrorÚhasattrrB   ÚlenÚisdtyper4   r   rv   r‡   ÚintÚzerosÚsortr   r   r   ÚsearchsortedÚastypeÚconcatÚcumulative_sumÚ	full_liker	   rˆ   Údatarw   ÚanyÚreshape)r)   r   rb   rc   rd   Ú
pos_switchÚy_typer7   ry   Údevice_ÚeÚ	n_samplesÚ	n_classesÚ
int_dtype_r‰   Ú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ó
ð 	
ð �ÓÜÐ?Ó@Ð@ä 8¸Ó ;Ñ€B�gæžÔ.AÀ"×.EÑ.EÜðØŸ+™+˜ð 'IðIó
ð 	
ðØ—*‘*˜W�*Ð5ˆô & a¨×1Ñ1�—‘˜’
´s¸1³v€IØ—‘˜aÑ €IÜˆq�'×Ñ˜rŸz™z¨!¯'©'°:×>Ñ>Ø—W‘W‰
ä# BÓ'ˆ
à�ÓØ˜‹>ÞÜ—}’} i° ^¼3Ñ?Ð?à—H‘H˜i¨˜^°:�HÐ>�Ø‘�Ø�Ø˜!‹^Ø!ˆFà—7‘7˜7Ó#€LØÐ'Ó'Ü$+¨A¨w×$7Ñ$7�a—g‘g˜a’j¼SÀÀ1Á»YˆØ˜Ó#ÜØL×SÑSØœ]¨1Ó-óóð ð Ð)Ó)Ü˜‹Oˆô ˜Q¨BÑ/ˆØ�<‘ˆØ—/‘/ ,°Ó7ˆà—y‘y ¨zÓ:ˆØ—‘à—
‘
˜A˜3 w�
Ð/Ø×!Ñ! ,°QÐ!Ð7ðó
ˆð �|‰|˜G YÓ/ˆô �MŠMä! $¨2Ñ.Ü! '¨bÑ1Ü! &¨RÑ0ðð
 Ð(ñ
ˆö Ø—
‘
˜1Ÿ9™9›;¨w�
Ð7ˆAøà	Ð)Ó	)ÞÜ—’˜aÓ ˆAØ˜A‹~Ø—|‘| A§F¡F¨IÓ6�Ø�”øä�{Š{˜1�~‰~Ø—I‘I“K�à—
‘
˜1°4�
Ð8ˆAØ˜A‹~Ø%�!�q‘&‘	øô ØEÈÑNó
ð 	
ö Ø˜‹>Ø!ˆa�1‰f‰IæØ !ˆA�9‰nÑà�I‰I�a¨%ˆIÐ0‰à—‘—‘œs¨�Ð/ˆŒð 
‡v�vˆgÑ%×&Ñ&Ø—/‘/ ,Ó8ˆØŠa�ˆj‰Mˆà�ÓÞØ’!�b�T�'‘
ˆAð €Hð —
‘
˜1šQ ˜U™8 WÓ-ˆAà€HøôW œ	Ð"ó ô ðØ—‘ˆ}˜Bð ó
ð ð	ûðús   ÄR ÒSÒ,SÓSc                 ó’  • [         R                  " U 5      (       Ga×  [        R                  " U5      nU R	                  5       n U R
                  u  p4[        R                  " U5      n[        U S5      S   n[        R                  " U R                  5      n[        R                  " Xg5      n[        R                  " X€R                  :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&                  " X_5         S   XÎ'   MO     X   $ [)        XS9u  nnnUR                  UUS9nUR+                  U SS9nUR-                  USUR
                  S   S-
  5      nUU   $ )zuInverse label binarization transformation for multiclass.

Multiclass uses the maximal score instead of a threshold.
rf   r¢   r   Nr=   r<   r>   )rv   rw   Únpr6   ÚtocsrrB   rA   r   rF   rÁ   ÚrepeatÚflatnonzeror²   Úappendr¨   r­   rÀ   ÚwhereÚravelr@   r   ÚargmaxÚclip)r)   r   r7   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Úindr8   r·   rÀ   s                      r*   r…   r…   µ  sì  € ô
 
‡{‚{�1‡~‚~Ü—*’*˜WÓ%ˆð �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ñ ð Ñ"Ð"ä1°!Ñ;‰ˆˆAˆwØ—*‘*˜W¨W�*Ð5ˆØ—)‘)˜A A�)Ð&ˆØ—'‘'˜' 1 g§m¡m°AÑ&6¸Ñ&:Ó;ˆà�wÑÐr-   c                 óè  • US:X  aG  U R                   S:X  a7  U R                  S   S:”  a$  [        SR                  U R                  5      5      e[	        XS9u  pEnUR                  X&S9nUS:w  a+  U R                  S   UR                  S   :w  a  [        S5      e[        XS9n[        U S	5      (       a.  UR                  U R                  S
5      (       a  U R                  nO[        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         ODUR                  U R'                  5       U:„  X†S9n O"UR                  UR                  XUS9U:„  UU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R                  S   S:X  a  UR)                  US   [+        U 5      5      $ X$R-                  U S5         $ US:X  a  U $ [        SR                  U5      5      e)z=Inverse label binarization transformation using thresholding.rœ   é   rf   z'output_type='binary', but y.shape = {0}r=   r<   r   zAThe number of class is not equal to the number of dimension of y.r4   r›   )r—   Úcscr�   )r4   r   N)r¢   rŸ   z{0} format is not supported)ÚndimrB   rC   r¥   r   r6   r
   r§   r©   r4   r   rv   rw   rÄ   rÃ   Úarrayr²   rª   Úeliminate_zerosrˆ   rÅ   r¨   r´   )	r)   Úoutput_typer   rŠ   r7   r8   r·   Údtype_r»   s	            r*   r†   r†   ä  s  € ð �hÓ 1§6¡6¨Q£;°1·7±7¸1±:À³>ÜÐB×IÑIÈ!Ï'É'ÓRÓSÐSä-¨aÑ7�N€Bˆ7Ø�j‰j˜ˆjÐ1€Gà�hÓ 1§7¡7¨1¡:°·±¸qÑ1AÓ#AÜØOó
ð 	
ô +¨1Ñ4€FÜˆq�'×Ñ˜rŸz™z¨!¯'©'°:×>Ñ>Ø—W‘W‰
ä# BÓ'ˆ
ô 
‡{‚{�1‡~�~Ø�q‹=Ø�x‰x˜~Ó-Ø—G‘G“I�Ü—X’X˜aŸf™f yÑ0¼Ñ<ˆAŒFØ×ÑÕà—
‘
˜1Ÿ9™9›;¨Ñ2¸*�
ÐU‰Aà�J‰JØ�J‰J�q¨wˆJÐ7¸)ÑCØØð ð 
ˆð �hÓÜ�;Š;�q�>‰>Ø—	‘	“ˆAØ�6‰6�Q‹;˜1Ÿ7™7 1™:¨›?ØšQ ˜T™7Ñ#Ð#à�}‰}˜QÑ 1Ó$Ø—y‘y ¨¡¬S°«VÓ4Ð4àŸz™z¨!¨UÓ3Ñ4Ð4à	Ð.Ó	.Øˆô Ð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U 4S jrSrU =r$ )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“   Nr`   ©r   rd   re   Fc                ó   • Xl         X l        g rh   rá   )r(   r   rd   s      r*   ri   ÚMultiLabelBinarizer.__init___  s   € ØŒØ*Õr-   Trk   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rh   ©r£   rª   ©Ú.0Úcs     r*   Ú	<genexpr>Ú*MultiLabelBinarizer.fit.<locals>.<genexpr>  s   é € Ð?²w°!œ: a¬×-Ð-²wùó   ‚r�   )Ú_cached_dictr   ÚsortedÚsetÚ	itertoolsÚchainÚfrom_iterabler¨   rC   Úallrª   ÚobjectrÃ   Úemptyr&   )r(   r)   r   r4   s       r*   r+   ÚMultiLabelBinarizer.fitc  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rh   ræ   rç   s     r*   rê   Ú4MultiLabelBinarizer.fit_transform.<locals>.<genexpr>¤  s   é € Ð;²s°!œ: a¬×-Ð-²sùrì   r�   Tr/   )r   r+   r9   rí   r   rª   Ú__len__Údefault_factoryÚ
_transformrî   Úgetró   rô   rÃ   rõ   r¨   Úuniquer&   r6   rÀ   r4   rd   rˆ   )r(   r)   Úclass_mappingÚytÚtmpr4   Úinverses          r*   r1   Ú!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þ   rd   rˆ   )r(   r)   Úclass_to_indexr  s       r*   r9   ÚMultiLabelBinarizer.transform°  sA   € ô  	˜Ôà×*Ñ*Ó,ˆØ�_‰_˜QÓ/ˆà×!×!Ø—‘“ˆBàˆ	r-   c           
      ó´   • U R                   c@  [        [        U R                  [	        [        U R                  5      5      5      5      U l         U R                   $ rh   )rí   r‘   Úzipr&   Úranger¨   )r(   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�   rf   r    )rÜ   rï   ÚaddÚKeyErrorÚextendrÇ   r¨   Úwarningsr$   r¥   rî   rD   rÃ   Úonesrª   rv   r‡   )
r(   r)   r  rÀ   rÁ   rš   ÚlabelsÚindexÚlabelr²   s
             r*   rþ   ÚMultiLabelBinarizer._transformÐ  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 )aP  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_original : list of tuples
    The set of labels for each sample such that `y[i]` consists of
    `classes_[j]` for each `yt[i, j] == 1`.
rf   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   rB   r¨   r&   rC   r¥   rv   rw   rÄ   r²   rÃ   r@   r  rÁ   ÚtuplerE   rÀ   Úcompress)r(   r  ÚstartÚendÚ
unexpectedÚ
indicatorss         r*   rG   Ú%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                 óh   >• [         TU ]  5       nSUR                  l        SUR                  l        U$ rŽ   )rJ   rK   rM   rN   rO   Útwo_d_labelsrQ   s     €r*   rK   Ú$MultiLabelBinarizer.__sklearn_tags__!  r�   r-   )rí   r   r&   rd   )rU   rV   rW   rX   rY   re   r‘   r’   ri   r   r+   r1   r9   r  rþ   rG   rK   rZ   r[   r\   s   @r*   r   r     sˆ   ø‡ ñ<ð~ ! $Ð'Ø#˜ñ$Ð˜Dó ð
 #'°eõ +ñ °Ñ5ñó 6ðñ@ °Ñ5ñ)ó 6ð)òVò4!ò&
òP'T÷Ró r-   r   rh   )2rÜ   rð   r  Úcollectionsr   Únumbersr   ÚnumpyrÃ   Úscipy.sparseÚsparserv   Úsklearn.baser   r   r   Úsklearn.utilsr   Úsklearn.utils._array_apir	   r
   r   r   r   r   r   r   r   Úsklearn.utils._encoder   r   Úsklearn.utils._param_validationr   r   Úsklearn.utils.multiclassr   r   Úsklearn.utils.sparsefuncsr   Úsklearn.utils.validationr   r   r   Ú__all__r   r   r   r…   r†   r   © r-   r*   Ú<module>r2     sû   ðó Û Û Ý #Ý ã Ý ç FÑ FÝ &÷
÷ 
õ 
÷ 3ß Eß BÝ 2ß OÑ Oò€ôMÐ# ]È$ò Mô`VÐ% }ÈDò Vñr à˜OÐ,Ø �>Ù˜x¨¨t¸IÑFÐGÙ˜x¨¨t¸IÑFÐGØ#˜ñð #'ñ	ð -.¸È%ô Wó	ðWôt, ô^4LônJÐ*¨MÐQUó Jr-   