§
    rŠtj³  ã                   óp   — d Z ddlmZ ddlZddlmc mZ ddl	m
Z
mZ ddlmZmZmZ ddlmZ d
d„Zdd	„ZdS )z
Common code for all metrics.

é    )ÚcombinationsN)Úcheck_arrayÚcheck_consistent_length)Ú_averageÚ_ravelÚget_namespace_and_device)Útype_of_targetc           
      óü  — t          ||¦  «        \  }}}d}||vr"t          d                     |¦  «        ¦  «        ‚t          |¦  «        }	|	dvr"t          d                     |	¦  «        ¦  «        ‚|	dk    r | |||¬¦  «        S t	          |||¦  «         t          |¦  «        }t          |¦  «        }d}
|}d}|d	k    rB|�!|                     ||j        d         ¦  «        }t          |¦  «        }t          |¦  «        }nÍ|d
k    r»|�\| 	                    ||j
        ¬¦  «        }|                     |                     ||                     |d¦  «        ¦  «        d¬¦  «        }n|                     |d¬¦  «        }t          j        |                     |¦  «        | 	                    d|j
        |¬¦  «        ¦  «        rdS n|dk    r|}d}d}
|j        dk    r|                     |d¦  «        }|j        dk    r|                     |d¦  «        }|j        |
         }|                     |f|¬¦  «        }t%          |¦  «        D ]‰}t          |                     || 	                    |g|¬¦  «        |
¬¦  «        ¦  «        }t          |                     || 	                    |g|¬¦  «        |
¬¦  «        ¦  «        } | |||¬¦  «        ||<   ŒŠ|�*|�	d||dk    <   t)          t+          |||¬¦  «        ¦  «        S |S )a�  Average a binary metric for multilabel classification.

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

    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 or non-thresholded decision values (as returned by
        :term:`decision_function` on some classifiers).

    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.

    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   )Údtype)éÿÿÿÿr   r   )Úaxis)r   Údevicer   )r   )ÚweightsÚxp)r   Ú
ValueErrorÚformatr	   r   r   ÚrepeatÚshaper   Úasarrayr   ÚsumÚmultiplyÚreshapeÚxpxÚiscloseÚndimÚzerosÚrangeÚtakeÚfloatr   )Úbinary_metricÚy_trueÚy_scoreÚaverager   r   Ú_Ú_deviceÚaverage_optionsÚy_typeÚnot_average_axisÚscore_weightÚaverage_weightÚ	n_classesÚscoreÚcÚy_true_cÚ	y_score_cs                     úS/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sklearn/metrics/_base.pyÚ_average_binary_scorer8      sH  € õX .¨g°}ÑEÔE�N€Bˆˆ7ØE€OØ�oÐ%Ð%ÝÐ7×>Ò>¸ÑOÔOÑPÔPÐPå˜FÑ#Ô#€FØÐ7Ð7Ð7ÝÐ6×=Ò=¸fÑEÔEÑFÔFÐFà�ÒÐØˆ}˜V W¸MÐJÑJÔJÐJå˜F G¨]Ñ;Ô;Ð;Ý˜Ñ Ô €FÝ˜'Ñ"Ô"€GàÐØ €LØ€Nà�'ÒÐØÐ#ØŸ9š9 \°6´<À´?ÑCÔCˆLÝ˜‘”ˆÝ˜‘/”/ˆˆà	�JÒ	Ð	ØÐ#à—Z’Z ¨lÔ.@�ZÑAÔAˆFØŸVšVØ—’˜F B§J¢J¨|¸WÑ$EÔ$EÑFÔFÈQð $ñ ô ˆNˆNð  ŸVšV F°˜VÑ3Ô3ˆNÝŒ;Ø�FŠF�>Ñ"Ô"Ø�JŠJ�q Ô 4¸WˆJÑEÔEñ
ô 
ð 	ð �1ð		ð 
�IÒ	Ð	à%ˆØˆØÐà„{�aÒÐØ—’˜F GÑ,Ô,ˆà„|�qÒÐØ—*’*˜W gÑ.Ô.ˆà”Ð.Ô/€IØ�HŠH�i�\¨'ˆHÑ2Ô2€EÝ�9ÑÔð Rð RˆÝØ�GŠG�F˜BŸJšJ¨ s°7˜JÑ;Ô;ÐBRˆGÑSÔSñ
ô 
ˆõ Ø�GŠG�G˜RŸZšZ¨¨°G˜ZÑ<Ô<ÐCSˆGÑTÔTñ
ô 
ˆ	ð !�= ¨9ÀLÐQÑQÔQˆˆa‰ˆð ÐØÐ%ð *+ˆE�. AÒ%Ñ&Ý•X˜e¨^ÀÐCÑCÔCÑDÔDÐDàˆó    r   c                 óP  — t          ||¦  «         t          j        |¦  «        }|j        d         }||dz
  z  dz  }t          j        |¦  «        }|dk    }|rt          j        |¦  «        nd}	t          t          |d¦  «        ¦  «        D ]…\  }
\  }}||k    }||k    }t          j        ||¦  «        }|rt          j        |¦  «        |	|
<   ||         }||         } | ||||f         ¦  «        } | ||||f         ¦  «        }||z   dz  ||
<   Œ†t          j        ||	¬¦  «        S )aL  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   N)r   )	r   ÚnpÚuniquer   ÚemptyÚ	enumerater   Ú
logical_orr*   )r'   r(   r)   r*   Úy_true_uniquer2   Ú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                       r7   Ú_average_multiclass_ovo_scorerP   Ž   sO  € õP ˜F GÑ,Ô,Ð,å”I˜fÑ%Ô%€MØÔ# AÔ&€IØ˜9 q™=Ñ)¨QÑ.€GÝ”(˜7Ñ#Ô#€Kà˜ZÒ'€KØ&1Ð;•”˜'Ñ"Ô"Ð"°t€Jõ  ¥¨]¸AÑ >Ô >Ñ?Ô?ð <ð <‰
ˆ‰FˆQ�Ø˜1’ˆØ˜1’ˆÝ”- ¨Ñ/Ô/ˆàð 	1ÝœZ¨Ñ0Ô0ˆJ�r‰Nà˜”ˆØ˜”ˆà$�} V¨W°W¸a°ZÔ-@ÑAÔAˆØ$�} V¨W°W¸a°ZÔ-@ÑAÔAˆØ'¨,Ñ6¸!Ñ;ˆ�B‰ˆåŒ:�k¨:Ð6Ñ6Ô6Ð6r9   )N)r   )Ú__doc__Ú	itertoolsr   Únumpyr<   Ú!sklearn.externals.array_api_extraÚ	externalsÚarray_api_extrar    Úsklearn.utilsr   r   Úsklearn.utils._array_apir   r   r   Úsklearn.utils.multiclassr	   r8   rP   © r9   r7   ú<module>r[      så   ððð ð #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð à /Ð /Ð /Ð /Ð /Ð /Ð /Ð /Ð /Ø >Ð >Ð >Ð >Ð >Ð >Ð >Ð >ðð ð ð ð ð ð ð ð ð ð
 4Ð 3Ð 3Ð 3Ð 3Ð 3ðtð tð tð tðnC7ð C7ð C7ð C7ð C7ð C7r9   