ó
    Ñ]jW  ã                   óL   • S r SSKJr  SSKrSSKJrJr  SSKJ	r	  SS jr
S	S jrg)
z
Common code for all metrics.

é    )ÚcombinationsN)Úcheck_arrayÚcheck_consistent_length)Útype_of_targetc           	      óÐ  • SnX5;  a  [        SR                  U5      5      e[        U5      nUS;  a  [        SR                  U5      5      eUS:X  a  U " XUS9$ [        XU5        [	        U5      n[	        U5      nSnUnSn	US	:X  aG  Ub#  [
        R                  " X�R                  S   5      nUR                  5       nUR                  5       nO–US
:X  a„  Ub@  [
        R                  " [
        R                  " U[
        R                  " US5      5      SS9n	O[
        R                  " USS9n	[
        R                  " U	R                  5       S5      (       a  gOUS:X  a  Un	SnSnUR                  S:X  a  UR                  S5      nUR                  S:X  a  UR                  S5      nUR                  U   n
[
        R                  " U
45      n[        U
5       HJ  nUR!                  U/US9R                  5       nUR!                  U/US9R                  5       nU " XÞUS9X¼'   ML     Ub=  U	b  [
        R"                  " U	5      n	SX¹S:H  '   [%        [
        R&                  " X¹S95      $ U$ )aÍ  Average a binary metric for multilabel classification.

Parameters
----------
y_true : array, shape = [n_samples] or [n_samples, n_classes]
    True binary labels in binary label indicators.

y_score : array, shape = [n_samples] or [n_samples, n_classes]
    Target scores, can either be probability estimates of the positive
    class, confidence values, or binary decisions.

average : {None, 'micro', 'macro', 'samples', 'weighted'}, default='macro'
    If ``None``, the scores for each class are returned. Otherwise,
    this determines the type of averaging performed on the data:

    ``'micro'``:
        Calculate metrics globally by considering each element of the label
        indicator matrix as a label.
    ``'macro'``:
        Calculate metrics for each label, and find their unweighted
        mean.  This does not take label imbalance into account.
    ``'weighted'``:
        Calculate metrics for each label, and find their average, weighted
        by support (the number of true instances for each label).
    ``'samples'``:
        Calculate metrics for each instance, and find their average.

    Will be ignored when ``y_true`` is binary.

sample_weight : array-like of shape (n_samples,), default=None
    Sample weights.

binary_metric : callable, returns shape [n_classes]
    The binary metric function to use.

Returns
-------
score : float or array of shape [n_classes]
    If not ``None``, average the score, else return the score for each
    classes.

)NÚmicroÚmacroÚweightedÚsampleszaverage has to be one of {0})Úbinaryzmultilabel-indicatorz{0} format is not supportedr   )Úsample_weighté   Nr   r
   )éÿÿÿÿr   r   )Úaxisg        r   ©Úweights)Ú
ValueErrorÚformatr   r   r   ÚnpÚrepeatÚshapeÚravelÚsumÚmultiplyÚreshapeÚiscloseÚndimÚzerosÚrangeÚtakeÚasarrayÚfloatÚaverage)Úbinary_metricÚy_trueÚy_scorer#   r   Úaverage_optionsÚy_typeÚnot_average_axisÚscore_weightÚaverage_weightÚ	n_classesÚscoreÚcÚy_true_cÚ	y_score_cs                  ÚR/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sklearn/metrics/_base.pyÚ_average_binary_scorer2      sD  € ðV F€OØÓ%ÜÐ7×>Ñ>¸ÓOÓPÐPä˜FÓ#€FØÐ7Ó7ÜÐ6×=Ñ=¸fÓEÓFÐFà�ÓÙ˜V¸MÑJÐJä˜F¨]Ô;Ü˜Ó €FÜ˜'Ó"€GàÐØ €LØ€Nà�'ÓØÑ#ÜŸ9š9 \·<±<À±?ÓCˆLØ—‘“ˆØ—-‘-“/‰à	�JÓ	ØÑ#ÜŸVšVÜ—’˜F¤B§J¢J¨|¸WÓ$EÓFÈQñ‰Nô  ŸVšV F°Ñ3ˆNÜ�:Š:�n×(Ñ(Ó*¨C×0Ñ0Øð 1ð 
�IÓ	à%ˆØˆØÐà‡{�{�aÓØ—‘ Ó(ˆà‡|�|�qÓØ—/‘/ 'Ó*ˆà—‘Ð.Ñ/€IÜ�HŠH�i�\Ó"€EÜ�9ÖˆØ—;‘; ˜sÐ)9�;Ð:×@Ñ@ÓBˆØ—L‘L ! Ð+;�LÐ<×BÑBÓDˆ	Ù  ÀLÑQˆ‹ñ ð ÑØÑ%ô  ŸZšZ¨Ó7ˆNØ)*ˆE AÑ%Ñ&Ü”R—Z’Z Ñ>Ó?Ð?àˆó    c                 ó&  • [        X5        [        R                  " U5      nUR                  S   nXUS-
  -  S-  n[        R                  " U5      nUS:H  nU(       a  [        R                  " U5      OSn	[        [        US5      5       Hq  u  n
u  p¼X:H  nX:H  n[        R                  " XÞ5      nU(       a  [        R                  " U5      Xš'   Xß   nXï   nU " UX/U4   5      nU " UX/U4   5      nUU-   S-  Xz'   Ms     [        R                  " XyS9$ )aÌ  Average one-versus-one scores for multiclass classification.

Uses the binary metric for one-vs-one multiclass classification,
where the score is computed according to the Hand & Till (2001) algorithm.

Parameters
----------
binary_metric : callable
    The binary metric function to use that accepts the following as input:
        y_true_target : array, shape = [n_samples_target]
            Some sub-array of y_true for a pair of classes designated
            positive and negative in the one-vs-one scheme.
        y_score_target : array, shape = [n_samples_target]
            Scores corresponding to the probability estimates
            of a sample belonging to the designated positive class label

y_true : array-like of shape (n_samples,)
    True multiclass labels.

y_score : array-like of shape (n_samples, n_classes)
    Target scores corresponding to probability estimates of a sample
    belonging to a particular class.

average : {'macro', 'weighted'}, default='macro'
    Determines the type of averaging performed on the pairwise binary
    metric scores:
    ``'macro'``:
        Calculate metrics for each label, and find their unweighted
        mean. This does not take label imbalance into account. Classes
        are assumed to be uniformly distributed.
    ``'weighted'``:
        Calculate metrics for each label, taking into account the
        prevalence of the classes.

Returns
-------
score : float
    Average of the pairwise binary metric scores.
r   r   é   r
   Nr   )	r   r   Úuniquer   ÚemptyÚ	enumerater   Ú
logical_orr#   )r$   r%   r&   r#   Úy_true_uniquer,   Ún_pairsÚpair_scoresÚis_weightedÚ
prevalenceÚixÚaÚbÚa_maskÚb_maskÚab_maskÚa_trueÚb_trueÚa_true_scoreÚb_true_scores                       r1   Ú_average_multiclass_ovo_scorerI   ~   s
  € ôP ˜FÔ,ä—I’I˜fÓ%€MØ×#Ñ# AÑ&€IØ q™=Ñ)¨QÑ.€GÜ—(’(˜7Ó#€Kà˜ZÑ'€KÞ&1”—’˜'Ô"°t€Jô  ¤¨]¸AÓ >Ö?‰
ˆ‰FˆQØ‘ˆØ‘ˆÜ—-’- Ó/ˆæÜŸZšZ¨Ó0ˆJ‰Nà‘ˆØ‘ˆá$ V¨W¸a°ZÑ-@ÓAˆÙ$ V¨W¸a°ZÑ-@ÓAˆØ'¨,Ñ6¸!Ñ;ˆ‹ñ @ô �:Š:�kÑ6Ð6r3   )N)r	   )Ú__doc__Ú	itertoolsr   Únumpyr   Úsklearn.utilsr   r   Úsklearn.utils.multiclassr   r2   rI   © r3   r1   Ú<module>rP      s%   ðñõ #ã ç >Ý 3ôjõZC7r3   