Ë
    ÜÍ:jŠ  ã                   ó¾  — d dl Z d dlZd dlZd dlmZ d dlmZ d dlZd dl	m
Z d dlmZmZmZ d dlmZmZ d dlmZmZmZmZmZmZmZmZmZ d dlmZmZ d dl m!Z!m"Z" d d	l#m$Z$m%Z% d d
l&m'Z' d dl(m)Z)m*Z*m+Z+ g d¢Z, G d„ deed¬«      Z- G d„ deed¬«      Z. e"ddgdg e!eddd¬«      g e!eddd¬«      gdgdœd¬«      d dddœd„«       Z/d"d„Z0d"d„Z1 G d „ d!eed¬«      Z2y)#é    N)Údefaultdict)ÚIntegral)ÚBaseEstimatorÚTransformerMixinÚ_fit_context)Ú_align_api_if_sparseÚcolumn_or_1d)	Ú_find_matching_floating_dtypeÚ_is_numpy_namespaceÚ_isinÚdeviceÚget_namespaceÚget_namespace_and_deviceÚindexing_dtypeÚmove_toÚ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                   ó:   ‡ — e Zd ZdZd„ Zd„ Zd„ Zd„ Zˆ fd„Zˆ xZ	S )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                 ó@   — t        |d¬«      }t        |«      | _        | S )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     úq/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/sklearn/preprocessing/_label.pyÚfitzLabelEncoder.fitZ   s    € ô ˜ Ô&ˆÜ ›
ˆŒØˆó    c                 óJ   — t        |d¬«      }t        |d¬«      \  | _        }|S )a  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_transformzLabelEncoder.fit_transformk   s(   € ô ˜ Ô&ˆÜ" 1°TÔ:ÑˆŒ�qØˆr,   c                 óä   — t        | «       t        |«      \  }}t        || j                  j                  d¬«      }t        |«      dk(  r|j                  g «      S t        || j                  ¬«      S )a  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&   r2   r   Úasarrayr   )r(   r)   ÚxpÚ_s       r*   Ú	transformzLabelEncoder.transform|   s]   € ô 	˜ÔÜ˜aÓ ‰ˆˆAÜ˜ $§-¡-×"5Ñ"5¸DÔAˆä˜‹?˜aÒØ—:‘:˜b“>Ð!ä�q $§-¡-Ô0Ð0r,   c           	      óÈ  — t        | «       t        |«      \  }}t        |d¬«      }t        |«      dk(  r|j	                  g «      S t        j                  ||j                  | j                  j                  d   t        |«      ¬«      |¬«      }|j                  d   rt        dt        |«      z  «      ‚|j	                  |«      }|j                  | j                  |d¬«      S )a  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   ©r5   z'y contains previously unseen labels: %s©Úaxis)r   r   r	   r   r4   r   Ú	setdiff1dÚaranger&   Úshaper   Ú
ValueErrorÚstrÚtake)r(   r)   r5   r6   Údiffs        r*   Úinverse_transformzLabelEncoder.inverse_transform’   s¿   € ô 	˜ÔÜ˜aÓ ‰ˆˆ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         ‰| �  «       }d|_        d|j                  _        d|j
                  _        |S )NTF)ÚsuperÚ__sklearn_tags__Úarray_api_supportÚ
input_tagsÚtwo_d_arrayÚtarget_tagsÚone_d_labels©r(   ÚtagsÚ	__class__s     €r*   rG   zLabelEncoder.__sklearn_tags__°   s7   ø€ Ü‰wÑ'Ó)ˆØ!%ˆÔØ&+ˆ�‰Ô#Ø(,ˆ×ÑÔ%Øˆr,   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r+   r0   r7   rD   rG   Ú__classcell__©rO   s   @r*   r   r   (   s'   ø„ ñ/òbò"ò"1ò,1÷<ð r,   r   )Úauto_wrap_output_keysc                   ó‚   ‡ — e Zd ZU dZegegdgdœZeed<   ddddœd„Z e	d	¬
«      d„ «       Z
d„ Zd„ Zdd„Zˆ fd„Zˆ xZS )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                ó.   — || _         || _        || _        y ©NrY   )r(   rZ   r[   r\   s       r*   Ú__init__zLabelBinarizer.__init__  s   € Ø"ˆŒØ"ˆŒØ*ˆÕr,   T©Úprefer_skip_nested_validationc                 ó„  — | j                   | j                  k\  r&t        d| j                   › d| j                  › d�«      ‚| j                  rC| j                  dk(  s| j                   dk7  r%t        d| j                  › d| j                   › �«      ‚t	        |«      \  }}|r0| j                  r$t        |«      st        d|j                  › d�«      ‚t        |d	¬
«      | _        d| j                  v rt        d«      ‚t        |«      dk(  rt        d|z  «      ‚t        j                  |«      | _        t        |«      | _        | S )aa  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)rZ   r[   r@   r\   r   r   rP   r   Úy_type_r   ÚspÚissparseÚsparse_input_r   r&   )r(   r)   r5   Úis_array_apis       r*   r+   zLabelBinarizer.fit  sH  € ð �>‰>˜TŸ^™^Ò+ÜØ˜TŸ^™^Ð,ð -Ø!Ÿ^™^Ð,¨Að/óð ð
 ×Ò 4§>¡>°QÒ#6¸$¿.¹.ÈAÒ:MÜðà!Ÿ^™^Ð,¨O¸D¿N¹NÐ;KðMóð ô )¨Ó+ÑˆˆLá˜D×.Ò.Ô7JÈ2Ô7NÜðØŸ[™[˜Mð *MðMóð ô & a°CÔ8ˆŒà˜DŸL™LÑ(ÜØRóð ô ˜‹?˜aÒÜÐ2°QÑ6Ó7Ð7äŸ[™[¨›^ˆÔÜ% aÓ(ˆŒØˆr,   c                 óB   — | j                  |«      j                  |«      S )aÁ  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+   r7   r'   s     r*   r0   zLabelBinarizer.fit_transformN  s   € ð( �x‰x˜‹{×$Ñ$ QÓ'Ð'r,   c                 óŒ  — t        | «       t        |«      \  }}|r0| j                  r$t        |«      st	        d|j
                  › d�«      ‚t        |«      j                  d«      }|r&| j                  j                  d«      st	        d«      ‚t        || j                  | j                  | j                  | j                  ¬«      S )a»  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.
        rf   rg   Ú
multilabelz0The object was not fitted with multilabel input.)Úclassesr[   rZ   r\   )r   r   r\   r   r@   rP   r   Ú
startswithrl   r    r&   r[   rZ   )r(   r)   r5   rp   Úy_is_multilabels        r*   r7   zLabelBinarizer.transformd  sº   € ô( 	˜Ôä(¨Ó+ÑˆˆLá˜D×.Ò.Ô7JÈ2Ô7NÜðØŸ[™[˜Mð *MðMóð ô )¨Ó+×6Ñ6°|ÓDˆÙ 4§<¡<×#:Ñ#:¸<Ô#HÜÐOÓPÐPäØØ—M‘MØ—n‘nØ—n‘nØ×,Ñ,ô
ð 	
r,   c                 ó  — t        | «       t        |«      \  }}|r0| j                  r$t        |«      st	        d|j
                  › d�«      ‚|€| j                  | j                  z   dz  }| j                  dk(  rt        || j                  |¬«      }n$t        || j                  | j                  ||¬«      }| j                  r t        t        j                  |«      «      }|S t        j                  |«      r|j!                  «       }|S )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   ro   r   r@   rP   r[   rZ   rl   Ú_inverse_binarize_multiclassr&   Ú_inverse_binarize_thresholdingr   rm   Ú	csr_arrayrn   Útoarray)r(   ÚYÚ	thresholdr5   rp   Úy_invs         r*   rD   z LabelBinarizer.inverse_transform�  sð   € ô@ 	˜Ôä(¨Ó+ÑˆˆLá˜D×.Ò.Ô7JÈ2Ô7NÜð'Ø')§{¡{ mÐ3RðTóð ð
 ÐØŸ™¨$¯.©.Ñ8¸CÑ?ˆIà�<‰<˜<Ò'Ü0°°D·M±MÀbÔI‰Eä2Ø�4—<‘< §¡°	¸bôˆEð ×ÒÜ(¬¯©°eÓ)<Ó=ˆEð ˆô �[‰[˜ÔØ—M‘M“OˆEàˆr,   c                 óh   •— t         ‰| �  «       }d|j                  _        d|j                  _        |S ©NFT)rF   rG   rI   rJ   rK   rL   rM   s     €r*   rG   zLabelBinarizer.__sklearn_tags__Ê  ó/   ø€ Ü‰wÑ'Ó)ˆØ&+ˆ�‰Ô#Ø(,ˆ×ÑÔ%Øˆr,   r`   )rP   rQ   rR   rS   r   r]   ÚdictÚ__annotations__ra   r   r+   r0   r7   rD   rG   rT   rU   s   @r*   r   r   ¸   sm   ø… ñVðr �ZØ�ZØ#˜ñ$Ð˜Dó ð %&°À%ô +ñ
 °Ô5ñ/ó 6ð/òb(ò,)
óV9÷vð r,   r   ú
array-likezsparse matrixÚneither)ÚclosedrX   )r)   rt   rZ   r[   r\   Trb   r^   FrY   c          	      ó 
  — t        | t        «      st        | dddd¬«      } nt        | «      dk(  rt	        d| z  «      ‚||k\  rt	        dj                  ||«      «      ‚|r%|dk(  s|dk7  rt	        d	j                  ||«      «      ‚|dk(  }|r| }t        | «      }d
|v rt	        d«      ‚|dk(  rt	        d«      ‚t        | «      \  }}}	|r&|r$t        |«      st	        d|j                  › d�«      ‚	 |j                  ||	¬«      }t        | d«      r| j                  d   n
t        | «      }|j                  d   }t        | d«      }|r)|j                  | j                   d«      r| j                   }nt#        |«      }|r:|j                  | j                   d«      r|j%                  || j                   d¬«      }|dk(  rP|dk(  rD|r&t'        t)        j*                  |dft,        ¬«      «      S |j/                  |df|¬«      }||z  }|S |dk\  rd}|j1                  |«      }|dk(  rRt        | d«      r| j                  d   nt        | d   «      }||k7  r$t	        dj                  |t3        | «      «      «      ‚|dv rút5        | «      } t7        | ||¬ «      }| |   }|j9                  ||«      }|j%                  ||«      }|j;                  |j                  dg|	¬«      |j=                  |d¬!«      f«      }|j?                  ||«      }t)        j*                  tA        |tB        d"¬#«      tA        |tB        d"¬#«      tA        |tB        d"¬#«      f||f¬$«      }|s¼|j                  |jE                  «       |	¬«      }nš|dk(  r‡|r>t)        j*                  | «      }|dk7  ry|j?                  |jF                  |«      }||_#        nUt)        jH                  | «      r| jE                  «       } |j                  | |	d%¬&«      }|dk7  r|||dk7  <   nt	        d'|z  «      ‚|s,|dk7  r|||dk(  <   |rd|||k(  <   |j%                  ||d¬«      }n&|jF                  j%                  t,        d¬«      |_#        |jK                  ||k7  «      r|j9                  ||«      }|dd…|f   }|dk(  r0|r|dd…d(gf   }t'        |«      S |jM                  |dd…d(f   d)«      }t'        |«      S # t        t        f$ r}
t	        d|j                  › d�«      |
‚d}
~
ww xY w)*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.

    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)rh   Úaccept_sparseÚ	ensure_2dr2   r   rk   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}ri   rj   Ú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.r9   z>`classes` contains unsupported dtype for array API namespace 'z'.r?   r2   úsigned integerÚintegral)ÚcopyÚbinaryr^   ©r2   é   rx   úmultilabel-indicatorz:classes {0} mismatch with the labels {1} found in the data)r�   rx   r:   r;   Úcpu)r5   r   ©r?   T)r   r�   z7%s target data is not supported with label binarizationéÿÿÿÿ)r–   r^   )'Ú
isinstanceÚlistr   r   r@   Úformatr   r   r   rP   r4   Ú	TypeErrorÚhasattrr?   ÚlenÚisdtyper2   r   Úastyper   rm   r{   ÚintÚzerosÚsortr   r	   r   ÚsearchsortedÚconcatÚcumulative_sumÚ	full_liker   Únpr|   Údatarn   ÚanyÚreshape)r)   rt   rZ   r[   r\   Ú
pos_switchÚy_typer5   rp   Údevice_ÚeÚ	n_samplesÚ	n_classesÚy_has_dtypeÚ
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Ø�IÒÜØE×LÑLØ˜9óó
ð 	
ñ ˜) qš.¨I¸ªNÜð÷ ‰v�i Ó+ó	
ð 	
ð ˜a‘€JÙØ�Jˆ	ä˜AÓ€FØ˜ÑÜØNó
ð 	
ð �ÒÜÐ?Ó@Ð@ä 8¸Ó ;Ñ€Bˆ�gá™Ô.AÀ"Ô.EÜðØŸ+™+˜ð 'IðIó
ð 	
ðØ—*‘*˜W¨W�*Ó5ˆô & a¨Ô1�—‘˜’
´s¸1³v€IØ—‘˜aÑ €Iä˜!˜WÓ%€KÙ�r—z‘z !§'¡'Ð+;Ô<Ø—W‘W‰
ä# BÓ'ˆ
ñ �r—z‘z !§'¡'¨:Ô6Ø—)‘)˜G Q§W¡W°5�)Ó9ˆà�ÒØ˜Š>ÙÜ+¬B¯L©L¸)ÀQ¸ÌsÔ,SÓTÐTà—H‘H˜i¨˜^°:�HÓ>�Ø�Y‘�Ø�Ø˜!Š^Ø!ˆFà—7‘7˜7Ó#€LØÐ'Ò'Ü$+¨A¨wÔ$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Ó/ˆô �L‰Lä˜¤¨EÔ2Ü˜¤B¨uÔ5Ü˜¤2¨eÔ4ðð
 ˜iÐ(ô
ˆñ Ø—
‘
˜1Ÿ9™9›;¨w�
Ó7‰Aà	Ð)Ò	)ÙÜ—‘˜Q“ˆAØ˜AŠ~Ø—|‘| A§F¡F¨IÓ6�Ø�•ä�{‰{˜1Œ~Ø—I‘I“K�à—
‘
˜1 W°4�
Ó8ˆAØ˜AŠ~Ø%��!�q‘&’	ô ØEÈÑNó
ð 	
ñ Ø˜Š>Ø!ˆAˆa�1‰f‰IáØ !ˆAˆa�9‰nÑà�I‰I�a˜¨%ˆIÓ0‰à—‘—‘œs¨�Ó/ˆŒð 
‡v�vˆg˜Ñ%Ô&Ø—/‘/ ,°Ó8ˆØŠa�ˆj‰Mˆà�ÒÙØ’!�b�T�'‘
ˆAô   Ó"Ð"ð —
‘
˜1šQ ˜U™8 WÓ-ˆAä Ó"Ð"øôe œ	Ð"ò ô ðØ—‘ˆ}˜Bð ó
ð ð	ûðús   Ã1S ÓS=ÓS8Ó8S=c                 óŽ  — t        j                  | «      �rÑt        j                  |«      }| j	                  «       } | j
                  \  }}t        j                  |«      }t        | d«      d   }t        j                  | j                  «      }t        j                  ||«      }t        j                  || j                  k(  «      }	|d   dk(  r*t        j                  |	t        | j                  «      g«      }	t        j                  |	| j                  dd «      }
t        j                  | j                   dg«      }||	|
      }d|t        j"                  |dk(  «      d   <   t        j                  |«      |dkD  |j%                  «       dk(  z     }|D ]M  }| j                   | j                  |   | j                  |dz       }|t        j&                  ||«         d   ||<   ŒO ||   S t)        | |¬«      \  }}}|j                  ||¬«      }|j+                  | d¬«      }|j-                  |d|j
                  d   dz
  «      }||   S )z}Inverse label binarization transformation for multiclass.

    Multiclass uses the maximal score instead of a threshold.
    r^   r–   r   Nr:   r9   r;   )rm   rn   r¦   r4   Útocsrr?   r>   r   rC   r·   ÚrepeatÚflatnonzeror§   Úappendrœ   r¢   r¶   ÚwhereÚravelr=   r   ÚargmaxÚclip)r)   rt   r5   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Úindr6   r¬   r¶   s                      r*   ry   ry   ¼  s  € ô
 
‡{�{�1…~Ü—*‘*˜WÓ%ˆð �G‰G‹IˆØ Ÿw™wÑˆ	�9Ü—)‘)˜IÓ&ˆÜ˜q !Ó$ QÑ'ˆÜ—'‘'˜!Ÿ(™(Ó#ˆä Ÿi™i¨°Ó9ÐäŸ™Ð(;¸q¿v¹vÑ(EÓFˆð �2‰;˜!ÒÜŸY™Y ~¼¸A¿F¹F»°}ÓEˆNô  Ÿ_™_¨^¸Q¿X¹XÀcÀr¸]ÓKÐä—I‘I˜aŸi™i¨!¨Ó-ˆ	Ø˜~Ð.@ÑAÑBˆ
à01ˆ
”2—8‘8˜G q™LÓ)¨!Ñ,Ñ-ô —)‘)˜IÓ&¨°!©¸¿¹»È1Ñ8LÑ'MÑNˆØò 	CˆAØ—)‘)˜AŸH™H Q™K¨!¯(©(°1°q±5©/Ð:ˆCØ#¤B§L¡L°¸#Ó$>Ñ?ÀÑBˆJ�qŠMð	Cð �zÑ"Ð"ä1°!¸Ô;‰ˆˆAˆwØ—*‘*˜W¨W�*Ó5ˆØ—)‘)˜A A�)Ó&ˆØ—'‘'˜' 1 g§m¡m°AÑ&6¸Ñ&:Ó;ˆà�wÑÐr,   c                 óÚ  — |dk(  rE| j                   dk(  r6| j                  d   dkD  r$t        dj                  | j                  «      «      ‚t	        | |¬«      \  }}}|j                  ||¬«      }|dk7  r*| j                  d   |j                  d   k7  rt        d«      ‚t        | |¬«      }t        | d	«      r)|j                  | j                  d
«      r| j                  }nt        |«      }t        j                  | «      r‡|dkD  r\| j                  dvr| j                  «       } t        j                  | j                   |kD  t"        ¬«      | _        | j%                  «        nO|j                  | j'                  «       |kD  ||¬«      } n)|j                  |j                  | ||¬«      |kD  ||¬«      } |dk(  r—t        j                  | «      r| j'                  «       } | j                   dk(  r| j                  d   dk(  r|| dd…df      S |j                  d   dk(  r|j)                  |d   t+        | «      «      S ||j-                  | d«         S |dk(  r| S t        dj                  |«      «      ‚)z=Inverse label binarization transformation using thresholding.r�   é   r^   z'output_type='binary', but y.shape = {0}r:   r9   r   zAThe number of class is not equal to the number of dimension of y.r2   r�   )r‰   Úcscr‘   )r2   r   N)r–   r“   z{0} format is not supported)Úndimr?   r@   r™   r   r4   r
   r›   r�   r2   r   rm   rn   r¹   r¦   Úarrayr§   rŸ   Úeliminate_zerosr|   rº   rœ   r©   )	r)   Úoutput_typert   r~   r5   r6   r¬   Údtype_r±   s	            r*   rz   rz   ë  s$  € ð �hÒ 1§6¡6¨Q¢;°1·7±7¸1±:À²>ÜÐB×IÑIÈ!Ï'É'ÓRÓSÐSä-¨a°BÔ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¨!¯'©'Ð3CÔDØ—W‘W‰
ä# BÓ'ˆ
ô 
‡{�{�1„~Ø�qŠ=Ø�x‰x˜~Ñ-Ø—G‘G“I�Ü—X‘X˜aŸf™f yÑ0¼Ô<ˆAŒFØ×ÑÕà—
‘
˜1Ÿ9™9›;¨Ñ2¸*ÈW�
ÓU‰Aà�J‰JØ�J‰J�q ¨wˆJÓ7¸)ÑCØØð ó 
ˆð �hÒÜ�;‰;�qŒ>Ø—	‘	“ˆAØ�6‰6�QŠ;˜1Ÿ7™7 1™:¨š?Ø˜1šQ ˜T™7Ñ#Ð#à�}‰}˜QÑ 1Ò$Ø—y‘y ¨¡¬S°«VÓ4Ð4à˜rŸz™z¨!¨UÓ3Ñ4Ð4à	Ð.Ò	.Øˆô Ð6×=Ñ=¸kÓJÓKÐKr,   c                   ó    ‡ — e Zd ZU dZddgdgdœZeed<   dddœd„Z ed	¬
«      d„ «       Z	 ed	¬
«      d„ «       Z
d„ Zd„ Zd„ Zd„ Zˆ fd„Zˆ xZS )r   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.

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

    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…   NrX   ©rt   r\   r]   Fc                ó    — || _         || _        y r`   rÖ   )r(   rt   r\   s      r*   ra   zMultiLabelBinarizer.__init__h  s   € ØˆŒØ*ˆÕr,   Trb   c                 óÊ  — d| _         | j                  €2t        t        t        j
                  j                  |«      «      «      }nKt        t        | j                  «      «      t        | j                  «      k  rt        d«      ‚| j                  }t        d„ |D «       «      rt        nt        }t        j                  t        |«      |¬«      | _        || j                  dd | S )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   ó<   K  — | ]  }t        |t        «      –— Œ y ­wr`   ©r—   rŸ   ©Ú.0Úcs     r*   ú	<genexpr>z*MultiLabelBinarizer.fit.<locals>.<genexpr>ˆ  s   è ø€ Ò?°!œ: a¬×-Ñ?ùó   ‚r‘   )Ú_cached_dictrt   ÚsortedÚsetÚ	itertoolsÚchainÚfrom_iterablerœ   r@   ÚallrŸ   Úobjectr¦   Úemptyr&   )r(   r)   rt   r2   s       r*   r+   zMultiLabelBinarizer.fitl  s­   € ð  !ˆÔà�<‰<ÐÜœS¤§¡×!>Ñ!>¸qÓ!AÓBÓC‰GÜ”�T—\‘\Ó"Ó#¤c¨$¯,©,Ó&7Ò7Üð/óð ð —l‘lˆGÜÑ?°wÔ?Ô?•ÄVˆÜŸ™¤ W£°UÔ;ˆŒØ"ˆ�‰‘aÐØˆr,   c                 ót  — | j                   � | j                  |«      j                  |«      S d| _        t	        t
        «      }|j                  |_        | j                  ||«      }t        ||j                  ¬«      }t        d„ |D «       «      rt
        nt        }t        j                  t        |«      |¬«      }||dd t        j                   |d¬«      \  | _        }t        j$                  ||j&                     |j&                  j(                  ¬«      |_        | j*                  s|j-                  «       }|S )aM  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   ó<   K  — | ]  }t        |t        «      –— Œ y ­wr`   rÚ   rÛ   s     r*   rÞ   z4MultiLabelBinarizer.fit_transform.<locals>.<genexpr>­  s   è ø€ Ò;°!œ: a¬×-Ñ;ùrß   r‘   Tr.   )rt   r+   r7   rà   r   rŸ   Ú__len__Údefault_factoryÚ
_transformrá   Úgetræ   rç   r¦   rè   rœ   Úuniquer&   r4   r¶   r2   r\   r|   )r(   r)   Úclass_mappingÚytÚtmpr2   Úinverses          r*   r0   z!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                 ó˜   — t        | «       | j                  «       }| j                  ||«      }| j                  s|j	                  «       }|S )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ï   r\   r|   )r(   r)   Úclass_to_indexró   s       r*   r7   zMultiLabelBinarizer.transform¹  sC   € ô  	˜Ôà×*Ñ*Ó,ˆØ�_‰_˜Q Ó/ˆà×!Ò!Ø—‘“ˆBàˆ	r,   c           
      ó²   — | j                   €@t        t        | j                  t	        t        | j                  «      «      «      «      | _         | j                   S r`   )rà   rƒ   Úzipr&   Úrangerœ   )r(   s    r*   r÷   z MultiLabelBinarizer._build_cacheÓ  s@   € Ø×ÑÐ$Ü $¤S¨¯©¼¼cÀ$Ç-Á-Ó>PÓ8QÓ%RÓ SˆDÔà× Ñ Ð r,   c           	      ó„  — t        j                   d«      }t        j                   ddg«      }t        «       }|D ]S  }t        «       }|D ]  }	 |j                  ||   «       Œ |j	                  |«       |j                  t        |«      «       ŒU |r3t        j                  dj                  t        |t        ¬«      «      «       t        j                  t        |«      t        ¬«      }	t        t!        j"                  |	||ft        |«      dz
  t        |«      f¬«      «      S # t        $ r |j                  |«       Y Œöw xY w)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‘   r^   r•   )rÑ   râ   ÚaddÚKeyErrorÚextendr¼   rœ   Úwarningsr$   r™   rá   rA   r¦   ÚonesrŸ   r   rm   r{   )
r(   r)   rò   r¶   r·   rŒ   ÚlabelsÚindexÚlabelr§   s
             r*   rï   zMultiLabelBinarizer._transformÙ  s  € ô$ —+‘+˜cÓ"ˆÜ—‘˜S 1 #Ó&ˆÜ“%ˆØò 	(ˆFÜ“EˆEØò '�ð'Ø—I‘I˜m¨EÑ2Õ3ð'ð
 �N‰N˜5Ô!Ø�M‰Mœ#˜g›,Õ'ð	(ñ Ü�M‰MØ7×>Ñ>¼vÀgÔSVÔ?WÓXôô �w‰w”s˜7“|¬3Ô/ˆä#Ü�L‰LØ�w Ð'´°F³¸a±ÄÀ]ÓASÐ/Tôó
ð 	
øô  ò 'Ø—K‘K Ö&ð'ús   ÁD"Ä"D?Ä>D?c                 óŽ  — t        | «       |j                  d   t        | j                  «      k7  r;t	        dj                  t        | j                  «      |j                  d   «      «      ‚t        j                  |«      rÉ|j                  «       }t        |j                  «      dk7  r9t        t        j                  |j                  ddg«      «      dkD  rt	        d«      ‚t        |j                  dd |j                  dd «      D ��cg c]6  \  }}t        | j                  j                  |j                   || «      «      ‘Œ8 c}}S t        j                  |ddg«      }t        |«      dkD  rt	        dj                  |«      «      ‚|D �cg c]&  }t        | j                  j#                  |«      «      ‘Œ( c}S c c}}w c c}w )aŸ  Transform the given indicator matrix into label sets.

        Parameters
        ----------
        yt : {ndarray, sparse matrix} of shape (n_samples, n_classes)
            A matrix containing only 1s and 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`.
        r^   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?   rœ   r&   r@   r™   rm   rn   r¹   r§   r¦   r=   rú   r·   ÚtuplerB   r¶   Úcompress)r(   ró   ÚstartÚendÚ
unexpectedÚ
indicatorss         r*   rD   z%MultiLabelBinarizer.inverse_transform  sx  € ô 	˜Ôà�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÷á�E˜3ô �d—m‘m×(Ñ(¨¯©°E¸#Ð)>Ó?Õ@óð ô
 Ÿ™ b¨1¨a¨&Ó1ˆJÜ�:‹ Ò"Ü ØN×UÑUØ"óóð ð
 QSÖSÀ*”E˜$Ÿ-™-×0Ñ0°Ó<Õ=ÒSÐSùóùò Ts   Ä;F<Æ+Gc                 óh   •— t         ‰| �  «       }d|j                  _        d|j                  _        |S r�   )rF   rG   rI   rJ   rK   Útwo_d_labelsrM   s     €r*   rG   z$MultiLabelBinarizer.__sklearn_tags__,  r‚   r,   )rP   rQ   rR   rS   r]   rƒ   r„   ra   r   r+   r0   r7   r÷   rï   rD   rG   rT   rU   s   @r*   r   r   "  sˆ   ø… ñ>ðB ! $Ð'Ø#˜ñ$Ð˜Dó ð
 #'°eô +ñ °Ô5ñó 6ðñ@ °Ô5ñ)ó 6ð)òVò4!ò(
òT'T÷Rð r,   r   r`   )3rÑ   rã   r   Úcollectionsr   Únumbersr   Únumpyr¦   Úscipy.sparseÚsparserm   Úsklearn.baser   r   r   Úsklearn.utilsr   r	   Ú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    ry   rz   r   © r,   r*   ú<module>r     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Ø#˜ñð #'ô	ð -.¸È%ó ^#ó	ð^#óB, ó^4LônNÐ*¨MÐQUö Nr,   