ó
    ¨ñ:iœ  ã                   ó¼  • S r SSKrSSKrSSKrSSKJr  SSKrSSKr	SSK
JrJr  SSKJr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Jr  \" S/S/SS/\\R8                  S/S\" 1 Sk5      /S/SS/S.SS9SSSSSS.S j5       r\" S/S/SS/\\R8                  S/S\" 1 Sk5      /SS/S.SS9SSSSS.S j5       r\" S/S/SS/\\R8                  S/S\" 1 Sk5      /SS/S.SS9SSSSS.S j5       r\" S/S/SS/\\R8                  S/S\" 1 Sk5      /SS/\" \R@                  SSSS9/S.SS9SSSSSS.S  j5       r!\" \R@                  /S!/S".SS9S#SS".S$ j5       r"\" S/S/SS/SS/SS/\" \R8                  SSSS9/\R@                  /S!/\" S%15      \" \R8                  SSS&S9/S'.	SS9SSSS	S#S(S%S).S* j5       r#\" S/S/SS/S+.SS9SS,.S- j5       r$g).ab  Metrics to assess performance on a classification task given class
predictions. The available metrics are complementary from the metrics available
in scikit-learn.

Functions named as ``*_score`` return a scalar value to maximize: the higher
the better

Function named as ``*_error`` or ``*_loss`` return a scalar value to minimize:
the lower the better
é    N)Ú	signature)Úmean_absolute_errorÚprecision_recall_fscore_support)Ú_check_targetsÚ_prf_divide)ÚLabelEncoder)Úunique_labels)Úcheck_consistent_lengthÚcolumn_or_1dé   )ÚIntervalÚ
StrOptionsÚvalidate_paramsz
array-like>   ÚmacroÚmicroÚbinaryÚsamplesÚweighted)Úy_trueÚy_predÚlabelsÚ	pos_labelÚaverageÚwarn_forÚsample_weightT)Úprefer_skip_nested_validationé   )ÚsensitivityÚspecificity©r   r   r   r   r   c          	      óÀ  • SnXG;  a  US:w  a  [        S[        U5      -   5      e[        X5      u  p€n[        X5      n	US:X  a@  US:X  a,  X9;  a#  [	        U	5      S:  a  g[        SU< SU	< 35      eU/nO8[        SU-  5      eUS	;  a$  [
        R                  " S
U< SU< S3[        5        Uc  U	nSn
O6[	        U5      n
[        R                  " U[        R                  " X’SS9/5      nUR                  S5      (       a  [        S5      eUS:X  a  [        S5      e[        5       nUR                  U5        UR                  U 5      n UR                  U5      nUR                  nX:H  nX   nUb  [        R                   " U5      U   nOSn[	        U5      (       a  [        R"                  " Xï[	        U5      S9nO#[        R$                  " [	        U5      5      =n=nn[	        U5      (       a  [        R"                  " X[	        U5      S9n[	        U 5      (       a  [        R"                  " X[	        U5      S9nU R&                  WW-   U-
  -
  n[        R(                  " XÂSU
 5      nUU   nUU   nUU   nUU   nUS:X  a”  [        R*                  " UR-                  5       /5      n[        R*                  " UR-                  5       /5      n[        R*                  " UR-                  5       /5      n[        R*                  " UR-                  5       /5      n[        R.                  " SSS9   [1        UUU-   U-
  SSUU5      n[1        UUSSXE5      nSSS5        US:X  a  UnUR-                  5       S:X  a  gOUS:X  a  UnOSnUbC  US:w  d  [	        W5      S:X  d   e[        R2                  " WUS 9n[        R2                  " WUS 9nSnWWU4$ ! , (       d  f       N‚= f)!a1  Compute sensitivity, specificity, and support for each class.

The sensitivity is the ratio ``tp / (tp + fn)`` where ``tp`` is the number
of true positives and ``fn`` the number of false negatives. The sensitivity
quantifies the ability to avoid false negatives_[1].

The specificity is the ratio ``tn / (tn + fp)`` where ``tn`` is the number
of true negatives and ``fn`` the number of false negatives. The specificity
quantifies the ability to avoid false positives_[1].

The support is the number of occurrences of each class in ``y_true``.

If ``pos_label is None`` and in binary classification, this function
returns the average sensitivity and specificity if ``average``
is one of ``'weighted'``.

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

Parameters
----------
y_true : array-like of shape (n_samples,)
    Ground truth (correct) target values.

y_pred : array-like of shape (n_samples,)
    Estimated targets as returned by a classifier.

labels : array-like, default=None
    The set of labels to include when ``average != 'binary'``, and their
    order if ``average is None``. Labels present in the data can be
    excluded, for example to calculate a multiclass average ignoring a
    majority negative class, while labels not present in the data will
    result in 0 components in a macro average. For multilabel targets,
    labels are column indices. By default, all labels in ``y_true`` and
    ``y_pred`` are used in sorted order.

pos_label : str, int or None, default=1
    The class to report if ``average='binary'`` and the data is binary.
    If ``pos_label is None`` and in binary classification, this function
    returns the average sensitivity and specificity if ``average``
    is one of ``'weighted'``.
    If the data are multiclass, this will be ignored;
    setting ``labels=[pos_label]`` and ``average != 'binary'`` will report
    scores for that label only.

average : str, default=None
    If ``None``, the scores for each class are returned. Otherwise, this
    determines the type of averaging performed on the data:

    ``'binary'``:
        Only report results for the class specified by ``pos_label``.
        This is applicable only if targets (``y_{true,pred}``) are binary.
    ``'micro'``:
        Calculate metrics globally by counting the total true positives,
        false negatives and false positives.
    ``'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). This
        alters 'macro' to account for label imbalance; it can result in an
        F-score that is not between precision and recall.
    ``'samples'``:
        Calculate metrics for each instance, and find their average (only
        meaningful for multilabel classification where this differs from
        :func:`accuracy_score`).

warn_for : tuple or set of {{"sensitivity", "specificity"}}, for internal use
    This determines which warnings will be made in the case that this
    function is being used to return only one of its metrics.

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

Returns
-------
sensitivity : float (if `average is None`) or ndarray of             shape (n_unique_labels,)
    The sensitivity metric.

specificity : float (if `average is None`) or ndarray of             shape (n_unique_labels,)
    The specificity metric.

support : int (if `average is None`) or ndarray of             shape (n_unique_labels,)
    The number of occurrences of each label in ``y_true``.

References
----------
.. [1] `Wikipedia entry for the Sensitivity and specificity
       <https://en.wikipedia.org/wiki/Sensitivity_and_specificity>`_

Examples
--------
>>> import numpy as np
>>> from imblearn.metrics import sensitivity_specificity_support
>>> y_true = np.array(['cat', 'dog', 'pig', 'cat', 'dog', 'pig'])
>>> y_pred = np.array(['cat', 'pig', 'dog', 'cat', 'cat', 'dog'])
>>> sensitivity_specificity_support(y_true, y_pred, average='macro')
(0.33..., 0.66..., None)
>>> sensitivity_specificity_support(y_true, y_pred, average='micro')
(0.33..., 0.66..., None)
>>> sensitivity_specificity_support(y_true, y_pred, average='weighted')
(0.33..., 0.66..., None)
)Nr   r   r   r   r   zaverage has to be one of r   )ç        r"   r   z
pos_label=z is not a valid label: zITarget is %s but average='binary'. Please choose another average setting.)Nr   zNote that pos_label (set to z+) is ignored when average != 'binary' (got zE). You may use labels=[pos_label] to specify a single positive class.NT©Úassume_uniqueÚ
multilabelz$imblearn does not support multilabelr   z{Sample-based precision, recall, fscore is not meaningful outside multilabel classification. See the accuracy_score instead.©ÚweightsÚ	minlengthr   Úignore©ÚdivideÚinvalidr   Ú	predictedr   Útruer   r   )r   r   Nr   ©r'   )Ú
ValueErrorÚstrr   r	   ÚlenÚwarningsÚwarnÚUserWarningÚnpÚhstackÚ	setdiff1dÚ
startswithr   ÚfitÚ	transformÚclasses_ÚasarrayÚbincountÚzerosÚsizeÚsearchsortedÚarrayÚsumÚerrstater   r   )r   r   r   r   r   r   r   Úaverage_optionsÚy_typeÚpresent_labelsÚn_labelsÚleÚsorted_labelsÚtpÚtp_binsÚtp_bins_weightsÚtp_sumÚtrue_sumÚpred_sumÚtn_sumÚindicesr   r   r'   s                           Úc/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/imblearn/metrics/_classification.pyÚsensitivity_specificity_supportrT   !   sÄ  € ðF F€OØÓ%¨'°XÓ*=ÜÐ4´s¸?Ó7KÑKÓLÐLä+¨FÓ;Ñ€F�FÜ" 6Ó2€Nà�(ÓØ�XÓØÓ.Ü�~Ó&¨Ó*à(å$ã$¢nð6óð ð  �[‰Fäð2Ø4:ñ;óð ð 
˜)Ó	#Ü�‹ó ›'ð#ô ô	
ð �~ØˆØ‰ä�v“;ˆÜ—’Ø”R—\’\ .ÈÑMÐNó
ˆð ×Ñ˜×&Ñ&ÜÐ?Ó@Ð@Ø	�IÓ	Üð>ó
ð 	
ô ‹^ˆØ
�‰ˆvŒØ—‘˜fÓ%ˆØ—‘˜fÓ%ˆØŸ™ˆð ÑˆØ‘*ˆØÑ$Ü Ÿjšj¨Ó7¸Ñ;‰Oà"ˆOäˆw�<‰<Ü—[’[Ø¼CÀ»Kñ‰Fô
 ,.¯8ª8´C¸³KÓ+@Ð@ˆHÐ@�x &Üˆv�;‰;Ü—{’{ 6ÌCÐPVËKÑXˆHÜˆv�;‰;Ü—{’{ 6ÌCÐPVËKÑXˆHð —‘ ¨8Ñ 3°fÑ <Ñ=ˆô —/’/ -¸	¸Ð1BÓCˆØ˜‘ˆØ˜GÑ$ˆØ˜GÑ$ˆØ˜‘ˆà�'ÓÜ—’˜6Ÿ:™:›<˜.Ó)ˆÜ—8’8˜XŸ\™\›^Ð,Ó-ˆÜ—8’8˜XŸ\™\›^Ð,Ó-ˆÜ—’˜6Ÿ:™:›<˜.Ó)ˆô 
�Š˜H¨hÓ	7ô
 "ØØ�XÑ Ñ&ØØØØó
ˆô "Ø�H˜m¨V°Wó
ˆ÷ 
8ð& �*ÓØˆØ�;‰;‹=˜AÓØð à	�IÓ	Ø‰àˆàÑØ˜(Ó"¤c¨+Ó&6¸!Ó&;Ð;Ð;Ü—j’j °gÑ>ˆÜ—j’j °gÑ>ˆØˆà˜ XÐ-Ð-÷E 
8Õ	7ús   Ì-&OÏ
O)r   r   r   r   r   r   r   )r   r   r   r   c          
      ó,   • [        U UUUUSUS9u  n  nU$ )a  Compute the sensitivity.

The sensitivity is the ratio ``tp / (tp + fn)`` where ``tp`` is the number
of true positives and ``fn`` the number of false negatives. The sensitivity
quantifies the ability to avoid false negatives.

The best value is 1 and the worst value is 0.

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

Parameters
----------
y_true : array-like of shape (n_samples,)
    Ground truth (correct) target values.

y_pred : array-like of shape (n_samples,)
    Estimated targets as returned by a classifier.

labels : array-like, default=None
    The set of labels to include when ``average != 'binary'``, and their
    order if ``average is None``. Labels present in the data can be
    excluded, for example to calculate a multiclass average ignoring a
    majority negative class, while labels not present in the data will
    result in 0 components in a macro average.

pos_label : str, int or None, default=1
    The class to report if ``average='binary'`` and the data is binary.
    If ``pos_label is None`` and in binary classification, this function
    returns the average sensitivity if ``average`` is one of ``'weighted'``.
    If the data are multiclass, this will be ignored;
    setting ``labels=[pos_label]`` and ``average != 'binary'`` will report
    scores for that label only.

average : str, default=None
    If ``None``, the scores for each class are returned. Otherwise, this
    determines the type of averaging performed on the data:

    ``'binary'``:
        Only report results for the class specified by ``pos_label``.
        This is applicable only if targets (``y_{true,pred}``) are binary.
    ``'micro'``:
        Calculate metrics globally by counting the total true positives,
        false negatives and false positives.
    ``'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). This
        alters 'macro' to account for label imbalance; it can result in an
        F-score that is not between precision and recall.
    ``'samples'``:
        Calculate metrics for each instance, and find their average (only
        meaningful for multilabel classification where this differs from
        :func:`accuracy_score`).

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

Returns
-------
specificity : float (if `average is None`) or ndarray of             shape (n_unique_labels,)
    The specifcity metric.

Examples
--------
>>> import numpy as np
>>> from imblearn.metrics import sensitivity_score
>>> y_true = [0, 1, 2, 0, 1, 2]
>>> y_pred = [0, 2, 1, 0, 0, 1]
>>> sensitivity_score(y_true, y_pred, average='macro')
0.33...
>>> sensitivity_score(y_true, y_pred, average='micro')
0.33...
>>> sensitivity_score(y_true, y_pred, average='weighted')
0.33...
>>> sensitivity_score(y_true, y_pred, average=None)
array([1., 0., 0.])
)r   r    ©rT   )r   r   r   r   r   r   ÚsÚ_s           rS   Úsensitivity_scorerY   *  s1   € ôN .ØØØØØØ!Ø#ñ�G€A€qˆ!ð €Hó    c          
      ó*   • [        U UUUUSUS9u  pgnU$ )a  Compute the specificity.

The specificity is the ratio ``tn / (tn + fp)`` where ``tn`` is the number
of true negatives and ``fp`` the number of false positives. The specificity
quantifies the ability to avoid false positives.

The best value is 1 and the worst value is 0.

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

Parameters
----------
y_true : array-like of shape (n_samples,)
    Ground truth (correct) target values.

y_pred : array-like of shape (n_samples,)
    Estimated targets as returned by a classifier.

labels : array-like, default=None
    The set of labels to include when ``average != 'binary'``, and their
    order if ``average is None``. Labels present in the data can be
    excluded, for example to calculate a multiclass average ignoring a
    majority negative class, while labels not present in the data will
    result in 0 components in a macro average.

pos_label : str, int or None, default=1
    The class to report if ``average='binary'`` and the data is binary.
    If ``pos_label is None`` and in binary classification, this function
    returns the average specificity if ``average`` is one of ``'weighted'``.
    If the data are multiclass, this will be ignored;
    setting ``labels=[pos_label]`` and ``average != 'binary'`` will report
    scores for that label only.

average : str, default=None
    If ``None``, the scores for each class are returned. Otherwise, this
    determines the type of averaging performed on the data:

    ``'binary'``:
        Only report results for the class specified by ``pos_label``.
        This is applicable only if targets (``y_{true,pred}``) are binary.
    ``'micro'``:
        Calculate metrics globally by counting the total true positives,
        false negatives and false positives.
    ``'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). This
        alters 'macro' to account for label imbalance; it can result in an
        F-score that is not between precision and recall.
    ``'samples'``:
        Calculate metrics for each instance, and find their average (only
        meaningful for multilabel classification where this differs from
        :func:`accuracy_score`).

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

Returns
-------
specificity : float (if `average is None`) or ndarray of             shape (n_unique_labels,)
    The specificity metric.

Examples
--------
>>> import numpy as np
>>> from imblearn.metrics import specificity_score
>>> y_true = [0, 1, 2, 0, 1, 2]
>>> y_pred = [0, 2, 1, 0, 0, 1]
>>> specificity_score(y_true, y_pred, average='macro')
0.66...
>>> specificity_score(y_true, y_pred, average='micro')
0.66...
>>> specificity_score(y_true, y_pred, average='weighted')
0.66...
>>> specificity_score(y_true, y_pred, average=None)
array([0.75, 0.5 , 0.75])
)r   r    rV   )r   r   r   r   r   r   rX   rW   s           rS   Úspecificity_scorer\   ž  s/   € ôN .ØØØØØØ!Ø#ñ�G€Aˆ!ð €HrZ   >   r   r   r   r   r   Ú
multiclassÚleft)Úclosed)r   r   r   r   r   r   Ú
correctionr]   r"   )r   r   r   r   r`   c          
      ó´  • Ub  US:w  a*  [        U UUUUSUS9u  pxn	[        R                  " Xx-  5      $ [        X5      n
Uc  U
nSnO6[	        U5      n[        R
                  " U[        R                  " X¢SS9/5      n[        5       nUR                  U5        UR                  U 5      n UR                  U5      nUR                  nX:H  nX   nUb  [        R                  " U5      U   nOSn[	        U5      (       a   [        R                  " UU[	        U5      S9nO![        R                  " [	        U5      5      =nn[	        U 5      (       a  [        R                  " X[	        U5      S9n[        R                  " XÒSU 5      nUU   nWU   n[        R                  " SSS	9   [!        UUS
SSS
5      nSSS5        UWUS:H  '   [        R                  " SSS	9   ["        R$                  R'                  U5      nSSS5        [)        W[        R*                  R,                  R.                  5      (       a  gU$ ! , (       d  f       N‰= f! , (       d  f       NU= f)u"  Compute the geometric mean.

The geometric mean (G-mean) is the root of the product of class-wise
sensitivity. This measure tries to maximize the accuracy on each of the
classes while keeping these accuracies balanced. For binary classification
G-mean is the squared root of the product of the sensitivity
and specificity. For multi-class problems it is a higher root of the
product of sensitivity for each class.

For compatibility with other imbalance performance measures, G-mean can be
calculated for each class separately on a one-vs-rest basis when
``average != 'multiclass'``.

The best value is 1 and the worst value is 0. Traditionally if at least one
class is unrecognized by the classifier, G-mean resolves to zero. To
alleviate this property, for highly multi-class the sensitivity of
unrecognized classes can be "corrected" to be a user specified value
(instead of zero). This option works only if ``average == 'multiclass'``.

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

Parameters
----------
y_true : array-like of shape (n_samples,)
    Ground truth (correct) target values.

y_pred : array-like of shape (n_samples,)
    Estimated targets as returned by a classifier.

labels : array-like, default=None
    The set of labels to include when ``average != 'binary'``, and their
    order if ``average is None``. Labels present in the data can be
    excluded, for example to calculate a multiclass average ignoring a
    majority negative class, while labels not present in the data will
    result in 0 components in a macro average.

pos_label : str, int or None, default=1
    The class to report if ``average='binary'`` and the data is binary.
    If ``pos_label is None`` and in binary classification, this function
    returns the average geometric mean if ``average`` is one of
    ``'weighted'``.
    If the data are multiclass, this will be ignored;
    setting ``labels=[pos_label]`` and ``average != 'binary'`` will report
    scores for that label only.

average : str or None, default='multiclass'
    If ``None``, the scores for each class are returned. Otherwise, this
    determines the type of averaging performed on the data:

    ``'binary'``:
        Only report results for the class specified by ``pos_label``.
        This is applicable only if targets (``y_{true,pred}``) are binary.
    ``'micro'``:
        Calculate metrics globally by counting the total true positives,
        false negatives and false positives.
    ``'macro'``:
        Calculate metrics for each label, and find their unweighted
        mean.  This does not take label imbalance into account.
    ``'multiclass'``:
        No average is taken.
    ``'weighted'``:
        Calculate metrics for each label, and find their average, weighted
        by support (the number of true instances for each label). This
        alters 'macro' to account for label imbalance; it can result in an
        F-score that is not between precision and recall.
    ``'samples'``:
        Calculate metrics for each instance, and find their average (only
        meaningful for multilabel classification where this differs from
        :func:`accuracy_score`).

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

correction : float, default=0.0
    Substitutes sensitivity of unrecognized classes from zero to a given
    value.

Returns
-------
geometric_mean : float
    Returns the geometric mean.

Notes
-----
See :ref:`sphx_glr_auto_examples_evaluation_plot_metrics.py`.

References
----------
.. [1] Kubat, M. and Matwin, S. "Addressing the curse of
   imbalanced training sets: one-sided selection" ICML (1997)

.. [2] Barandela, R., SÃ¡nchez, J. S., GarcÄ±a, V., & Rangel, E. "Strategies
   for learning in class imbalance problems", Pattern Recognition,
   36(3), (2003), pp 849-851.

Examples
--------
>>> from imblearn.metrics import geometric_mean_score
>>> y_true = [0, 1, 2, 0, 1, 2]
>>> y_pred = [0, 2, 1, 0, 0, 1]
>>> geometric_mean_score(y_true, y_pred)
0.0
>>> geometric_mean_score(y_true, y_pred, correction=0.001)
0.010...
>>> geometric_mean_score(y_true, y_pred, average='macro')
0.471...
>>> geometric_mean_score(y_true, y_pred, average='micro')
0.471...
>>> geometric_mean_score(y_true, y_pred, average='weighted')
0.471...
>>> geometric_mean_score(y_true, y_pred, average=None)
array([0.866...,  0.       ,  0.       ])
Nr]   )r   r   r    Tr#   r&   r)   r*   Úrecallr.   r   r"   )rT   r6   Úsqrtr	   r2   r7   r8   r   r:   r;   r<   r=   r>   r?   rA   rD   r   ÚspÚstatsÚgmeanÚ
isinstanceÚmaÚcoreÚMaskedConstant)r   r   r   r   r   r   r`   ÚsenÚsperX   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rR   rb   rf   s                         rS   Úgeometric_mean_scorerm     s  € ðX �˜' \Ó1Ü5ØØØØØØ3Ø'ñ
‰ˆ�!ô �wŠw�s‘yÓ!Ð!ä& vÓ6ˆà‰>Ø#ˆFØ‰Hä˜6“{ˆHÜ—Y’YØœŸš nÈDÑQÐRóˆFô ‹^ˆØ
�‰ˆvŒØ—‘˜fÓ%ˆØ—‘˜fÓ%ˆØŸ™ˆð ÑˆØ‘*ˆàÑ$Ü Ÿjšj¨Ó7¸Ñ;‰Oà"ˆOäˆw�<‰<Ü—[’[Ø ¼CÀ»Kñ‰Fô
 !#§¢¬¨V«Ó 5Ð5ˆH�vÜˆv�;‰;Ü—{’{ 6ÌCÐPVËKÑXˆHô —/’/ -¸	¸Ð1BÓCˆØ˜‘ˆØ˜GÑ$ˆä�[Š[ °(Ó;Ü  ¨°8¸VÀTÈ8ÓTˆF÷ <à(ˆˆv˜‰{Ñä�[Š[ °(Ó;Ü—H‘H—N‘N 6Ó*ˆE÷ <ô �eœRŸU™UŸZ™Z×6Ñ6×7Ñ7ØØˆ÷ <Õ;ú÷ <Õ;ús   Æ$H8Ç I	È8
IÉ	
IÚboolean©ÚalphaÚsquaredgš™™™™™¹?c                 ó   ^ ^• U U4S jnU$ )u¬  Balance any scoring function using the index balanced accuracy.

This factory function wraps scoring function to express it as the
index balanced accuracy (IBA). You need to use this function to
decorate any scoring function.

Only metrics requiring ``y_pred`` can be corrected with the index
balanced accuracy. ``y_score`` cannot be used since the dominance
cannot be computed.

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

Parameters
----------
alpha : float, default=0.1
    Weighting factor.

squared : bool, default=True
    If ``squared`` is True, then the metric computed will be squared
    before to be weighted.

Returns
-------
iba_scoring_func : callable,
    Returns the scoring metric decorated which will automatically compute
    the index balanced accuracy.

Notes
-----
See :ref:`sphx_glr_auto_examples_evaluation_plot_metrics.py`.

References
----------
.. [1] GarcÃ­a, Vicente, Javier Salvador SÃ¡nchez, and RamÃ³n Alberto
   Mollineda. "On the effectiveness of preprocessing methods when dealing
   with different levels of class imbalance." Knowledge-Based Systems 25.1
   (2012): 13-21.

Examples
--------
>>> from imblearn.metrics import geometric_mean_score as gmean
>>> from imblearn.metrics import make_index_balanced_accuracy as iba
>>> gmean = iba(alpha=0.1, squared=True)(gmean)
>>> y_true = [1, 0, 0, 1, 0, 1]
>>> y_pred = [0, 0, 1, 1, 0, 1]
>>> print(gmean(y_true, y_pred, average=None))
[0.44...  0.44...]
c                 óL   >^ • [         R                  " T 5      UU U4S j5       nU$ )Nc                  ón  >• [        T5      n[        UR                  R                  5       5      n[        / SQ5      nUR	                  U5      (       a  [        STR                   S35      eUR                  " U 0 UD6nUR                  5         T" UR                  0 UR                  D6nT(       a  [        R                  " US5      n[        [        5      n[        UR                  R                  5       5      nUR	                  [        UR                  R                  5       5      5      n	U	 V
s0 s H  oªUR                  U
   _M     nn
TR                  S:X  a  SU;   a  US   S:X  a  SUS'   O%TR                  S	:X  d  TR                  S
:X  a  SUS'   [        S0 UD6u  pÍnXÍ-
  nSTU-  -   U-  $ s  sn
f )N)Úy_scoreÚy_probÚy2zThe function zh has an unsupported attribute. Metric with`y_pred` are the only supported metrics is the only supported.r   rm   r   r]   r   Úaccuracy_scoreÚjaccard_scorer   g      ð?© )r   ÚsetÚ
parametersÚkeysÚintersectionÚAttributeErrorÚ__name__ÚbindÚapply_defaultsÚargsÚkwargsr6   ÚpowerrT   Ú	arguments)rƒ   r„   Úsignature_scoring_funcÚparams_scoring_funcÚprohibitied_y_predÚargs_scoring_funcÚ_scoreÚsignature_sens_specÚparams_sens_specÚcommon_paramsÚkÚargs_sens_specr   r   rX   Ú	dominancerp   Úscoring_funcrq   s                   €€€rS   Úcompute_scoreÚEmake_index_balanced_accuracy.<locals>.decorate.<locals>.compute_score  sÌ  ø€ ä%.¨|Ó%<Ð"Ü"%Ð&<×&GÑ&G×&LÑ&LÓ&NÓ"OÐô "%Ò%@Ó!AÐØ!×.Ñ.Ð/B×CÑCÜ$Ø# L×$9Ñ$9Ð#:ð ;"ð #óð ð !7× ;Ò ;¸TÐ LÀVÑ LÐØ×,Ñ,Ô.Ù!Ð#4×#9Ñ#9ÐVÐ=N×=UÑ=UÑVˆFÞÜŸš &¨!Ó,�ä"+Ô,KÓ"LÐÜ"Ð#6×#AÑ#A×#FÑ#FÓ#HÓIÐØ,×9Ñ9ÜÐ%×/Ñ/×4Ñ4Ó6Ó7óˆMñ JWÓWÊÀAÐ!2×!<Ñ!<¸QÑ!?Ò?ÉˆNÐWà×$Ñ$Ð(>Ó>Ø Ó.Ø% iÑ0°LÓ@Ø4;˜ yÑ1øà×%Ñ%Ð)9Ó9Ø×(Ñ(¨OÓ;ð -5�˜yÑ)ä*Iñ +Ø ñ+Ñ'ˆK að $Ñ1ˆIØ˜% )Ñ+Ñ+¨vÑ5Ð5ùò' Xs   Ä0F2)Ú	functoolsÚwraps)r’   r“   rp   rq   s   ` €€rS   ÚdecorateÚ.make_index_balanced_accuracy.<locals>.decorate  s'   ù€ Ü	�Š˜Ó	&ö.	6ó 
'ð.	6ð` ÐrZ   rz   )rp   rq   r—   s   `` rS   Úmake_index_balanced_accuracyr™   à  s   ù€ öl2ðh €OrZ   r4   Úboth)	r   r   r   Útarget_namesr   Údigitsrp   Úoutput_dictÚzero_divisionF)r   r›   r   rœ   rp   r�   rž   c                óV  • Uc  [        X5      nO[        R                  " U5      nSn	Uc  U V
s/ s H  oª PM     nn
[        S U 5       5      n[        U[	        U	5      U5      n/ SQnSU-  nUS-  nUSR                  U Vs/ s H  nSPM     sn5      -  nUS	-  nS
/U-   nU[        U5      -  nUS	-  n[        U UUSUUS9u  nnnn[        U UUSUS9n[        U UUSUS9n[        USS9" [        5      nU" U UUSUS9n0 n[        U5       Hˆ  u  nn
0 nUU   /n[        USS UU   UU   UU   UU   UU   UU   /5       H!  u  nnUSR                  UU5      /-  nUUU'   M#     UUU    /-  nUU   UUS   '   UU[        U5      -  -  nUUUU   '   MŠ     US	-  nU	/n[        USS [        R                  " UUS9[        R                  " UUS9[        R                  " UUS9[        R                  " UUS9[        R                  " UUS9[        R                  " UUS9/5       H$  u  nnUSR                  UU5      /-  nUUSU 3'   M&     U[        R                  " U5       /-  nUU[        U5      -  -  n[        R                  " U5      US'   U(       a  U$ U$ s  sn
f s  snf )at
  Build a classification report based on metrics used with imbalanced dataset.

Specific metrics have been proposed to evaluate the classification
performed on imbalanced dataset. This report compiles the
state-of-the-art metrics: precision/recall/specificity, geometric
mean, and index balanced accuracy of the
geometric mean.

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

Parameters
----------
y_true : 1d array-like, or label indicator array / sparse matrix
    Ground truth (correct) target values.

y_pred : 1d array-like, or label indicator array / sparse matrix
    Estimated targets as returned by a classifier.

labels : array-like of shape (n_labels,), default=None
    Optional list of label indices to include in the report.

target_names : list of str of shape (n_labels,), default=None
    Optional display names matching the labels (same order).

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

digits : int, default=2
    Number of digits for formatting output floating point values.
    When ``output_dict`` is ``True``, this will be ignored and the
    returned values will not be rounded.

alpha : float, default=0.1
    Weighting factor.

output_dict : bool, default=False
    If True, return output as dict.

    .. versionadded:: 0.8

zero_division : "warn" or {0, 1}, default="warn"
    Sets the value to return when there is a zero division. If set to
    "warn", this acts as 0, but warnings are also raised.

    .. versionadded:: 0.8

Returns
-------
report : string / dict
    Text summary of the precision, recall, specificity, geometric mean,
    and index balanced accuracy.
    Dictionary returned if output_dict is True. Dictionary has the
    following structure::

        {'label 1': {'pre':0.5,
                     'rec':1.0,
                     ...
                    },
         'label 2': { ... },
          ...
        }

Examples
--------
>>> import numpy as np
>>> from imblearn.metrics import classification_report_imbalanced
>>> y_true = [0, 1, 2, 2, 2]
>>> y_pred = [0, 0, 2, 2, 1]
>>> target_names = ['class 0', 'class 1', 'class 2']
>>> print(classification_report_imbalanced(y_true, y_pred,     target_names=target_names))
                   pre       rec       spe        f1       geo       iba       sup
<BLANKLINE>
    class 0       0.50      1.00      0.75      0.67      0.87      0.77         1
    class 1       0.00      0.00      0.75      0.00      0.00      0.00         1
    class 2       1.00      0.67      1.00      0.80      0.82      0.64         3
<BLANKLINE>
avg / total       0.70      0.60      0.90      0.61      0.66      0.54         5
<BLANKLINE>
Nzavg / totalc              3   ó8   #   • U  H  n[        U5      v •  M     g 7f)N)r2   )Ú.0Úcns     rS   Ú	<genexpr>Ú3classification_report_imbalanced.<locals>.<genexpr>É  s   é € Ð4¢| ”S˜—W�W¢|ùs   ‚)ÚpreÚrecrl   Úf1ÚgeoÚibaÚsupz%% %dsz  Ú z% 9sÚ
Ú )r   r   r   rž   )r   r   r   Tro   r   éÿÿÿÿz
{0:0.{1}f}r/   Úavg_Útotal_support)r	   r6   r=   Úmaxr2   ÚjoinÚtupler   r\   rm   r™   Ú	enumerateÚzipÚformatr   rC   )r   r   r   r›   r   rœ   rp   r�   rž   Úlast_line_headingÚlabelÚ
name_widthÚwidthÚheadersÚfmtrX   ÚreportÚ	precisionrb   r§   Úsupportr   Úgeo_meanÚ	iba_gmeanr©   Úreport_dictÚiÚreport_dict_labelÚvaluesÚ
score_nameÚscore_values                                  rS   Ú classification_report_imbalancedrÈ   M  sT  € ðf �~Ü˜vÓ.‰ä—’˜FÓ#ˆà%ÐàÑÙ06Ó7² u˜'š
±ˆÐ7ÜÑ4¡|Ó4Ó4€JÜ�
œCÐ 1Ó2°FÓ;€Eâ>€GØ
�UÑ
€CØˆ4�K€CØˆ3�8‰8¡WÓ-¢W “V¡WÑ-Ó.Ñ.€CØˆ4�K€Càˆd�W‰n€GØ”5˜“>Ñ!€FØ
ˆd�N€Fô &EØØØØØ#Ø#ñ&Ñ"€Iˆv�r˜7ô $ØØØØØ#ñ€Kô $ØØØØØ#ñ€Hô -°5À$ÒGÜó€Iñ ØØØØØ#ñ€Cð €KÜ˜fÖ%‰ˆˆ5ØÐØ˜q‘/Ð"ˆÜ'*Ø�A�bˆMà˜!‘Ø�q‘	Ø˜A‘Ø�1‘Ø˜‘Ø�A‘ðö
(
Ñ#ˆJ˜ð �|×*Ñ*¨;¸Ó?Ð@Ñ@ˆFØ,7Ð˜jÓ)ñ
(
ð 	�g˜a‘j�\Ð#Ñ#ˆØ)0°©Ð˜' "™+Ñ&Ø�#œ˜f›Ñ%Ñ%ˆà'8ˆ�L ‘OÓ$ñ) &ð, ˆd�N€Fð  Ð €FÜ#&Ø��"ˆä�JŠJ�y¨'Ñ2Ü�JŠJ�v wÑ/Ü�JŠJ�{¨GÑ4Ü�JŠJ�r 7Ñ+Ü�JŠJ�x¨Ñ1Ü�JŠJ�s GÑ,ð	
ö
$Ñˆ
�Kð 	�<×&Ñ& {°FÓ;Ð<Ñ<ˆØ+6ˆ�d˜:˜,Ð'Ó(ñ
$ð ”"—&’&˜“/Ð"Ð$Ñ$€FØ
ˆc”E˜&“MÑ!Ñ!€FÜ#%§6¢6¨'£?€K�Ñ æØÐØ€MùòE 8ùò .s   ¯J!ÂJ&
)r   r   r   ©r   c          	      ót  • [        X5      u  p0nUb  [        U5      nO [        R                  " U R                  5      n[        XU5        [        X5      n/ nU H;  n[        R                  " X:H  5      nUR                  [        X   X   X'   S95        M=     [        R                  " U5      [        U5      -  $ )aç  Compute Macro-Averaged MAE for imbalanced ordinal classification.

This function computes each MAE for each class and average them,
giving an equal weight to each class.

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

.. versionadded:: 0.8

Parameters
----------
y_true : array-like of shape (n_samples,) or (n_samples, n_outputs)
    Ground truth (correct) target values.

y_pred : array-like of shape (n_samples,) or (n_samples, n_outputs)
    Estimated targets as returned by a classifier.

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

Returns
-------
loss : float or ndarray of floats
    Macro-Averaged MAE output is non-negative floating point.
    The best value is 0.0.

Examples
--------
>>> import numpy as np
>>> from sklearn.metrics import mean_absolute_error
>>> from imblearn.metrics import macro_averaged_mean_absolute_error
>>> y_true_balanced = [1, 1, 2, 2]
>>> y_true_imbalanced = [1, 2, 2, 2]
>>> y_pred = [1, 2, 1, 2]
>>> mean_absolute_error(y_true_balanced, y_pred)
0.5
>>> mean_absolute_error(y_true_imbalanced, y_pred)
0.25
>>> macro_averaged_mean_absolute_error(y_true_balanced, y_pred)
0.5
>>> macro_averaged_mean_absolute_error(y_true_imbalanced, y_pred)
0.16...
rÉ   )r   r   r6   ÚonesÚshaper
   r	   ÚflatnonzeroÚappendr   rC   r2   )r   r   r   rX   r   ÚmaeÚpossible_classrR   s           rS   Ú"macro_averaged_mean_absolute_errorrÑ   -  s§   € ôh ' vÓ6Ñ€AˆvØÑ Ü$ ]Ó3‰äŸš §¡Ó-ˆÜ˜F¨MÔ:Ü˜6Ó*€FØ
€CÛ ˆÜ—.’. Ñ!9Ó:ˆà�
‰
ÜØ‘Ø‘Ø+Ñ4ñö	
ñ !ô �6Š6�#‹;œ˜S›Ñ!Ð!rZ   )%Ú__doc__r•   Únumbersr3   Úinspectr   Únumpyr6   Úscipyrd   Úsklearn.metricsr   r   Úsklearn.metrics._classificationr   r   Úsklearn.preprocessingr   Úsklearn.utils.multiclassr	   Úsklearn.utils.validationr
   r   Úutils._param_validationr   r   r   r1   ÚIntegralrT   rY   r\   ÚRealrm   r™   rÈ   rÑ   rz   rZ   rS   Ú<module>rß      s2  ðñ	ó Û Û Ý ã Û ß Pß GÝ .Ý 2ß Jç KÑ Kñ à�.Ø�.Ø Ð&Ø˜7×+Ñ+¨TÐ2àÙÒJÓKð
ð "�NØ&¨Ð-ñð #'ñð& ØØØ+Øôw.óðw.ñt à�.Ø�.Ø Ð&Ø˜7×+Ñ+¨TÐ2àÙÒJÓKð
ð '¨Ð-ñ
ð #'ñð$ ØØØôcóðcñL à�.Ø�.Ø Ð&Ø˜7×+Ñ+¨TÐ2àÙÒJÓKð
ð '¨Ð-ñ
ð #'ñð$ ØØØôcóðcñL à�.Ø�.Ø Ð&Ø˜7×+Ñ+¨TÐ2àÙÚQóð
ð '¨Ð-Ù §¡¨a°¸fÑEÐFñð #'ñð* ØØØØôzó#ð"zñz Ø�|‰|ˆn¨)¨Ñ5Ø"&ñð +.°tô fó	ðfñR à�.Ø�.Ø Ð&Ø% tÐ,Ø&¨Ð-Ù˜G×,Ñ,¨a°¸fÑEÐFØ—,‘,�Ø!�{á˜�xÓ Ù�W×%Ñ% q¨!°FÑ;ð
ñð #'ñð* ØØØØ
ØØôLó#ð"Lñ^ à�.Ø�.Ø&¨Ð-ñð
 #'ñð IMô ?"óñ?"rZ   