
    -iO                         S 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  SSKJr  S	S
KJrJr  S	SKJrJr  SS jrSS jr\\\S.rS rS rS rS rSS jrSS jrSS jrS rg)zAUtilities to handle multiclass/multioutput target in classifiers.    N)Sequence)chain)issparse   )get_namespace)VisibleDeprecationWarning   )attach_uniquecached_unique)_assert_all_finitecheck_arrayc                     [        XS9u  p[        U S5      (       d  U(       a  [        UR                  U 5      US9$ [	        U 5      $ )Nxp	__array__)r   hasattrr   asarraysetyr   is_array_api_compliants      K/var/www/html/venv/lib/python3.13/site-packages/sklearn/utils/multiclass.py_unique_multiclassr      s=    !.q!8Bq+"8RZZ]r221v    c                 j    [        XS9u  pUR                  [        U S/ SQS9R                  S   5      $ )Nr   r   csrcsccoo)
input_nameaccept_sparser	   )r   aranger   shape)r   r   _s      r   _unique_indicatorr%      s8    !#EB99A#5JKQQRST r   )binary
multiclassmultilabel-indicatorc            
      &  ^^ [        U SS06n [        U 6 u  mn[        U 5      S:X  a  [        S5      e[	        S U  5       5      nUSS1:X  a  S1n[        U5      S:  a  [        S	U-  5      eUR                  5       nUS
:X  a*  [        [	        S U  5       5      5      S:  a  [        S5      e[        R                  US5      mT(       d  [        S[        U 5      -  5      eU(       a8  TR                  U  Vs/ s H
  nT" UTS9PM     sn5      nTR                  U5      $ [	        [        R                  " UU4S jU  5       5      5      n[        [	        S U 5       5      5      S:  a  [        S5      eTR                  [        U5      5      $ s  snf )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_tupleTr   zNo argument has been passed.c              3   8   #    U  H  n[        U5      v   M     g 7fN)type_of_target).0xs     r   	<genexpr> unique_labels.<locals>.<genexpr>O   s     1b>!$$bs   r&   r'   r	   z'Mix type of y not allowed, got types %sr(   c              3   T   #    U  H  n[        U/ S QS9R                  S   v   M      g7f)r   )r!   r	   N)r   r#   )r.   r   s     r   r0   r1   \   s(      VXQRA-BCII!LVXs   &(zCMulti-label binary indicator input with different numbers of labelsNzUnknown label type: %sr   c              3   @   >#    U  H  nS  T" UTS9 5       v   M     g7f)c              3   $   #    U  H  ov   M     g 7fr,    )r.   is     r   r0   *unique_labels.<locals>.<genexpr>.<genexpr>q   s     A(@1Q(@s   r   Nr5   )r.   r   _unique_labelsr   s     r   r0   r1   q   s!     N2aAqR(@AA2s   c              3   B   #    U  H  n[        U[        5      v   M     g 7fr,   )
isinstancestr)r.   labels     r   r0   r1   t   s     =9%z%%%9s   z,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_typer   	unique_ys	ys_labelsr8   r   s	          @@r   unique_labelsrL   )   s   @ 
	.	.B!.!3B
2w!|788 1b11HHl++ >
8}qBXMNNJ 	,, VX 

  Q
 	

 '**:t<N1DH<==IIDA~aB7DE		**N2NNI 3=9==>BGHH::fY'(( Es   7Fc           
         [        U 5      u  pUR                  U R                  S5      =(       aP    [        UR	                  UR                  UR                  XR                  5      U R                  5      U :H  5      5      $ )Nreal floating)r   isdtypedtypeboolallastypeint64r   s      r   _is_integral_floatrU   z   s_    !.q!1B::agg/ D
ryy"))Axx0177;q@A5 r   c           	         [        U 5      u  p[        U S5      (       d  [        U [        5      (       d  U(       aV  [	        SSSSSSS9n[
        R                  " 5          [
        R                  " S[        5         [        U 4SS0UD6n SSS5        [        U S
5      (       a#  U R                  S:X  a  U R                  S   S:  d  g[!        U 5      (       a  U R"                  S;   a  U R%                  5       n UR'                  U R(                  5      n[+        U R(                  5      S:H  =(       dc    UR,                  S:H  =(       d    UR,                  S:H  =(       a    SU;   =(       a+    U R.                  R0                  S;   =(       d    [3        U5      $ [5        XS9nUR                  S   S:  =(       a.    UR7                  U R.                  S5      =(       d    [3        U5      $ ! [        [        4 a=  n[        U5      R                  S	5      (       a  e [        U 4S[        0UD6n  SnAGNSnAff = f! , (       d  f       GN= f)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
r   TFr   r!   allow_ndensure_all_finite	ensure_2densure_min_samplesensure_min_featureserrorrP   NComplex data not supportedr#   r   r	   )doklilbiur      )rQ   zsigned integerzunsigned integer)r   r   r:   r   dictwarningscatch_warningssimplefilterr   r   r>   r;   
startswithobjectndimr#   r   formattocsrrD   datar=   sizerP   kindrU   r   rO   )r   r   r   check_y_kwargselabelss         r   is_multilabelrr      s   8 "/q!1Bq+*Q"9"9=S #  !
 $$&!!'+DEC@@@ ' AwAFFaKAGGAJN{{88~%	A!!!&&)166{a 
[[AG6;;!#3"F!v+ F&D*<V*D	

 q(||A" 
JJqww NO *!&)	
- .z: Cq6$$%ABB  BB>BC	 '&s0   H3;G##H032H+%H3+H00H33
Ic                 B    [        U SS9nUS;  a  [        SU S35      eg)a!  Ensure 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'   zmulticlass-multioutputr(   zmultilabel-sequenceszUnknown 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_targetsrv      sB     A#.F   "6( +8 8
 	
r   c           	      T  ^ ^^ [        T 5      u  p4UUU 4S jn[        T [        5      =(       d    [        T 5      =(       d    [	        T S5      =(       a    [        T [
        5      (       + =(       d    UnU(       d  [        ST -  5      eT R                  R                  S;   nU(       a  [        S5      e[        T 5      (       a  g[        SSSSS	S	S
9n[        R                  " 5          [        R                  " S[        5        [        T 5      (       d   [        T 4SS0UD6m SSS5         [        T 5      (       a
  T S	/SS24   OT S	   n
[        U
[$        5      (       a  ['        S5      e[	        U
S5      (       d5  [        U
[        5      (       a   [        U
[
        5      (       d  [        S5      eT R*                  S;  a  U" 5       $ [-        T R.                  5      (       d  T R*                  S:X  a  gU" 5       $ [        T 5      (       d=  T R0                  ["        :X  a)  [        T R2                  S	   [
        5      (       d  U" 5       $ T R*                  S:X  a  T R.                  S   S:  a  SnOSnUR5                  T R0                  S5      (       aY  [        T 5      (       a  T R6                  OT nUR9                  XR;                  U[<        5      :g  5      (       a  [?        UTS9  SU-   $ [        W
5      (       a  U
R6                  n
[A        T 5      nT R.                  S	   S:  a]  T R.                  S	   UR.                  S	   s=:  a  [C        ST R.                  S	   -  5      :  a  O  O[        RD                  " S[F        SS9  UR.                  S	   S:  d  T R*                  S:X  a  [I        U
5      S:  a  SU-   $ g! [        [        4 a=  n	[        U	5      R!                  S5      (       a  e [        T 4S["        0UD6m  Sn	A	GNSn	A	ff = f! , (       d  f       GN= f! [(         a     GNvf = f)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                  N   > T(       a  T(       a  TOSn [        SU  ST< 35      eg)zTDepending on the value of raise_unknown, either raise an error or return
'unknown'.
rl   zUnknown label type for z: unknown)r>   )inputr    raise_unknownr   s    r   _raise_or_return(type_of_target.<locals>._raise_or_return3  s-     ",J&E6ugRuEFFr   r   z:Expected array-like (array or non-string sequence), got %r)SparseSeriesSparseArrayz1y cannot be class 'SparseSeries' or 'SparseArray'r(   TFr   rW   r]   rP   Nr^   zkSupport for labels represented as bytes is not supported. Convert the labels to a string or integer format.zYou 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	   r   r	   r&   r   z-multioutput rN   rt   
continuous   g      ?zThe number of unique classes is greater than 50% of the number of samples. `y` could represent a regression problem, not a classification problem.)
stacklevelr'   )%r   r:   r   r   r   r;   r>   	__class____name__rr   rc   rd   re   rf   r   r   rg   rh   bytes	TypeError
IndexErrorri   minr#   rP   flatrO   rl   anyrS   intr   r   roundwarnUserWarningr=   )r   r    r{   r   r   r|   validsparse_pandasro   rp   first_row_or_valsuffixrl   classess   ```           r   r-   r-      s   Z "/q!1B 
Ax	 	JHQK	J71k3J 	#1c""  
  

 H1L
 	
 KK((,KKMLMMQ% N 
	 	 	"g'@A{{C@@@	 
#(01aS!V91&..<  (+66+X66/55;  	vvV!!qww<<66Q;!!A;;177f,Zq	35O5O!! 	vv{qwwqzA~ 
zz!''?++!!qvv!66$))D#..//t
;&((  !!+00AGwwqzB1771:a(8R5qwwqzAQ;RR& 	
 }}Q!!4D0E0If$$] .z: Cq6$$%ABB  BB>BC 
#	"D  sC   ',PN7+BP 7P2O?9P?PP
P
P'&P'c                    [        U SS5      c  Uc  [        S5      eUbm  [        U SS5      bN  [        R                  " U R                  [        U5      5      (       d  [        SU< SU R                  < 35      e g[        U5      U l        gg)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   rL   )clfr   s     r   _check_partial_fit_first_callr     s     sJ%-'/STT		3
D)5>>#,,g0FGG 18#,,H  H  )1CL r   c                 0   / n/ n/ nU R                   u  pVUb  [        R                  " U5      n[        U 5      (       Ga  U R	                  5       n [        R
                  " U R                  5      n[        U5       GH  nU R                  U R                  U   U R                  US-       n	Ub2  X   n
[        R                  " U5      [        R                  " U
5      -
  nOSn
U R                   S   Xx   -
  n[        R                  " U R                  U R                  U   U R                  US-       SS9u  p[        R                  " XS9nSU;   a  XS:H  ==   U-  ss'   SU;  aE  Xx   U R                   S   :  a0  [        R                  " USS5      n[        R                  " USU5      nUR                  U5        UR                  UR                   S   5        UR                  XR                  5       -  5        GM     O[        U5       H  n[        R                  " U SS2U4   SS9u  pUR                  U5        UR                  UR                   S   5        [        R                  " XS9nUR                  XR                  5       -  5        M     X#U4$ )a>  Compute 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	   r   T)return_inverse)weights)r#   r   r   r   tocscdiffindptrrangeindicessumuniquerl   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     s1   , GIK77I 

=1{{GGI!y!A))AHHQK!((1q5/BK(!.!;(*}(=~@V(V%!%()
UX(=%YYqxx{QXXa!e_5dNI KKDM I~1n-1FF- 	!eh&;IIiA6	 "		-<Q RNN9%Y__Q/0}/@/@/BBC9 "< y!AYYqAwtDNINN9%Y__Q/0KKCM}/@/@/BBC " ,,r   c                    U R                   S   n[        R                  " X245      n[        R                  " X245      nSn[        U5       H~  n[        US-   U5       Hh  nUSS2U4==   USS2U4   -  ss'   USS2U4==   USS2U4   -  ss'   X@SS2U4   S:H  U4==   S-  ss'   X@SS2U4   S:H  U4==   S-  ss'   US-  nMj     M     US[        R                  " U5      S-   -  -  n	XI-   $ )aE  Compute 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``.
r   r	   Nrb   )r#   r   zerosr   abs)
predictionsconfidencesr   r   votessum_of_confidencesr   r6   jtransformed_confidencess
             r   _ovr_decision_functionr     s   & !!!$IHHi+,E9"89	A9q1ui(Aq!t$AqD(99$q!t$AqD(99$ad#q(!+,1,ad#q(!+,1,FA )  1	RVV&'!+, **r   r,   )r   F)__doc__rd   collections.abcr   	itertoolsr   numpyr   scipy.sparser   utils._array_apir   utils.fixesr   _uniquer
   r   
validationr   r   r   r%   r@   rL   rU   rr   rv   r-   r   r   r   r5   r   r   <module>r      ss    G
  $   ! , 3 1 7 !$- N)bE
P
6JZ FG-T*+r   