§
    	¼¸j•>  ã                   ó¤   — d dl m Z  d dlmZm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 ddlmZmZmZ dd	lmZ dd
lmZ  G d„ dee¦  «        ZdS )é    )Úarray)ÚIterableÚMapping)ÚNumber)Ú
itemgetterN)Úmetadata_routingé   )ÚBaseEstimatorÚTransformerMixinÚ_fit_context)Úcheck_array)Úcheck_is_fittedc                   ó   ‡ — e Zd ZU dZdej        iZdegdgdgdœZe	e
d<   ej        ddddœd	„Zdd
dddœd„Z ed¬¦  «        dd„¦   «         Zd„ Z ed¬¦  «        dd„¦   «         Ze	fd„Zd„ Zdd„Zdd„Zˆ fd„Zˆ xZS )ÚDictVectorizera¨  Transforms lists of feature-value mappings to vectors.

    This transformer turns lists of mappings (dict-like objects) of feature
    names to feature values into Numpy arrays or scipy.sparse matrices for use
    with scikit-learn estimators.

    When feature values are strings, this transformer will do a binary one-hot
    (aka one-of-K) coding: one boolean-valued feature is constructed for each
    of the possible string values that the feature can take on. For instance,
    a feature "f" that can take on the values "ham" and "spam" will become two
    features in the output, one signifying "f=ham", the other "f=spam".

    If a feature value is a sequence or set of strings, this transformer
    will iterate over the values and will count the occurrences of each string
    value.

    However, note that this transformer will only do a binary one-hot encoding
    when feature values are of type string. If categorical features are
    represented as numeric values such as int or iterables of strings, the
    DictVectorizer can be followed by
    :class:`~sklearn.preprocessing.OneHotEncoder` to complete
    binary one-hot encoding.

    Features that do not occur in a sample (mapping) will have a zero value
    in the resulting array/matrix.

    For an efficiency comparison of the different feature extractors, see
    :ref:`sphx_glr_auto_examples_text_plot_hashing_vs_dict_vectorizer.py`.

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

    Parameters
    ----------
    dtype : dtype, default=np.float64
        The type of feature values. Passed to Numpy array/scipy.sparse matrix
        constructors as the dtype argument.
    separator : str, default="="
        Separator string used when constructing new features for one-hot
        coding.
    sparse : bool, default=True
        Whether transform should produce scipy.sparse matrices.
    sort : bool, default=True
        Whether ``feature_names_`` and ``vocabulary_`` should be
        sorted when fitting.

    Attributes
    ----------
    vocabulary_ : dict
        A dictionary mapping feature names to feature indices.

    feature_names_ : list
        A list of length n_features containing the feature names (e.g., "f=ham"
        and "f=spam").

    See Also
    --------
    FeatureHasher : Performs vectorization using only a hash function.
    sklearn.preprocessing.OrdinalEncoder : Handles nominal/categorical
        features encoded as columns of arbitrary data types.

    Examples
    --------
    >>> from sklearn.feature_extraction import DictVectorizer
    >>> v = DictVectorizer(sparse=False)
    >>> D = [{'foo': 1, 'bar': 2}, {'foo': 3, 'baz': 1}]
    >>> X = v.fit_transform(D)
    >>> X
    array([[2., 0., 1.],
           [0., 1., 3.]])
    >>> v.inverse_transform(X) == [{'bar': 2.0, 'foo': 1.0},
    ...                            {'baz': 1.0, 'foo': 3.0}]
    True
    >>> v.transform({'foo': 4, 'unseen_feature': 3})
    array([[0., 0., 4.]])
    Ú	dict_typeÚno_validationÚboolean©ÚdtypeÚ	separatorÚsparseÚsortÚ_parameter_constraintsú=Tc                ó>   — || _         || _        || _        || _        d S ©Nr   )Úselfr   r   r   r   s        ú{/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/sklearn/feature_extraction/_dict_vectorizer.pyÚ__init__zDictVectorizer.__init__j   s"   € ØˆŒ
Ø"ˆŒØˆŒØˆŒ	ˆ	ˆ	ó    FN©ÚfittingÚtransformingÚindicesÚvaluesc                ó†  — |D ]½}	t          |	t          ¦  «        r|›| j        ›|	›�}
d}	n t          dt	          |	¦  «        › d�¦  «        ‚|r+|
|vr't          |¦  «        ||
<   |                     |
¦  «         |rG|
|v rC|                     ||
         ¦  «         |                     |                      |	¦  «        ¦  «         Œ¾dS )z)Add feature names for iterable of stringsé   zUnsupported type z; in iterable value. Only iterables of string are supported.N)Ú
isinstanceÚstrr   Ú	TypeErrorÚtypeÚlenÚappendr   )r   ÚfÚvÚfeature_namesÚvocabr"   r#   r$   r%   ÚvvÚfeature_names              r   Ú_add_iterable_elementz$DictVectorizer._add_iterable_elementp   sø   € ð ð 	.ð 	.ˆBÝ˜"�cÑ"Ô"ð Ø+,¨1¨d¬n¨n¸b¸bÐA�Ø��åð!­¨R©¬ð !ð !ð !ñô ð ð
 ð 3˜<¨uÐ4Ð4Ý&)¨-Ñ&8Ô&8��lÑ#Ø×$Ò$ \Ñ2Ô2Ð2àð . °Ð 5Ð 5Ø—’˜u \Ô2Ñ3Ô3Ð3Ø—’˜dŸjšj¨™nœnÑ-Ô-Ð-øð!	.ð 	.r    )Úprefer_skip_nested_validationc                 óx  — g }i }|D ]ð}|                      ¦   «         D ]Ù\  }}t          |t          ¦  «        r|›| j        ›|›�}n„t          |t          ¦  «        s|€|}njt          |t
          ¦  «        r&t          dt          |¦  «        › d|› d|› d�¦  «        ‚t          |t          ¦  «        rd}|  	                    ||||¦  «         |�+||vr't          |¦  «        ||<   |                     |¦  «         ŒÚŒñ| j        r-|                     ¦   «          d„ t          |¦  «        D ¦   «         }|| _        || _        | S )a)  Learn a list of feature name -> indices mappings.

        Parameters
        ----------
        X : Mapping or iterable over Mappings
            Dict(s) or Mapping(s) from feature names (arbitrary Python
            objects) to feature values (strings or convertible to dtype).

            .. versionchanged:: 0.24
               Accepts multiple string values for one categorical feature.

        y : (ignored)
            Ignored parameter.

        Returns
        -------
        self : object
            DictVectorizer class instance.
        NzUnsupported value type ú for ú: z$.
Mapping objects are not supported.c                 ó   — i | ]\  }}||“Œ	S © r:   )Ú.0Úir.   s      r   ú
<dictcomp>z&DictVectorizer.fit.<locals>.<dictcomp>¾   s   € Ð?Ð?Ð?™d˜a �Q˜Ð?Ð?Ð?r    )Úitemsr(   r)   r   r   r   r*   r+   r   r4   r,   r-   r   Ú	enumerateÚfeature_names_Úvocabulary_)	r   ÚXÚyr0   r1   Úxr.   r/   r3   s	            r   ÚfitzDictVectorizer.fit�   sš  € ð* ˆØˆàð 	;ð 	;ˆAØŸš™	œ	ð ;ð ;‘��1Ý˜a¥Ñ%Ô%ð KØ/0¨q°$´.°.À!À!Ð#D�L�LÝ ¥6Ñ*Ô*ð 
K¨q¨yØ#$�L�LÝ ¥7Ñ+Ô+ð KÝ#ð=µ$°q±'´'ð =ð =Ø ð=ð =Ø$%ð=ð =ð =ñô ð õ
   ¥8Ñ,Ô,ð KØ#'�LØ×.Ò.¨q°!°]ÀEÑJÔJÐJàÐ+Ø#¨5Ð0Ð0Ý.1°-Ñ.@Ô.@˜˜lÑ+Ø%×,Ò,¨\Ñ:Ô:Ð:øð%;ð( Œ9ð 	@Ø×ÒÑ Ô Ð Ø?Ð?¥i°Ñ&>Ô&>Ð?Ñ?Ô?ˆEà+ˆÔØ ˆÔàˆr    c                 óF  — t          d¦  «        j        dk    s
J d¦   «         ‚| j        }|rg }i }n| j        }| j        }d}t          |t          ¦  «        r|gn|}t          d¦  «        }dg}g }	|D �]v}
|
                     ¦   «         D �];\  }}t          |t          ¦  «        r|›| j	        ›|›�}d}nšt          |t          ¦  «        s|€|}n€t          |t          ¦  «        s5t          |t          ¦  «        r d }|                      ||||||||	¬¦  «         n6t          dt          |¦  «        › d	|› d
|› dt          |¦  «        › d�	¦  «        ‚|�t|r+||vr't          |¦  «        ||<   |                     |¦  «         ||v rC|                     ||         ¦  «         |	                     |                      |¦  «        ¦  «         �Œ=|                     t          |¦  «        ¦  «         �Œxt          |¦  «        dk    rt#          d¦  «        ‚t%          j        |t$          j        ¬¦  «        }t          |¦  «        dz
  t          |¦  «        f}t+          j        |	||f||¬¦  «        }|ry| j        rr|                     ¦   «          t%          j        t          |¦  «        t$          j        ¬¦  «        }t5          |¦  «        D ]\  }}||         ||<   |||<   Œ|d d …|f         }| j        r|                     ¦   «          n|                     ¦   «         }|r|| _        || _        |S )Nr<   é   z¯sizeof(int) != 4 on your platform; please report this at https://github.com/scikit-learn/scikit-learn/issues and include the output from platform.platform() in your bug reportTr   r'   r!   zUnsupported value Type r7   r8   z.
z objects are not supported.zSample sequence X is empty.©r   )Úshaper   )r   Úitemsizer   r@   rA   r(   r   r>   r)   r   r   r   r4   r*   r+   r,   r-   Ú
ValueErrorÚnpÚ
frombufferÚintcÚspÚ
csr_matrixr   ÚemptyÚint32r?   r   Úsort_indicesÚtoarray)r   rB   r"   r   r0   r1   r#   r$   Úindptrr%   rD   r.   r/   r3   rI   Úresult_matrixÚ	map_indexÚnew_vals                     r   Ú
_transformzDictVectorizer._transformÅ   s·  € õ
 �S‰zŒzÔ" aÒ'Ð'Ð'ðNñ (Ô'Ð'ð ”
ˆØð 	%ØˆMØˆEˆEà Ô/ˆMØÔ$ˆEàˆõ ˜a¥Ñ)Ô)Ð0ˆQˆCˆC¨qˆå˜‘*”*ˆØ�ˆð ˆð ð #	(ñ #	(ˆAØŸš™	œ	ð  5ñ  5‘��1Ý˜a¥Ñ%Ô%ð Ø/0¨q°$´.°.À!À!Ð#D�LØ�A�AÝ ¥6Ñ*Ô*ð ¨q¨yØ#$�L�LÝ# A¥wÑ/Ô/ð µJ¸qÅ(Ñ4KÔ4Kð Ø#'�LØ×.Ò.ØØØ%ØØ 'Ø%1Ø 'Ø%ð /ñ 	ô 	ð 	ð 	õ $ð@µ$°q±'´'ð @ð @Ø ð@ð @Ø$%ð@ð @å ™7œ7ð@ð @ð @ñô ð ð  Ð+Øð ; <°uÐ#<Ð#<Ý.1°-Ñ.@Ô.@˜˜lÑ+Ø%×,Ò,¨\Ñ:Ô:Ð:à# uÐ,Ð,ØŸš u¨\Ô':Ñ;Ô;Ð;ØŸš d§j¢j°¡m¤mÑ4Ô4Ð4ùà�MŠM�#˜g™,œ,Ñ'Ô'Ð'Ñ'åˆv‰;Œ;˜!ÒÐÝÐ:Ñ;Ô;Ð;å”- ­r¬wÐ7Ñ7Ô7ˆÝ�V‘”˜q‘¥# e¡*¤*Ð-ˆåœØ�W˜fÐ%¨U¸%ð
ñ 
ô 
ˆð
 ð 	8�t”yð 	8Ø×ÒÑ Ô Ð Ýœ¥ ]Ñ!3Ô!3½2¼8ÐDÑDÔDˆIÝ'¨Ñ6Ô6ð #ð #‘
�˜Ø%*¨1¤X�	˜'Ñ"Ø"��a‘�Ø)¨!¨!¨!¨Y¨,Ô7ˆMàŒ;ð 	4Ø×&Ò&Ñ(Ô(Ð(Ð(à)×1Ò1Ñ3Ô3ˆMàð 	%Ø"/ˆDÔØ$ˆDÔàÐr    c                 ó0   — |                       |d¬¦  «        S )a¬  Learn a list of feature name -> indices mappings and transform X.

        Like fit(X) followed by transform(X), but does not require
        materializing X in memory.

        Parameters
        ----------
        X : Mapping or iterable over Mappings
            Dict(s) or Mapping(s) from feature names (arbitrary Python
            objects) to feature values (strings or convertible to dtype).

            .. versionchanged:: 0.24
               Accepts multiple string values for one categorical feature.

        y : (ignored)
            Ignored parameter.

        Returns
        -------
        Xa : {array, sparse matrix}
            Feature vectors; always 2-d.
        T©r"   )rY   )r   rB   rC   s      r   Úfit_transformzDictVectorizer.fit_transform(  s   € ð0 �Š˜q¨$ˆÑ/Ô/Ð/r    c                 óä  ‡— t          | d¦  «         t          |ddg¬¦  «        }|j        d         }| j        }ˆfd„t	          |¦  «        D ¦   «         }t          j        |¦  «        r;t          |                     ¦   «         Ž D ]\  }}|||f         ||         ||         <   ŒnMt          |¦  «        D ]=\  }}t          ||dd…f         ¦  «        D ]\  }}	|	dk    r|||f         |||         <   ŒŒ>|S )aN  Transform array or sparse matrix X back to feature mappings.

        X must have been produced by this DictVectorizer's transform or
        fit_transform method; it may only have passed through transformers
        that preserve the number of features and their order.

        In the case of one-hot/one-of-K coding, the constructed feature
        names and values are returned rather than the original ones.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Sample matrix.
        dict_type : type, default=dict
            Constructor for feature mappings. Must conform to the
            collections.Mapping API.

        Returns
        -------
        D : list of dict_type objects of shape (n_samples,)
            Feature mappings for the samples in X.
        r@   ÚcsrÚcsc)Úaccept_sparser   c                 ó$   •— g | ]} ‰¦   «         ‘ŒS r:   r:   )r;   Ú_r   s     €r   ú
<listcomp>z4DictVectorizer.inverse_transform.<locals>.<listcomp>`  s   ø€ Ð7Ð7Ð7 ��‘”Ð7Ð7Ð7r    N)
r   r   rI   r@   ÚrangerO   ÚissparseÚzipÚnonzeror?   )
r   rB   r   Ú	n_samplesÚnamesÚdictsr<   ÚjÚdr/   s
     `       r   Úinverse_transformz DictVectorizer.inverse_transformB  s#  ø€ õ. 	˜Ð.Ñ/Ô/Ð/õ ˜¨%°¨Ð8Ñ8Ô8ˆØ”G˜A”Jˆ	àÔ#ˆØ7Ð7Ð7Ð7¥e¨IÑ&6Ô&6Ð7Ñ7Ô7ˆåŒ;�q‰>Œ>ð 	.Ý˜QŸYšY™[œ[Ð)ð -ð -‘��1Ø%& q¨! t¤W��a”˜˜qœÑ"Ð"ð-õ " %Ñ(Ô(ð .ð .‘��1Ý% a¨¨1¨1¨1¨¤gÑ.Ô.ð .ð .‘D�A�qØ˜A’v�vØ&'¨¨1¨¤g˜˜% œ(™øð.ð ˆr    c                 óT   — t          | ddg¦  «         |                      |d¬¦  «        S )a  Transform feature->value dicts to array or sparse matrix.

        Named features not encountered during fit or fit_transform will be
        silently ignored.

        Parameters
        ----------
        X : Mapping or iterable over Mappings of shape (n_samples,)
            Dict(s) or Mapping(s) from feature names (arbitrary Python
            objects) to feature values (strings or convertible to dtype).

        Returns
        -------
        Xa : {array, sparse matrix}
            Feature vectors; always 2-d.
        r@   rA   Fr[   )r   rY   )r   rB   s     r   Ú	transformzDictVectorizer.transformm  s0   € õ" 	˜Ð/°Ð?Ñ@Ô@Ð@Ø�Š˜q¨%ˆÑ0Ô0Ð0r    c                 óÆ   — t          | d¦  «         t          d„ | j        D ¦   «         ¦  «        rd„ | j        D ¦   «         }n| j        }t          j        |t
          ¬¦  «        S )a^  Get output feature names for transformation.

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

        Returns
        -------
        feature_names_out : ndarray of str objects
            Transformed feature names.
        r@   c              3   óB   K  — | ]}t          |t          ¦  «         V — Œd S r   )r(   r)   ©r;   Únames     r   ú	<genexpr>z7DictVectorizer.get_feature_names_out.<locals>.<genexpr>�  s/   è è € ÐIÐI¨T•:˜d¥CÑ(Ô(Ð(ÐIÐIÐIÐIÐIÐIr    c                 ó,   — g | ]}t          |¦  «        ‘ŒS r:   )r)   rr   s     r   rc   z8DictVectorizer.get_feature_names_out.<locals>.<listcomp>�  s   € ÐGÐGÐG¨4�S ™YœYÐGÐGÐGr    rH   )r   Úanyr@   rL   ÚasarrayÚobject)r   Úinput_featuresr0   s      r   Úget_feature_names_outz$DictVectorizer.get_feature_names_out�  sl   € õ 	˜Ð.Ñ/Ô/Ð/ÝÐIÐI°TÔ5HÐIÑIÔIÑIÔIð 	0ØGÐG°4Ô3FÐGÑGÔGˆMˆMà Ô/ˆMÝŒz˜-­vÐ6Ñ6Ô6Ð6r    c                 ó6  — t          | d¦  «         |st          j        |¦  «        d         }| j        }i }|D ]}t	          |¦  «        |||         <   Œ|| _        d„ t          |                     ¦   «         t          d¦  «        ¬¦  «        D ¦   «         | _        | S )a=  Restrict the features to those in support using feature selection.

        This function modifies the estimator in-place.

        Parameters
        ----------
        support : array-like
            Boolean mask or list of indices (as returned by the get_support
            member of feature selectors).
        indices : bool, default=False
            Whether support is a list of indices.

        Returns
        -------
        self : object
            DictVectorizer class instance.

        Examples
        --------
        >>> from sklearn.feature_extraction import DictVectorizer
        >>> from sklearn.feature_selection import SelectKBest, chi2
        >>> v = DictVectorizer()
        >>> D = [{'foo': 1, 'bar': 2}, {'foo': 3, 'baz': 1}]
        >>> X = v.fit_transform(D)
        >>> support = SelectKBest(chi2, k=2).fit(X, [0, 1])
        >>> v.get_feature_names_out()
        array(['bar', 'baz', 'foo'], ...)
        >>> v.restrict(support.get_support())
        DictVectorizer()
        >>> v.get_feature_names_out()
        array(['bar', 'foo'], ...)
        r@   r   c                 ó   — g | ]\  }}|‘ŒS r:   r:   )r;   r.   r<   s      r   rc   z+DictVectorizer.restrict.<locals>.<listcomp>Á  s)   € ð 
ð 
ð 
Ù�!�QˆAð
ð 
ð 
r    r'   )Úkey)	r   rL   Úwherer@   r,   rA   Úsortedr>   r   )r   Úsupportr$   ri   Ú	new_vocabr<   s         r   ÚrestrictzDictVectorizer.restrict•  s²   € õB 	˜Ð.Ñ/Ô/Ð/àð 	+Ý”h˜wÑ'Ô'¨Ô*ˆGàÔ#ˆØˆ	Øð 	1ð 	1ˆAÝ"% i¡.¤.ˆI�e˜A”hÑÐà$ˆÔð
ð 
Ý  §¢Ñ!2Ô!2½
À1¹¼ÐFÑFÔFð
ñ 
ô 
ˆÔð ˆr    c                 óx   •— t          ¦   «                              ¦   «         }d|j        _        d|j        _        |S )NTF)ÚsuperÚ__sklearn_tags__Ú
input_tagsÚdictÚtwo_d_array)r   ÚtagsÚ	__class__s     €r   r…   zDictVectorizer.__sklearn_tags__Ç  s1   ø€ Ý‰wŒw×'Ò'Ñ)Ô)ˆØ#ˆŒÔØ&+ˆŒÔ#Øˆr    r   )F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚUNUSEDÚ4_DictVectorizer__metadata_request__inverse_transformr)   r   r‡   Ú__annotations__rL   Úfloat64r   r4   r   rE   rY   r\   rm   ro   rz   r‚   r…   Ú__classcell__)rŠ   s   @r   r   r      s™  ø€ € € € € € ðJð JðZ .9Ð:JÔ:QÐ,RÐ)ð !Ø�UØ�+Ø�ð	$ð $Ð˜Dð ð ñ ð !#¤
°cÀ$ÈTð ð ð ð ð ð ØØØð.ð .ð .ð .ð .ð> €\°Ð5Ñ5Ô5ð3ð 3ð 3ñ 6Ô5ð3ðjað að aðF €\°Ð5Ñ5Ô5ð0ð 0ð 0ñ 6Ô5ð0ð2 .2ð )ð )ð )ð )ðV1ð 1ð 1ð(7ð 7ð 7ð 7ð(0ð 0ð 0ð 0ðdð ð ð ð ð ð ð ð r    r   )r   Úcollections.abcr   r   Únumbersr   Úoperatorr   ÚnumpyrL   Úscipy.sparser   rO   Úsklearn.utilsr   Úbaser
   r   r   Úutilsr   Úutils.validationr   r   r:   r    r   ú<module>r�      s  ðð Ð Ð Ð Ð Ð Ø -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ø Ð Ð Ð Ð Ð à *Ð *Ð *Ð *Ð *Ð *à @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ø Ð Ð Ð Ð Ð Ø .Ð .Ð .Ð .Ð .Ð .ðxð xð xð xð xÐ% }ñ xô xð xð xð xr    