� J�g�N����dZddlZddlmZddlmZddlZddlm Z ddl m Z ddl m Z d d lmZmZd d lmZmZdd �Zdd �Zeeed�Zd�Zd�Zd�Zd�Zdd�Zdd�Zdd�Zd�ZdS)zAUtilities to handle multiclass/multioutput target in classifiers.�N)�Sequence)�chain)�issparse�)� get_namespace)�VisibleDeprecationWarning�)� attach_unique� cached_unique)�_assert_all_finite� check_arrayc��t||���\}}t|d��s|r$t|�|��|���St |��S)N��xp� __array__)r�hasattrr �asarray�set��yr�is_array_api_compliants �h/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sklearn/utils/multiclass.py�_unique_multiclassrs\��!.�q�R�!8�!8�!8��B���q�+����"8���R�Z�Z��]�]�r�2�2�2�2��1�v�v� �c��t||���\}}|�t|dgd����jd��S)Nrr��csr�csc�coo)� input_name� accept_sparser )r�aranger �shape)rr�_s r�_unique_indicatorr%sP�� �!�� #� #� #�E�B�� �9�9��A�#�5J�5J�5J�K�K�K�Q�RS�T� � �r)�binary� multiclass�multilabel-indicatorc����t|ddi�}t|�\�}t|��dkrtd���t d�|D����}|ddhkrdh}t|��dkrtd |z���|���}|d kr9tt d �|D������dkrtd ���t �|d ����stdt|��z���|r7�� ��fd�|D����}�� |��St tj ��fd�|D������}tt d�|D������dkrtd����� t|����S)a�Extract an ordered array of unique labels. We don't allow: - mix of multilabel and multiclass (single label) targets - mix of label indicator matrix and anything else, because there are no explicit labels) - mix of label indicator matrices of different sizes - mix of string and integer labels At the moment, we also don't allow "multiclass-multioutput" input type. Parameters ---------- *ys : array-likes Label values. Returns ------- out : ndarray of shape (n_unique_labels,) An ordered array of unique labels. Examples -------- >>> from sklearn.utils.multiclass import unique_labels >>> unique_labels([3, 5, 5, 5, 7, 7]) array([3, 5, 7]) >>> unique_labels([1, 2, 3, 4], [2, 2, 3, 4]) array([1, 2, 3, 4]) >>> unique_labels([1, 2, 10], [5, 11]) array([ 1, 2, 5, 10, 11]) � return_tupleTrzNo argument has been passed.c3�4K�|]}t|��V��dS�N)�type_of_target)�.0�xs r� <genexpr>z unique_labels.<locals>.<genexpr>Os*����1�1��>�!�$�$�1�1�1�1�1�1rr&r'r z'Mix type of y not allowed, got types %sr(c3�RK�|]"}t|gd����jdV��#dS)r)r!r N)r r#)r.rs rr0z unique_labels.<locals>.<genexpr>\sO������QR� �A�-B�-B�-B�C�C�C�I�!�L������rzCMulti-label binary indicator input with different numbers of labelsNzUnknown label type: %sc�*��g|]}�|������S)r��r.r�_unique_labelsrs ��r� <listcomp>z!unique_labels.<locals>.<listcomp>ms(���D�D�D�A�~�~�a�B�7�7�7�D�D�Drc3�F�K�|]}d��|����D��V��dS)c3�K�|]}|V��dSr,r3)r.�is rr0z*unique_labels.<locals>.<genexpr>.<genexpr>qs"����A�A�1�Q�A�A�A�A�A�ArrNr3r4s ��rr0z unique_labels.<locals>.<genexpr>qsA�����N�N�a�A�A���q�R�(@�(@�(@�A�A�A�N�N�N�N�N�Nrc3�@K�|]}t|t��V��dSr,)� isinstance�str)r.�labels rr0z unique_labels.<locals>.<genexpr>ts,����=�=�%�z�%��%�%�=�=�=�=�=�=rz,Mix of label input types (string and number))r r�len� ValueErrorr�pop�_FN_UNIQUE_LABELS�get�repr�concat� unique_valuesr� from_iterabler�sorted)�ysr�ys_types� label_type� unique_ys� ys_labelsr5rs @@r� unique_labelsrM)s ����@ �� .�� .� .�B�!.��!3��B�� �2�w�w�!�|�|��7�8�8�8��1�1�b�1�1�1�1�1�H��H�l�+�+�+� �>�� �8�}�}�q����B�X�M�N�N�N������J� �,�,�,� � ���VX���� � � � � �  � �� Q� � � � '�*�*�:�t�<�<�N� �>��1�D��H�H�<�=�=�=��+��I�I�D�D�D�D�D��D�D�D�E�E� ���� �*�*�*�� ��N�N�N�N�N�2�N�N�N�N�N���I� �3�=�=�9�=�=�=� =� =�>�>��B�B��G�H�H�H� �:�:�f�Y�'�'� (� (�(rc � �t|��\}}|�|jd��oWt|�|�|�||j��|j��|k����S)N� real floating)r�isdtype�dtype�bool�all�astype�int64rs r�_is_integral_floatrVzsr��!.�q�!1�!1��B�� �:�:�a�g�� /� /� �D� ���r�y�y�"�)�)�A�r�x�0�0�1�7�;�;�q�@�A�A�5�5�rc��t|��\}}t|d��st|t��s|r�t dddddd���}t j��5t jdt�� t|fddi|��}nU#ttf$rA}t|��� d ��r�t|fdti|��}Yd}~nd}~wwxYwddd��n #1swxYwYt|d ��r|jd kr|jd d ksdSt!|��r�|jd vr|���}|�|j��}t+|j��dkp6|jd ks|jd ko d|vo|jjdvpt3|��St5||���}|jddko)|�|jd��pt3|��S)a~Check if ``y`` is in a multilabel format. Parameters ---------- y : ndarray of shape (n_samples,) Target values. Returns ------- out : bool Return ``True``, if ``y`` is in a multilabel format, else ```False``. Examples -------- >>> import numpy as np >>> from sklearn.utils.multiclass import is_multilabel >>> is_multilabel([0, 1, 0, 1]) False >>> is_multilabel([[1], [0, 2], []]) False >>> is_multilabel(np.array([[1, 0], [0, 0]])) True >>> is_multilabel(np.array([[1], [0], [0]])) False >>> is_multilabel(np.array([[1, 0, 0]])) True rTFr�r!�allow_nd�ensure_all_finite� ensure_2d�ensure_min_samples�ensure_min_features�errorrQN�Complex data not supportedr#rr )�dok�lil�biur�)rRzsigned integerzunsigned integer)rrr;r�dict�warnings�catch_warnings� simplefilterrr r?r<� startswith�object�ndimr#r�format�tocsrrE�datar>�sizerQ�kindrVr rP)rrr�check_y_kwargs�e�labelss r� is_multilabelrs�s���8"/�q�!1�!1��B���q�+���C�*�Q��"9�"9�C�=S�C����#�� � !�  � � ��� $� &� &� C� C� � !�'�+D� E� E� E� C���@�@��@��@�@����-�z�:� C� C� C��q�6�6�$�$�%A�B�B��� ��B�B��B�>�B�B�����������  C���� C� C� C� C� C� C� C� C� C� C� C���� C� C� C� C� �A�w� � ��A�F�a�K�K�A�G�A�J��N�N��u���{�{� � �8�~� %� %���� � �A��!�!�!�&�)�)�� ���K�K�1� � F�� �q� �H�V�[�A�%5�$H�A��K�F�����&�D�*<�V�*D�*D� � �q�R�(�(�(���|�A���"� � �J�J�q�w� N� O� O� *�!�&�)�)� s<�"C/�>B� C/�C �7C�C/�C � C/�/C3�6C3c�V�t|d���}|dvrtd|�d����dS)aAEnsure that target y is of a non-regression type. Only the following target types (as defined in type_of_target) are allowed: 'binary', 'multiclass', 'multiclass-multioutput', 'multilabel-indicator', 'multilabel-sequences' Parameters ---------- y : array-like Target values. r�r )r&r'zmulticlass-multioutputr(zmultilabel-sequenceszUnknown label type: zy. Maybe you are trying to fit a classifier, which expects discrete classes on a regression target with continuous values.N)r-r?)r�y_types r�check_classification_targetsrw�s\���A�#� .� .� .�F� ����� 8�6� 8� 8� 8� � � ��r�Fc�L����t���\}}���fd�}t�t��st���st �d��rt�t �� p|}|st d�z����jjdv}|rt d���t���rdStddddd d � ��}tj ��5tj d t��t���sf t�fd d i|���nU#tt f$rA} t | ���d��r�t�fd t"i|���Yd } ~ nd } ~ wwxYwd d d ��n #1swxYwY t���r �d gd d �fn�d } t| t$��rtjdt(��t | d��s9t| t��r$t| t ��st d���n#t*$rYnwxYw�jdvr |��St/�j��s�jdkrdS|��St���s:�jt"kr*t�jd t ��s |��S�jdkr�jddkrd} nd} |��jd��r`t���r�jn�} |�| |�| t>��k��rtA| ����d| zSt| ��r| j} tC���jd dks�jdkrtE| ��dkrd| zSdS)a� Determine the type of data indicated by the target. Note that this type is the most specific type that can be inferred. For example: * ``binary`` is more specific but compatible with ``multiclass``. * ``multiclass`` of integers is more specific but compatible with ``continuous``. * ``multilabel-indicator`` is more specific but compatible with ``multiclass-multioutput``. Parameters ---------- y : {array-like, sparse matrix} Target values. If a sparse matrix, `y` is expected to be a CSR/CSC matrix. input_name : str, default="" The data name used to construct the error message. .. versionadded:: 1.1.0 raise_unknown : bool, default=False If `True`, raise an error when the type of target returned by :func:`~sklearn.utils.multiclass.type_of_target` is `"unknown"`. .. versionadded:: 1.6 Returns ------- target_type : str One of: * 'continuous': `y` is an array-like of floats that are not all integers, and is 1d or a column vector. * 'continuous-multioutput': `y` is a 2d array of floats that are not all integers, and both dimensions are of size > 1. * 'binary': `y` contains <= 2 discrete values and is 1d or a column vector. * 'multiclass': `y` contains more than two discrete values, is not a sequence of sequences, and is 1d or a column vector. * 'multiclass-multioutput': `y` is a 2d array that contains more than two discrete values, is not a sequence of sequences, and both dimensions are of size > 1. * 'multilabel-indicator': `y` is a label indicator matrix, an array of two dimensions with at least two columns, and at most 2 unique values. * 'unknown': `y` is array-like but none of the above, such as a 3d array, sequence of sequences, or an array of non-sequence objects. Examples -------- >>> from sklearn.utils.multiclass import type_of_target >>> import numpy as np >>> type_of_target([0.1, 0.6]) 'continuous' >>> type_of_target([1, -1, -1, 1]) 'binary' >>> type_of_target(['a', 'b', 'a']) 'binary' >>> type_of_target([1.0, 2.0]) 'binary' >>> type_of_target([1, 0, 2]) 'multiclass' >>> type_of_target([1.0, 0.0, 3.0]) 'multiclass' >>> type_of_target(['a', 'b', 'c']) 'multiclass' >>> type_of_target(np.array([[1, 2], [3, 1]])) 'multiclass-multioutput' >>> type_of_target([[1, 2]]) 'multilabel-indicator' >>> type_of_target(np.array([[1.5, 2.0], [3.0, 1.6]])) 'continuous-multioutput' >>> type_of_target(np.array([[0, 1], [1, 1]])) 'multilabel-indicator' c�B���r�r�nd}td|�d������dS)zdDepending on the value of raise_unknown, either raise an error or return 'unknown'. rmzUnknown label type for z: �unknown)r?)�inputr � raise_unknownrs ���r�_raise_or_returnz(type_of_target.<locals>._raise_or_return4s?��� � �",�8�J�J�&�E��E�u�E�E��E�E�F�F� F��9rrz:Expected array-like (array or non-string sequence), got %r)� SparseSeries� SparseArrayz1y cannot be class 'SparseSeries' or 'SparseArray'r(TFrrXr^rQNr_z�Support for labels represented as bytes is deprecated in v1.5 and will error in v1.7. Convert the labels to a string or integer format.z�You appear to be using a legacy multi-label data representation. Sequence of sequences are no longer supported; use a binary array or sparse matrix instead - the MultiLabelBinarizer transformer can convert to this format.)r rr r&rz -multioutputrxrOru� continuousr')#rr;rrrr<r?� __class__�__name__rsrdrerfrgrr rhri�bytes�warn� FutureWarning� IndexErrorrj�minr#rQ�flatrPrm�anyrT�intr r r>) rr r}rrr~�valid� sparse_pandasrprq�first_row_or_val�suffixrms ``` rr-r-�s������Z"/�q�!1�!1��B��������� �A�x� � � J�H�Q�K�K� J�7�1�k�3J�3J� #��1�c�"�"� "� "� !� � � �� H�1� L� � � ��K�(�,K�K�M��N��L�M�M�M��Q���&�%�%� ������� ���N� � � "� "� C� C���g�'@�A�A�A���{�{� C� C���@�@��@��@�@����-�z�:� C� C� C��q�6�6�$�$�%A�B�B��� ��B�B��B�>�B�B�����������  C���� C� C� C� C� C� C� C� C� C� C� C���� C� C� C� C� �)1�� � �=�1�a�S�!�!�!�V�9�9��1��� �&�� .� .� � �M���  � � ��(�+�6�6� ��+�X�6�6� ��/��5�5� � �;��� ��� � � � � �� ���� �v�V�����!�!�!� �q�w�<�<�"� �6�Q�;�;��8���!�!�!� �A�;�;�"�1�7�f�,�,�Z���q� �3�5O�5O�,���!�!�!� �v��{�{�q�w�q�z�A�~�~������ �z�z�!�'�?�+�+�)�!�!���+�q�v�v�!�� �6�6�$�"�)�)�D�#�.�.�.� /� /� )� �t� � ;� ;� ;� ;��&�(� (�� �!�!�1�+�0���Q����a� �1�$�$���1����=M�9N�9N�QR�9R�9R��f�$�$��xsO�*E1�D�E1�E"�!7E�E1�E"�"E1�1E5�8E5�=BH� H'�&H'c� �t|dd���|�td���|�it|dd���Btj|jt |����std|�d|j�����nt |��|_dSdS)a"Private helper function for factorizing common classes param logic. Estimators that implement the ``partial_fit`` API need to be provided with the list of possible classes at the first call to partial_fit. Subsequent calls to partial_fit should check that ``classes`` is still consistent with a previous value of ``clf.classes_`` when provided. This function returns True if it detects that this was the first call to ``partial_fit`` on ``clf``. In that case the ``classes_`` attribute is also set on ``clf``. �classes_Nz8classes must be passed on the first call to partial_fit.z `classes=z7` is not the same as on last call to partial_fit, was: TF)�getattrr?�np� array_equalr�rM)�clf�classess r�_check_partial_fit_first_callr��s����s�J��%�%�-�'�/��S�T�T�T� � � �3� �D� )� )� 5��>�#�,� �g�0F�0F�G�G� � �j�18���#�,�,�H���� �)��1�1�C�L��4� �5rc�^�g}g}g}|j\}}|�tj|��}t|���r�|���}tj|j��}t|��D�]�}|j|j||j|dz�} |�2|| } tj |��tj | ��z } nd} |jd||z } tj |j |j||j|dz�d���\} } tj | | ���}d| vr|| dkxx| z cc<d| vrC|||jdkr,tj | dd��} tj |d| ��}|�| ��|�| jd��|�||� ��z �����n�t|��D]�}tj |dd�|fd���\} } |�| ��|�| jd��tj | |���}|�||� ��z ����|||fS)azCompute class priors from multioutput-multiclass target data. Parameters ---------- y : {array-like, sparse matrix} of size (n_samples, n_outputs) The labels for each example. sample_weight : array-like of shape (n_samples,), default=None Sample weights. Returns ------- classes : list of size n_outputs of ndarray of size (n_classes,) List of classes for each column. n_classes : list of int of size n_outputs Number of classes in each column. class_prior : list of size n_outputs of ndarray of size (n_classes,) Class distribution of each column. Nr rT)�return_inverse)�weights)r#r�rr�tocsc�diff�indptr�range�indices�sum�uniquerm�bincount�insert�append)r� sample_weightr�� n_classes� class_prior� n_samples� n_outputs�y_nnz�k� col_nonzero�nz_samp_weight�zeros_samp_weight_sum� classes_k�y_k� class_prior_ks r�class_distributionr��s���,�G��I��K��7��I�y�� �� �=�1�1� ���{�{�'D� �G�G�I�I������!�!���y�!�!� D� D�A��)�A�H�Q�K�!�(�1�q�5�/�$A�B�K��(�!.�{�!;��(*��}�(=�(=���~�@V�@V�(V�%�%�!%��()��� �U�1�X�(=�%��Y���q�x��{�Q�X�a�!�e�_�4�5�d����N�I�s��K��^�D�D�D�M��I�~�~��i�1�n�-�-�-�1F�F�-�-�-�� �!�!�e�A�h�����&;�&;��I�i��A�6�6� � "� �-��<Q� R� R� � �N�N�9� %� %� %� � � �Y�_�Q�/� 0� 0� 0� � � �}�}�/@�/@�/B�/B�B� C� C� C� C�9 D�<�y�!�!� D� D�A��Y�q����A��w�t�D�D�D�N�I�s� �N�N�9� %� %� %� � � �Y�_�Q�/� 0� 0� 0��K��]�C�C�C�M� � � �}�}�/@�/@�/B�/B�B� C� C� C� C� �Y� � ,�,rc��|jd}tj||f��}tj||f��}d}t|��D]�}t|dz|��D]�}|dd�|fxx|dd�|fzcc<|dd�|fxx|dd�|fz cc<||dd�|fdk|fxxdz cc<||dd�|fdk|fxxdz cc<|dz }����|dtj|��dzzz } || zS)ayCompute a continuous, tie-breaking OvR decision function from OvO. It is important to include a continuous value, not only votes, to make computing AUC or calibration meaningful. Parameters ---------- predictions : array-like of shape (n_samples, n_classifiers) Predicted classes for each binary classifier. confidences : array-like of shape (n_samples, n_classifiers) Decision functions or predicted probabilities for positive class for each binary classifier. n_classes : int Number of classes. n_classifiers must be ``n_classes * (n_classes - 1 ) / 2``. rr Nrc)r#r��zerosr��abs) � predictions� confidencesr�r��votes�sum_of_confidencesr�r9�j�transformed_confidencess r�_ovr_decision_functionr�s~��&�!�!�$�I� �H�i��+� ,� ,�E���9�i�"8�9�9�� �A� �9� � �����q�1�u�i�(�(� � �A� �q�q�q�!�t� $� $� $� �A�A�A�q�D�(9� 9� $� $� $� �q�q�q�!�t� $� $� $� �A�A�A�q�D�(9� 9� $� $� $� �+�a�a�a��d�#�q�(�!�+� ,� ,� ,�� 1� ,� ,� ,� �+�a�a�a��d�#�q�(�!�+� ,� ,� ,�� 1� ,� ,� ,� ��F�A�A�  �1� �R�V�&� '� '�!� +�,��� �*� *�*rr,)rxF)�__doc__re�collections.abcr� itertoolsr�numpyr�� scipy.sparser�utils._array_apir� utils.fixesr�_uniquer r � validationr r rr%rArMrVrsrwr-r�r�r�r3rr�<module>r�s���G�G� ����$�$�$�$�$�$�����������!�!�!�!�!�!�,�,�,�,�,�,�3�3�3�3�3�3�1�1�1�1�1�1�1�1�7�7�7�7�7�7�7�7���������!�$�-����N)�N)�N)�b���F �F �F �R � � �6F�F�F�F�R � � � �FG-�G-�G-�G-�T*+�*+�*+�*+�*+r
Memory