Ë
    C�Dj*ý  ã                   óD  — d Z ddlZddlmZ ddlZddlmZ ddlm	Z	 ddl
mZmZmZmZmZ ddlmZmZmZmZ dd	lmZ dd
lmZmZmZmZmZ g d¢Zd=d„Z edgdgddg eddh«      dgdœd¬«      dddœd„«       Z edgdgddg eeddd¬«      g eddh«      dgdœd¬«      ddddœd„«       Z  edgdgddg eddh«      dgdœd¬«      dddœd„«       Z! edgdgddg eddh«      dg e edh«      «      dgdœd¬«      dddd œd!„«       Z" edgdgddg eddh«      dgdœd¬«      dddœd"„«       Z# edgdgddg eddh«      dg e edh«      «      dgdœd¬«      dddd œd#„«       Z$ edgdgddg eddh«      dgdœd¬«      dddœd$„«       Z% edgdg eddh«      dgddgd%œd¬«      ddd&œd'„«       Z&d(„ Z' edgdgddg eh d)£«      dgdgd*œd¬«      dddd+œd,„«       Z( edgdgddg eh d)£«      ddgdgd*œd¬«      dddd+œd-„«       Z) edgdgd.œd¬«      d/„ «       Z*d0„ Z+ edgdgddg eeddd1¬«       eeddd2¬«      gd3œd¬«      ddd4œd5„«       Z, edgdgddgd6œd¬«      dd7œd8„«       Z- edgdgddgd6œd¬«      dd7œd9„«       Z. edgdgddg eeddd1¬«       eeddd2¬«      gd3œd¬«      ddd4œd:„«       Z/ edgdgddg eeddd¬«      g eddh«      dgdœd¬«      ddddœd;„«       Z0 edgdgddg eddh«      dgdœd¬«      dddœd<„«       Z1y)>zòMetrics to assess performance on regression task.

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)ÚReal)Úxlogyé   )ÚUndefinedMetricWarning)Ú_averageÚ_find_matching_floating_dtypeÚget_namespaceÚget_namespace_and_deviceÚsize)ÚHiddenÚIntervalÚ
StrOptionsÚvalidate_params)Ú_weighted_percentile)Ú_check_sample_weightÚ_num_samplesÚcheck_arrayÚcheck_consistent_lengthÚcolumn_or_1d)Ú	max_errorÚmean_absolute_errorÚmean_squared_errorÚmean_squared_log_errorÚmedian_absolute_errorÚmean_absolute_percentage_errorÚmean_pinball_lossÚr2_scoreÚroot_mean_squared_log_errorÚroot_mean_squared_errorÚexplained_variance_scoreÚmean_tweedie_devianceÚmean_poisson_devianceÚmean_gamma_devianceÚd2_tweedie_scoreÚd2_pinball_scoreÚd2_absolute_error_scorec                 óÌ  — t        | |||¬«      \  }}t        | |«       t        | d|¬«      } t        |d|¬«      }| j                  dk(  r|j	                  | d«      } |j                  dk(  r|j	                  |d«      }| j
                  d   |j
                  d   k7  r5t        dj                  | j
                  d   |j
                  d   «      «      ‚| j
                  d   }d}t        |t        «      r||vrat        dj                  ||«      «      ‚|�Dt        |d¬	«      }|dk(  rt        d
«      ‚|t        |«      k7  rt        dt        |«      |fz  «      ‚|dk(  rdnd}|| ||fS )aF  Check that y_true and y_pred belong to the same regression task.

    Parameters
    ----------
    y_true : array-like

    y_pred : array-like

    multioutput : array-like or string in ['raw_values', uniform_average',
        'variance_weighted'] or None
        None is accepted due to backward compatibility of r2_score().

    dtype : str or list, default="numeric"
        the dtype argument passed to check_array.

    Returns
    -------
    type_true : one of {'continuous', continuous-multioutput'}
        The type of the true target data, as output by
        'utils.multiclass.type_of_target'.

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

    y_pred : array-like of shape (n_samples, n_outputs)
        Estimated target values.

    multioutput : array-like of shape (n_outputs) or string in ['raw_values',
        uniform_average', 'variance_weighted'] or None
        Custom output weights if ``multioutput`` is array-like or
        just the corresponding argument if ``multioutput`` is a
        correct keyword.
    ©ÚxpF)Ú	ensure_2dÚdtypeé   )éÿÿÿÿr,   z<y_true and y_pred have different number of output ({0}!={1}))Ú
raw_valuesÚuniform_averageÚvariance_weightedzIAllowed 'multioutput' string values are {}. You provided multioutput={!r})r*   z5Custom weights are useful only in multi-output cases.z?There must be equally many custom weights (%d) as outputs (%d).Ú
continuousúcontinuous-multioutput)r	   r   r   ÚndimÚreshapeÚshapeÚ
ValueErrorÚformatÚ
isinstanceÚstrÚlen)	Úy_trueÚy_predÚmultioutputr+   r)   Ú_Ú	n_outputsÚallowed_multioutput_strÚy_types	            ú_C:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\sklearn/metrics/_regression.pyÚ_check_reg_targetsrC   K   s}  € ôD ˜& &¨+¸"Ô=�E€Bˆä˜F FÔ+Ü˜¨5¸Ô>€FÜ˜¨5¸Ô>€Fà‡{�{�aÒØ—‘˜F GÓ,ˆà‡{�{�aÒØ—‘˜F GÓ,ˆà‡|�|�A�˜&Ÿ,™, q™/Ò)ÜØJ×QÑQØ—‘˜Q‘ §¡¨a¡óó
ð 	
ð —‘˜Q‘€IØTÐÜ�+œsÔ#ØÐ5Ñ5Üð0ß06±Ø+¨[ó1óð ð 
Ð	 Ü! +¸Ô?ˆØ˜Š>ÜÐTÓUÐUØœ#˜kÓ*Ò*ÜØQÜ�{Ó# YÐ/ñ0óð ð '¨!š^‰\Ð1I€Fà�6˜6 ;Ð.Ð.ó    z
array-liker.   r/   ©r;   r<   Úsample_weightr=   T)Úprefer_skip_nested_validation©rF   r=   c                ó  — t        | ||«      \  }} }}t        | ||«       t        j                  t        j                  || z
  «      |d¬«      }t        |t        «      r|dk(  r|S |dk(  rd}t        j                  ||¬«      S )a*  Mean absolute error regression loss.

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

    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 target values.

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

    multioutput : {'raw_values', 'uniform_average'}  or array-like of shape             (n_outputs,), default='uniform_average'
        Defines aggregating of multiple output values.
        Array-like value defines weights used to average errors.

        'raw_values' :
            Returns a full set of errors in case of multioutput input.

        'uniform_average' :
            Errors of all outputs are averaged with uniform weight.

    Returns
    -------
    loss : float or ndarray of floats
        If multioutput is 'raw_values', then mean absolute error is returned
        for each output separately.
        If multioutput is 'uniform_average' or an ndarray of weights, then the
        weighted average of all output errors is returned.

        MAE output is non-negative floating point. The best value is 0.0.

    Examples
    --------
    >>> from sklearn.metrics import mean_absolute_error
    >>> y_true = [3, -0.5, 2, 7]
    >>> y_pred = [2.5, 0.0, 2, 8]
    >>> mean_absolute_error(y_true, y_pred)
    np.float64(0.5)
    >>> y_true = [[0.5, 1], [-1, 1], [7, -6]]
    >>> y_pred = [[0, 2], [-1, 2], [8, -5]]
    >>> mean_absolute_error(y_true, y_pred)
    np.float64(0.75)
    >>> mean_absolute_error(y_true, y_pred, multioutput='raw_values')
    array([0.5, 1. ])
    >>> mean_absolute_error(y_true, y_pred, multioutput=[0.3, 0.7])
    np.float64(0.85...)
    r   ©ÚweightsÚaxisr.   r/   N©rK   )rC   r   ÚnpÚaverageÚabsr8   r9   )r;   r<   rF   r=   rA   Úoutput_errorss         rB   r   r   ˜   s„   € ô@ +=Ø�˜ó+Ñ'€FˆF�F˜Kô ˜F F¨MÔ:Ü—J‘JœrŸv™v f¨v¡oÓ6ÀÐTUÔV€MÜ�+œsÔ#Ø˜,Ò&Ø Ð ØÐ-Ò-àˆKä�:‰:�m¨[Ô9Ð9rD   r,   Úboth)Úclosed)r;   r<   rF   Úalphar=   ç      à?©rF   rT   r=   c                ón  — t        | ||«      \  }} }}t        | ||«       | |z
  }|dk\  j                  |j                  «      }||z  |z  d|z
  d|z
  z  |z  z
  }t	        j
                  ||d¬«      }	t        |t        «      r|dk(  r|	S t        |t        «      r|dk(  rd}t	        j
                  |	|¬«      S )a"  Pinball loss for quantile regression.

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

    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 target values.

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

    alpha : float, slope of the pinball loss, default=0.5,
        This loss is equivalent to :ref:`mean_absolute_error` when `alpha=0.5`,
        `alpha=0.95` is minimized by estimators of the 95th percentile.

    multioutput : {'raw_values', 'uniform_average'}  or array-like of shape             (n_outputs,), default='uniform_average'
        Defines aggregating of multiple output values.
        Array-like value defines weights used to average errors.

        'raw_values' :
            Returns a full set of errors in case of multioutput input.

        'uniform_average' :
            Errors of all outputs are averaged with uniform weight.

    Returns
    -------
    loss : float or ndarray of floats
        If multioutput is 'raw_values', then mean absolute error is returned
        for each output separately.
        If multioutput is 'uniform_average' or an ndarray of weights, then the
        weighted average of all output errors is returned.

        The pinball loss output is a non-negative floating point. The best
        value is 0.0.

    Examples
    --------
    >>> from sklearn.metrics import mean_pinball_loss
    >>> y_true = [1, 2, 3]
    >>> mean_pinball_loss(y_true, [0, 2, 3], alpha=0.1)
    np.float64(0.03...)
    >>> mean_pinball_loss(y_true, [1, 2, 4], alpha=0.1)
    np.float64(0.3...)
    >>> mean_pinball_loss(y_true, [0, 2, 3], alpha=0.9)
    np.float64(0.3...)
    >>> mean_pinball_loss(y_true, [1, 2, 4], alpha=0.9)
    np.float64(0.03...)
    >>> mean_pinball_loss(y_true, y_true, alpha=0.1)
    np.float64(0.0)
    >>> mean_pinball_loss(y_true, y_true, alpha=0.9)
    np.float64(0.0)
    r   r,   rJ   r.   r/   NrM   )rC   r   Úastyper+   rN   rO   r8   r9   )
r;   r<   rF   rT   r=   rA   ÚdiffÚsignÚlossrQ   s
             rB   r   r   ç   sÄ   € ôN +=Ø�˜ó+Ñ'€FˆF�F˜Kô ˜F F¨MÔ:Ø�F‰?€DØ�A‰I×Ñ˜dŸj™jÓ)€DØ�4‰<˜$Ñ ! e¡)°°D±Ñ!9¸DÑ!@Ñ@€DÜ—J‘J˜t¨]ÀÔC€Mä�+œsÔ#¨°|Ò(CØÐä�+œsÔ#¨Ð7HÒ(Hàˆä�:‰:�m¨[Ô9Ð9rD   c                ó¸  — t        | ||«      \  }} }}t        | ||«       t        j                  t        j                  «      j
                  }t        j                  || z
  «      t        j                  t        j                  | «      |«      z  }t        j                  ||d¬«      }t        |t        «      r|dk(  r|S |dk(  rd}t        j                  ||¬«      S )a˜
  Mean absolute percentage error (MAPE) regression loss.

    Note here that the output is not a percentage in the range [0, 100]
    and a value of 100 does not mean 100% but 1e2. Furthermore, the output
    can be arbitrarily high when `y_true` is small (which is specific to the
    metric) or when `abs(y_true - y_pred)` is large (which is common for most
    regression metrics). Read more in the
    :ref:`User Guide <mean_absolute_percentage_error>`.

    .. versionadded:: 0.24

    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 target values.

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

    multioutput : {'raw_values', 'uniform_average'} or array-like
        Defines aggregating of multiple output values.
        Array-like value defines weights used to average errors.
        If input is list then the shape must be (n_outputs,).

        'raw_values' :
            Returns a full set of errors in case of multioutput input.

        'uniform_average' :
            Errors of all outputs are averaged with uniform weight.

    Returns
    -------
    loss : float or ndarray of floats
        If multioutput is 'raw_values', then mean absolute percentage error
        is returned for each output separately.
        If multioutput is 'uniform_average' or an ndarray of weights, then the
        weighted average of all output errors is returned.

        MAPE output is non-negative floating point. The best value is 0.0.
        But note that bad predictions can lead to arbitrarily large
        MAPE values, especially if some `y_true` values are very close to zero.
        Note that we return a large value instead of `inf` when `y_true` is zero.

    Examples
    --------
    >>> from sklearn.metrics import mean_absolute_percentage_error
    >>> y_true = [3, -0.5, 2, 7]
    >>> y_pred = [2.5, 0.0, 2, 8]
    >>> mean_absolute_percentage_error(y_true, y_pred)
    np.float64(0.3273...)
    >>> y_true = [[0.5, 1], [-1, 1], [7, -6]]
    >>> y_pred = [[0, 2], [-1, 2], [8, -5]]
    >>> mean_absolute_percentage_error(y_true, y_pred)
    np.float64(0.5515...)
    >>> mean_absolute_percentage_error(y_true, y_pred, multioutput=[0.3, 0.7])
    np.float64(0.6198...)
    >>> # the value when some element of the y_true is zero is arbitrarily high because
    >>> # of the division by epsilon
    >>> y_true = [1., 0., 2.4, 7.]
    >>> y_pred = [1.2, 0.1, 2.4, 8.]
    >>> mean_absolute_percentage_error(y_true, y_pred)
    np.float64(112589990684262.48)
    r   rJ   r.   r/   NrM   )rC   r   rN   ÚfinfoÚfloat64ÚepsrP   ÚmaximumrO   r8   r9   )r;   r<   rF   r=   rA   ÚepsilonÚmaperQ   s           rB   r   r   A  s¸   € ô\ +=Ø�˜ó+Ñ'€FˆF�F˜Kô ˜F F¨MÔ:Ü�h‰h”r—z‘zÓ"×&Ñ&€GÜ�6‰6�&˜6‘/Ó"¤R§Z¡Z´·±°v³ÀÓ%HÑH€DÜ—J‘J˜t¨]ÀÔC€MÜ�+œsÔ#Ø˜,Ò&Ø Ð ØÐ-Ò-àˆKä�:‰:�m¨[Ô9Ð9rD   Ú
deprecatedÚboolean)r;   r<   rF   r=   Úsquared)rF   r=   re   c                óF  — |dk7  r+t        j                  dt        «       |st        | |||¬«      S t	        | ||«      \  }} }}t        | ||«       t        j                  | |z
  dz  d|¬«      }t        |t        «      r|dk(  r|S |dk(  rd	}t        j                  ||¬
«      S )aÂ  Mean squared error regression loss.

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

    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 target values.

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

    multioutput : {'raw_values', 'uniform_average'} or array-like of shape             (n_outputs,), default='uniform_average'
        Defines aggregating of multiple output values.
        Array-like value defines weights used to average errors.

        'raw_values' :
            Returns a full set of errors in case of multioutput input.

        'uniform_average' :
            Errors of all outputs are averaged with uniform weight.

    squared : bool, default=True
        If True returns MSE value, if False returns RMSE value.

        .. deprecated:: 1.4
           `squared` is deprecated in 1.4 and will be removed in 1.6.
           Use :func:`~sklearn.metrics.root_mean_squared_error`
           instead to calculate the root mean squared error.

    Returns
    -------
    loss : float or ndarray of floats
        A non-negative floating point value (the best value is 0.0), or an
        array of floating point values, one for each individual target.

    Examples
    --------
    >>> from sklearn.metrics import mean_squared_error
    >>> y_true = [3, -0.5, 2, 7]
    >>> y_pred = [2.5, 0.0, 2, 8]
    >>> mean_squared_error(y_true, y_pred)
    np.float64(0.375)
    >>> y_true = [[0.5, 1],[-1, 1],[7, -6]]
    >>> y_pred = [[0, 2],[-1, 2],[8, -5]]
    >>> mean_squared_error(y_true, y_pred)
    np.float64(0.708...)
    >>> mean_squared_error(y_true, y_pred, multioutput='raw_values')
    array([0.41666667, 1.        ])
    >>> mean_squared_error(y_true, y_pred, multioutput=[0.3, 0.7])
    np.float64(0.825...)
    rc   z—'squared' is deprecated in version 1.4 and will be removed in 1.6. To calculate the root mean squared error, use the function'root_mean_squared_error'.rH   r   r   )rL   rK   r.   r/   NrM   )
ÚwarningsÚwarnÚFutureWarningr   rC   r   rN   rO   r8   r9   )r;   r<   rF   r=   re   rA   rQ   s          rB   r   r      sº   € ðV �,ÒÜ�‰ð-ô
 ô	
ñ Ü*Ø˜¨mÈôð ô +=Ø�˜ó+Ñ'€FˆF�F˜Kô ˜F F¨MÔ:Ü—J‘J ¨¡°AÑ5¸AÀ}ÔU€Mä�+œsÔ#Ø˜,Ò&Ø Ð ØÐ-Ò-àˆKä�:‰:�m¨[Ô9Ð9rD   c                ó°   — t        j                  t        | ||d¬«      «      }t        |t        «      r|dk(  r|S |dk(  rd}t        j
                  ||¬«      S )aí  Root mean squared error regression loss.

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

    .. versionadded:: 1.4

    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 target values.

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

    multioutput : {'raw_values', 'uniform_average'} or array-like of shape             (n_outputs,), default='uniform_average'
        Defines aggregating of multiple output values.
        Array-like value defines weights used to average errors.

        'raw_values' :
            Returns a full set of errors in case of multioutput input.

        'uniform_average' :
            Errors of all outputs are averaged with uniform weight.

    Returns
    -------
    loss : float or ndarray of floats
        A non-negative floating point value (the best value is 0.0), or an
        array of floating point values, one for each individual target.

    Examples
    --------
    >>> from sklearn.metrics import root_mean_squared_error
    >>> y_true = [3, -0.5, 2, 7]
    >>> y_pred = [2.5, 0.0, 2, 8]
    >>> root_mean_squared_error(y_true, y_pred)
    np.float64(0.612...)
    >>> y_true = [[0.5, 1],[-1, 1],[7, -6]]
    >>> y_pred = [[0, 2],[-1, 2],[8, -5]]
    >>> root_mean_squared_error(y_true, y_pred)
    np.float64(0.822...)
    r.   rH   r/   NrM   )rN   Úsqrtr   r8   r9   rO   )r;   r<   rF   r=   rQ   s        rB   r   r   
  s]   € ôt —G‘GÜØ�F¨-À\ô	
ó€Mô �+œsÔ#Ø˜,Ò&Ø Ð ØÐ-Ò-àˆKä�:‰:�m¨[Ô9Ð9rD   c                ól  — |dk7  r+t        j                  dt        «       |st        | |||¬«      S t	        | ||«      \  }} }}t        | ||«       | dk  j                  «       s|dk  j                  «       rt        d«      ‚t        t        j                  | «      t        j                  |«      ||¬«      S )aS  Mean squared logarithmic error regression loss.

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

    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 target values.

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

    multioutput : {'raw_values', 'uniform_average'} or array-like of shape             (n_outputs,), default='uniform_average'

        Defines aggregating of multiple output values.
        Array-like value defines weights used to average errors.

        'raw_values' :
            Returns a full set of errors when the input is of multioutput
            format.

        'uniform_average' :
            Errors of all outputs are averaged with uniform weight.

    squared : bool, default=True
        If True returns MSLE (mean squared log error) value.
        If False returns RMSLE (root mean squared log error) value.

        .. deprecated:: 1.4
           `squared` is deprecated in 1.4 and will be removed in 1.6.
           Use :func:`~sklearn.metrics.root_mean_squared_log_error`
           instead to calculate the root mean squared logarithmic error.

    Returns
    -------
    loss : float or ndarray of floats
        A non-negative floating point value (the best value is 0.0), or an
        array of floating point values, one for each individual target.

    Examples
    --------
    >>> from sklearn.metrics import mean_squared_log_error
    >>> y_true = [3, 5, 2.5, 7]
    >>> y_pred = [2.5, 5, 4, 8]
    >>> mean_squared_log_error(y_true, y_pred)
    np.float64(0.039...)
    >>> y_true = [[0.5, 1], [1, 2], [7, 6]]
    >>> y_pred = [[0.5, 2], [1, 2.5], [8, 8]]
    >>> mean_squared_log_error(y_true, y_pred)
    np.float64(0.044...)
    >>> mean_squared_log_error(y_true, y_pred, multioutput='raw_values')
    array([0.00462428, 0.08377444])
    >>> mean_squared_log_error(y_true, y_pred, multioutput=[0.3, 0.7])
    np.float64(0.060...)
    rc   z§'squared' is deprecated in version 1.4 and will be removed in 1.6. To calculate the root mean squared logarithmic error, use the function'root_mean_squared_log_error'.rH   r   zSMean Squared Logarithmic Error cannot be used when targets contain negative values.)rg   rh   ri   r   rC   r   Úanyr6   r   rN   Úlog1p)r;   r<   rF   r=   re   rA   s         rB   r   r   T  sÆ   € ð\ �,ÒÜ�‰ð1ô
 ô	
ñ Ü.Ø˜¨mÈôð ô +=Ø�˜ó+Ñ'€FˆF�F˜Kô ˜F F¨MÔ:à�‰
×ÑÔ˜f q™j×-Ñ-Ô/Üð/ó
ð 	
ô
 Ü
�‰�ÓÜ
�‰�ÓØ#Øô	ð rD   c                ó  — t        | ||«      \  }} }}t        | ||«       | dk  j                  «       s|dk  j                  «       rt        d«      ‚t	        t        j                  | «      t        j                  |«      ||¬«      S )a{  Root mean squared logarithmic error regression loss.

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

    .. versionadded:: 1.4

    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 target values.

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

    multioutput : {'raw_values', 'uniform_average'} or array-like of shape             (n_outputs,), default='uniform_average'

        Defines aggregating of multiple output values.
        Array-like value defines weights used to average errors.

        'raw_values' :
            Returns a full set of errors when the input is of multioutput
            format.

        'uniform_average' :
            Errors of all outputs are averaged with uniform weight.

    Returns
    -------
    loss : float or ndarray of floats
        A non-negative floating point value (the best value is 0.0), or an
        array of floating point values, one for each individual target.

    Examples
    --------
    >>> from sklearn.metrics import root_mean_squared_log_error
    >>> y_true = [3, 5, 2.5, 7]
    >>> y_pred = [2.5, 5, 4, 8]
    >>> root_mean_squared_log_error(y_true, y_pred)
    np.float64(0.199...)
    r   zXRoot Mean Squared Logarithmic Error cannot be used when targets contain negative values.rH   )rC   r   rm   r6   r   rN   rn   )r;   r<   rF   r=   r>   s        rB   r   r   Ä  s†   € ôp &8¸ÀÈÓ%TÑ"€A€vˆv�{Ü˜F F¨MÔ:à�‰
×ÑÔ˜f q™j×-Ñ-Ô/Üð/ó
ð 	
ô
 #Ü
�‰�ÓÜ
�‰�ÓØ#Øô	ð rD   )r;   r<   r=   rF   )r=   rF   c                óN  — t        | ||«      \  }} }}|€.t        j                  t        j                  || z
  «      d¬«      }n/t	        ||«      }t        t        j                  || z
  «      |¬«      }t        |t        «      r|dk(  r|S |dk(  rd}t        j                  ||¬«      S )aa  Median absolute error regression loss.

    Median absolute error output is non-negative floating point. The best value
    is 0.0. Read more in the :ref:`User Guide <median_absolute_error>`.

    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 target values.

    multioutput : {'raw_values', 'uniform_average'} or array-like of shape             (n_outputs,), default='uniform_average'
        Defines aggregating of multiple output values. Array-like value defines
        weights used to average errors.

        'raw_values' :
            Returns a full set of errors in case of multioutput input.

        'uniform_average' :
            Errors of all outputs are averaged with uniform weight.

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

        .. versionadded:: 0.24

    Returns
    -------
    loss : float or ndarray of floats
        If multioutput is 'raw_values', then mean absolute error is returned
        for each output separately.
        If multioutput is 'uniform_average' or an ndarray of weights, then the
        weighted average of all output errors is returned.

    Examples
    --------
    >>> from sklearn.metrics import median_absolute_error
    >>> y_true = [3, -0.5, 2, 7]
    >>> y_pred = [2.5, 0.0, 2, 8]
    >>> median_absolute_error(y_true, y_pred)
    np.float64(0.5)
    >>> y_true = [[0.5, 1], [-1, 1], [7, -6]]
    >>> y_pred = [[0, 2], [-1, 2], [8, -5]]
    >>> median_absolute_error(y_true, y_pred)
    np.float64(0.75)
    >>> median_absolute_error(y_true, y_pred, multioutput='raw_values')
    array([0.5, 1. ])
    >>> median_absolute_error(y_true, y_pred, multioutput=[0.3, 0.7])
    np.float64(0.85)
    Nr   ©rL   ©rF   r.   r/   rM   )	rC   rN   ÚmedianrP   r   r   r8   r9   rO   )r;   r<   r=   rF   rA   rQ   s         rB   r   r     s¥   € ôB +=Ø�˜ó+Ñ'€FˆF�F˜Kð ÐÜŸ	™	¤"§&¡&¨°&©Ó"9ÀÔB‰ä,¨]¸FÓCˆÜ,Ü�F‰F�6˜F‘?Ó#°=ô
ˆô �+œsÔ#Ø˜,Ò&Ø Ð ØÐ-Ò-àˆKä�:‰:�m¨[Ô9Ð9rD   c                 ót  — | j                   }|dk7  }|s	d| |z  z
  }	n9| dk7  }
|j                  |g||¬«      }	||
z  }d| |   ||   z  z
  |	|<   d|	|
| z  <   t        |t        «      r*|dk(  r|	S |dk(  rd}n|dk(  r|}|j	                  |«      sd}n|}t        |	¬	«      }t        |«      dk(  rt        |«      S |S )
zCCommon part used by explained variance score and :math:`R^2` score.r   r,   )Údevicer+   ç        r.   r/   Nr0   rM   )r+   Úonesr8   r9   rm   r   r   Úfloat)Ú	numeratorÚdenominatorr?   r=   Úforce_finiter)   ru   r+   Únonzero_denominatorÚoutput_scoresÚnonzero_numeratorÚvalid_scoreÚavg_weightsÚresults                 rB   Ú_assemble_r2_explained_variancer‚   b  s  € ð �O‰O€Eà%¨Ñ*Ðáà˜Y¨Ñ4Ñ5‰à%¨™NÐð Ÿ™  °FÀ%˜ÓHˆà)Ð,=Ñ=ˆà%&Ø�kÑ" [°Ñ%=Ñ=ñ&
ˆ�kÑ"ð CFˆÐ'Ð+>Ð*>Ñ>Ñ?ä�+œsÔ#Ø˜,Ò&à Ð ØÐ-Ò-à‰KØÐ/Ò/Ø%ˆKØ—6‘6Ð-Ô.ð #‘à!ˆä�m¨[Ô9€FÜˆFƒ|�qÒÜ�V‹}ÐØ€MrD   >   r.   r/   r0   )r;   r<   rF   r=   r{   )rF   r=   r{   c          
      óz  — t        | ||«      \  }} }}t        | ||«       t        j                  | |z
  |d¬«      }t        j                  | |z
  |z
  dz  |d¬«      }t        j                  | |d¬«      }t        j                  | |z
  dz  |d¬«      }	t	        ||	| j
                  d   ||t        | «      d   d¬«      S )a„  Explained variance regression score function.

    Best possible score is 1.0, lower values are worse.

    In the particular case when ``y_true`` is constant, the explained variance
    score is not finite: it is either ``NaN`` (perfect predictions) or
    ``-Inf`` (imperfect predictions). To prevent such non-finite numbers to
    pollute higher-level experiments such as a grid search cross-validation,
    by default these cases are replaced with 1.0 (perfect predictions) or 0.0
    (imperfect predictions) respectively. If ``force_finite``
    is set to ``False``, this score falls back on the original :math:`R^2`
    definition.

    .. note::
       The Explained Variance score is similar to the
       :func:`R^2 score <r2_score>`, with the notable difference that it
       does not account for systematic offsets in the prediction. Most often
       the :func:`R^2 score <r2_score>` should be preferred.

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

    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 target values.

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

    multioutput : {'raw_values', 'uniform_average', 'variance_weighted'} or             array-like of shape (n_outputs,), default='uniform_average'
        Defines aggregating of multiple output scores.
        Array-like value defines weights used to average scores.

        'raw_values' :
            Returns a full set of scores in case of multioutput input.

        'uniform_average' :
            Scores of all outputs are averaged with uniform weight.

        'variance_weighted' :
            Scores of all outputs are averaged, weighted by the variances
            of each individual output.

    force_finite : bool, default=True
        Flag indicating if ``NaN`` and ``-Inf`` scores resulting from constant
        data should be replaced with real numbers (``1.0`` if prediction is
        perfect, ``0.0`` otherwise). Default is ``True``, a convenient setting
        for hyperparameters' search procedures (e.g. grid search
        cross-validation).

        .. versionadded:: 1.1

    Returns
    -------
    score : float or ndarray of floats
        The explained variance or ndarray if 'multioutput' is 'raw_values'.

    See Also
    --------
    r2_score :
        Similar metric, but accounting for systematic offsets in
        prediction.

    Notes
    -----
    This is not a symmetric function.

    Examples
    --------
    >>> from sklearn.metrics import explained_variance_score
    >>> y_true = [3, -0.5, 2, 7]
    >>> y_pred = [2.5, 0.0, 2, 8]
    >>> explained_variance_score(y_true, y_pred)
    0.957...
    >>> y_true = [[0.5, 1], [-1, 1], [7, -6]]
    >>> y_pred = [[0, 2], [-1, 2], [8, -5]]
    >>> explained_variance_score(y_true, y_pred, multioutput='uniform_average')
    0.983...
    >>> y_true = [-2, -2, -2]
    >>> y_pred = [-2, -2, -2]
    >>> explained_variance_score(y_true, y_pred)
    1.0
    >>> explained_variance_score(y_true, y_pred, force_finite=False)
    nan
    >>> y_true = [-2, -2, -2]
    >>> y_pred = [-2, -2, -2 + 1e-8]
    >>> explained_variance_score(y_true, y_pred)
    0.0
    >>> explained_variance_score(y_true, y_pred, force_finite=False)
    -inf
    r   rJ   r   r,   N©ry   rz   r?   r=   r{   r)   ru   )rC   r   rN   rO   r‚   r5   r	   )
r;   r<   rF   r=   r{   rA   Ú
y_diff_avgry   Ú
y_true_avgrz   s
             rB   r    r    ”  sË   € ôh +=Ø�˜ó+Ñ'€FˆF�F˜Kô ˜F F¨MÔ:ä—‘˜F V™O°]ÈÔK€JÜ—
‘
Ø	�&‰˜:Ñ	%¨!Ñ+°]Èô€Iô —‘˜F¨MÀÔB€JÜ—*‘*˜f zÑ1°aÑ7ÀÐUVÔW€Kä*ØØØ—,‘,˜q‘/ØØ!Ü˜Ó  Ñ#àô	ð 	rD   c          
      óð  — t        | |||«      \  }}}t        | |||¬«      }t        | ||||¬«      \  }} }}t        | ||«       t	        |«      dk  r'd}	t        j                  |	t        «       t        d«      S |�t        ||¬«      }|dd…df   }
nd}
|j                  |
| |z
  dz  z  d	¬
«      }|j                  |
| t        | d	||¬«      z
  dz  z  d	¬
«      }t        ||| j                  d   ||||¬«      S )aX  :math:`R^2` (coefficient of determination) regression score function.

    Best possible score is 1.0 and it can be negative (because the
    model can be arbitrarily worse). In the general case when the true y is
    non-constant, a constant model that always predicts the average y
    disregarding the input features would get a :math:`R^2` score of 0.0.

    In the particular case when ``y_true`` is constant, the :math:`R^2` score
    is not finite: it is either ``NaN`` (perfect predictions) or ``-Inf``
    (imperfect predictions). To prevent such non-finite numbers to pollute
    higher-level experiments such as a grid search cross-validation, by default
    these cases are replaced with 1.0 (perfect predictions) or 0.0 (imperfect
    predictions) respectively. You can set ``force_finite`` to ``False`` to
    prevent this fix from happening.

    Note: when the prediction residuals have zero mean, the :math:`R^2` score
    is identical to the
    :func:`Explained Variance score <explained_variance_score>`.

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

    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 target values.

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

    multioutput : {'raw_values', 'uniform_average', 'variance_weighted'},             array-like of shape (n_outputs,) or None, default='uniform_average'

        Defines aggregating of multiple output scores.
        Array-like value defines weights used to average scores.
        Default is "uniform_average".

        'raw_values' :
            Returns a full set of scores in case of multioutput input.

        'uniform_average' :
            Scores of all outputs are averaged with uniform weight.

        'variance_weighted' :
            Scores of all outputs are averaged, weighted by the variances
            of each individual output.

        .. versionchanged:: 0.19
            Default value of multioutput is 'uniform_average'.

    force_finite : bool, default=True
        Flag indicating if ``NaN`` and ``-Inf`` scores resulting from constant
        data should be replaced with real numbers (``1.0`` if prediction is
        perfect, ``0.0`` otherwise). Default is ``True``, a convenient setting
        for hyperparameters' search procedures (e.g. grid search
        cross-validation).

        .. versionadded:: 1.1

    Returns
    -------
    z : float or ndarray of floats
        The :math:`R^2` score or ndarray of scores if 'multioutput' is
        'raw_values'.

    Notes
    -----
    This is not a symmetric function.

    Unlike most other scores, :math:`R^2` score may be negative (it need not
    actually be the square of a quantity R).

    This metric is not well-defined for single samples and will return a NaN
    value if n_samples is less than two.

    References
    ----------
    .. [1] `Wikipedia entry on the Coefficient of determination
            <https://en.wikipedia.org/wiki/Coefficient_of_determination>`_

    Examples
    --------
    >>> from sklearn.metrics import r2_score
    >>> y_true = [3, -0.5, 2, 7]
    >>> y_pred = [2.5, 0.0, 2, 8]
    >>> r2_score(y_true, y_pred)
    0.948...
    >>> y_true = [[0.5, 1], [-1, 1], [7, -6]]
    >>> y_pred = [[0, 2], [-1, 2], [8, -5]]
    >>> r2_score(y_true, y_pred,
    ...          multioutput='variance_weighted')
    0.938...
    >>> y_true = [1, 2, 3]
    >>> y_pred = [1, 2, 3]
    >>> r2_score(y_true, y_pred)
    1.0
    >>> y_true = [1, 2, 3]
    >>> y_pred = [2, 2, 2]
    >>> r2_score(y_true, y_pred)
    0.0
    >>> y_true = [1, 2, 3]
    >>> y_pred = [3, 2, 1]
    >>> r2_score(y_true, y_pred)
    -3.0
    >>> y_true = [-2, -2, -2]
    >>> y_pred = [-2, -2, -2]
    >>> r2_score(y_true, y_pred)
    1.0
    >>> r2_score(y_true, y_pred, force_finite=False)
    nan
    >>> y_true = [-2, -2, -2]
    >>> y_pred = [-2, -2, -2 + 1e-8]
    >>> r2_score(y_true, y_pred)
    0.0
    >>> r2_score(y_true, y_pred, force_finite=False)
    -inf
    r(   )r+   r)   r   z9R^2 score is not well-defined with less than two samples.ÚnanN©r+   g      ð?r   rq   )rL   rK   r)   r,   r„   )r
   r   rC   r   r   rg   rh   r   rx   r   Úsumr   r‚   r5   )r;   r<   rF   r=   r{   r)   r>   Údevice_r+   ÚmsgÚweightry   rz   s                rB   r   r   !  s,  € ôZ .Ø�˜ {ó�N€Bˆˆ7ô *¨&°&¸-ÈBÔO€Eä%7Ø�˜¨5°Rô&Ñ"€A€vˆv�{ô ˜F F¨MÔ:ä�FÓ˜aÒØIˆÜ�‰�cÔ1Ô2Ü�U‹|ÐàÐ Ü$ ]¸%Ô@ˆØšq $˜wÑ'‰àˆà—‘�v ¨&¡°QÑ 6Ñ6¸Q�Ó?€IØ—&‘&Ø�&œ8 F°¸MÈbÔQÑQÐVWÑWÑWØð ó €Kô
 +ØØØ—,‘,˜q‘/ØØ!ØØôð rD   )r;   r<   c                 óœ   — t        | |d«      \  }} }}|dk(  rt        d«      ‚t        j                  t        j                  | |z
  «      «      S )al  
    The max_error metric calculates the maximum residual error.

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

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

    y_pred : array-like of shape (n_samples,)
        Estimated target values.

    Returns
    -------
    max_error : float
        A positive floating point value (the best value is 0.0).

    Examples
    --------
    >>> from sklearn.metrics import max_error
    >>> y_true = [3, 2, 7, 1]
    >>> y_pred = [4, 2, 7, 1]
    >>> max_error(y_true, y_pred)
    np.int64(1)
    Nr2   z&Multioutput not supported in max_error)rC   r6   rN   ÚmaxrP   )r;   r<   rA   r>   s       rB   r   r   Õ  sM   € ôD !3°6¸6À4Ó HÑ€FˆF�F˜AØÐ)Ò)ÜÐAÓBÐBÜ�6‰6”"—&‘&˜ &™Ó)Ó*Ð*rD   c                 óÀ  — |}|dk  r€dt        j                  t        j                  | d«      d|z
  «      d|z
  d|z
  z  z  | t        j                  |d|z
  «      z  d|z
  z  z
  t        j                  |d|z
  «      d|z
  z  z   z  }nÁ|dk(  r	| |z
  dz  }n³|dk(  rdt        | | |z  «      | z
  |z   z  }n•|dk(  r%dt        j                  || z  «      | |z  z   dz
  z  }nkdt        j                  | d|z
  «      d|z
  d|z
  z  z  | t        j                  |d|z
  «      z  d|z
  z  z
  t        j                  |d|z
  «      d|z
  z  z   z  }t        j
                  ||¬«      S )z&Mean Tweedie deviance regression loss.r   r   r,   rM   )rN   Úpowerr`   r   ÚlogrO   )r;   r<   rF   r‘   ÚpÚdevs         rB   Ú_mean_tweedie_deviancer•   ý  s{  € à€AØˆ1‚uàÜ�H‰H”R—Z‘Z ¨Ó*¨A°©EÓ2°q¸1±uÀÀQÁÑ6GÑHØ”r—x‘x ¨¨A©Ó.Ñ.°!°a±%Ñ8ñ9ä�h‰h�v˜q 1™uÓ%¨¨Q©Ñ/ñ0ñ
‰ð
 
ˆaŠà˜‰ 1Ñ$‰Ø	
ˆaŠà”5˜ ¨&¡Ó1°FÑ:¸VÑCÑD‰Ø	
ˆaŠà”2—6‘6˜& 6™/Ó*¨V°f©_Ñ<¸qÑ@ÑA‰àÜ�H‰H�V˜Q ™UÓ#¨¨A©°!°a±%Ñ'8Ñ9Ø”r—x‘x ¨¨A©Ó.Ñ.°!°a±%Ñ8ñ9ä�h‰h�v˜q 1™uÓ%¨¨Q©Ñ/ñ0ñ
ˆô �:‰:�c =Ô1Ð1rD   ÚrightÚleft)r;   r<   rF   r‘   ©rF   r‘   c                ól  — t        | |dt        j                  t        j                  g¬«      \  }} }}|dk(  rt	        d«      ‚t        | ||«       |�"t        |«      }|dd…t        j                  f   }d|› d�}|dk  r!|dk  j                  «       r•t	        |dz   «      ‚|dk(  rn�d	|cxk  rd
k  r7n n4| dk  j                  «       s|dk  j                  «       rMt	        |dz   «      ‚|d
k\  r4| dk  j                  «       s|dk  j                  «       rt	        |dz   «      ‚t        ‚t        | |||¬«      S )ag  Mean Tweedie deviance regression loss.

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

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

    y_pred : array-like of shape (n_samples,)
        Estimated target values.

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

    power : float, default=0
        Tweedie power parameter. Either power <= 0 or power >= 1.

        The higher `p` the less weight is given to extreme
        deviations between true and predicted targets.

        - power < 0: Extreme stable distribution. Requires: y_pred > 0.
        - power = 0 : Normal distribution, output corresponds to
          mean_squared_error. y_true and y_pred can be any real numbers.
        - power = 1 : Poisson distribution. Requires: y_true >= 0 and
          y_pred > 0.
        - 1 < p < 2 : Compound Poisson distribution. Requires: y_true >= 0
          and y_pred > 0.
        - power = 2 : Gamma distribution. Requires: y_true > 0 and y_pred > 0.
        - power = 3 : Inverse Gaussian distribution. Requires: y_true > 0
          and y_pred > 0.
        - otherwise : Positive stable distribution. Requires: y_true > 0
          and y_pred > 0.

    Returns
    -------
    loss : float
        A non-negative floating point value (the best value is 0.0).

    Examples
    --------
    >>> from sklearn.metrics import mean_tweedie_deviance
    >>> y_true = [2, 0, 1, 4]
    >>> y_pred = [0.5, 0.5, 2., 2.]
    >>> mean_tweedie_deviance(y_true, y_pred, power=1)
    np.float64(1.4260...)
    Nr‰   r2   z2Multioutput not supported in mean_tweedie_deviancez'Mean Tweedie deviance error with power=z can only be used on r   zstrictly positive y_pred.r,   r   z,non-negative y and strictly positive y_pred.zstrictly positive y and y_pred.r˜   )
rC   rN   r^   Úfloat32r6   r   r   Únewaxisrm   r•   )r;   r<   rF   r‘   rA   r>   Úmessages          rB   r!   r!     sD  € ôx !3Ø�˜¤R§Z¡Z´·±Ð$<ô!Ñ€FˆF�F˜Að Ð)Ò)ÜÐMÓNÐNÜ˜F F¨MÔ:àÐ Ü$ ]Ó3ˆØ%¢a¬¯© mÑ4ˆà7¸°wÐ>SÐT€GØˆq‚yà�a‰K×ÑÔÜ˜WÐ'BÑBÓCÐCØ	�!ŠàØ	
ˆeŒ�a�à�Q‰J×ÑÔ &¨A¡+×!2Ñ!2Ô!4Ü˜WÐ'UÑUÓVÐVØ	�!Šà�a‰K×ÑÔ 6¨Q¡;×"3Ñ"3Ô"5Ü˜WÐ'HÑHÓIÐIô Ðä!Ø� m¸5ôð rD   ©r;   r<   rF   rr   c                ó    — t        | ||d¬«      S )ap  Mean Poisson deviance regression loss.

    Poisson deviance is equivalent to the Tweedie deviance with
    the power parameter `power=1`.

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

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

    y_pred : array-like of shape (n_samples,)
        Estimated target values. Requires y_pred > 0.

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

    Returns
    -------
    loss : float
        A non-negative floating point value (the best value is 0.0).

    Examples
    --------
    >>> from sklearn.metrics import mean_poisson_deviance
    >>> y_true = [2, 0, 1, 4]
    >>> y_pred = [0.5, 0.5, 2., 2.]
    >>> mean_poisson_deviance(y_true, y_pred)
    np.float64(1.4260...)
    r,   r˜   ©r!   r�   s      rB   r"   r"   z  s   € ôP ! ¨¸}ÐTUÔVÐVrD   c                ó    — t        | ||d¬«      S )a¾  Mean Gamma deviance regression loss.

    Gamma deviance is equivalent to the Tweedie deviance with
    the power parameter `power=2`. It is invariant to scaling of
    the target variable, and measures relative errors.

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

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

    y_pred : array-like of shape (n_samples,)
        Estimated target values. Requires y_pred > 0.

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

    Returns
    -------
    loss : float
        A non-negative floating point value (the best value is 0.0).

    Examples
    --------
    >>> from sklearn.metrics import mean_gamma_deviance
    >>> y_true = [2, 0.5, 1, 4]
    >>> y_pred = [0.5, 0.5, 2., 2.]
    >>> mean_gamma_deviance(y_true, y_pred)
    np.float64(1.0568...)
    r   r˜   rŸ   r�   s      rB   r#   r#   ¥  s   € ôR ! ¨¸}ÐTUÔVÐVrD   c                ó¾  — t        | |dt        j                  t        j                  g¬«      \  }} }}|dk(  rt	        d«      ‚t        |«      dk  r'd}t        j                  |t        «       t        d«      S t        j                  | «      t        j                  |«      }} t        | |||¬«      }t        j                  | |¬	«      }t        | |||¬«      }	d
||	z  z
  S )aW
  
    :math:`D^2` regression score function, fraction of Tweedie deviance explained.

    Best possible score is 1.0 and it can be negative (because the model can be
    arbitrarily worse). A model that always uses the empirical mean of `y_true` as
    constant prediction, disregarding the input features, gets a D^2 score of 0.0.

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

    .. versionadded:: 1.0

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

    y_pred : array-like of shape (n_samples,)
        Estimated target values.

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

    power : float, default=0
        Tweedie power parameter. Either power <= 0 or power >= 1.

        The higher `p` the less weight is given to extreme
        deviations between true and predicted targets.

        - power < 0: Extreme stable distribution. Requires: y_pred > 0.
        - power = 0 : Normal distribution, output corresponds to r2_score.
          y_true and y_pred can be any real numbers.
        - power = 1 : Poisson distribution. Requires: y_true >= 0 and
          y_pred > 0.
        - 1 < p < 2 : Compound Poisson distribution. Requires: y_true >= 0
          and y_pred > 0.
        - power = 2 : Gamma distribution. Requires: y_true > 0 and y_pred > 0.
        - power = 3 : Inverse Gaussian distribution. Requires: y_true > 0
          and y_pred > 0.
        - otherwise : Positive stable distribution. Requires: y_true > 0
          and y_pred > 0.

    Returns
    -------
    z : float or ndarray of floats
        The D^2 score.

    Notes
    -----
    This is not a symmetric function.

    Like R^2, D^2 score may be negative (it need not actually be the square of
    a quantity D).

    This metric is not well-defined for single samples and will return a NaN
    value if n_samples is less than two.

    References
    ----------
    .. [1] Eq. (3.11) of Hastie, Trevor J., Robert Tibshirani and Martin J.
           Wainwright. "Statistical Learning with Sparsity: The Lasso and
           Generalizations." (2015). https://hastie.su.domains/StatLearnSparsity/

    Examples
    --------
    >>> from sklearn.metrics import d2_tweedie_score
    >>> y_true = [0.5, 1, 2.5, 7]
    >>> y_pred = [1, 1, 5, 3.5]
    >>> d2_tweedie_score(y_true, y_pred)
    np.float64(0.285...)
    >>> d2_tweedie_score(y_true, y_pred, power=1)
    np.float64(0.487...)
    >>> d2_tweedie_score(y_true, y_pred, power=2)
    np.float64(0.630...)
    >>> d2_tweedie_score(y_true, y_true, power=2)
    np.float64(1.0)
    Nr‰   r2   z-Multioutput not supported in d2_tweedie_scorer   ú9D^2 score is not well-defined with less than two samples.rˆ   r˜   rM   r,   )rC   rN   r^   rš   r6   r   rg   rh   r   rx   Úsqueezer!   rO   r•   )
r;   r<   rF   r‘   rA   r>   rŒ   ry   Úy_avgrz   s
             rB   r$   r$   Ñ  sÕ   € ôr !3Ø�˜¤R§Z¡Z´·±Ð$<ô!Ñ€FˆF�F˜Að Ð)Ò)ÜÐHÓIÐIä�FÓ˜aÒØIˆÜ�‰�cÔ1Ô2Ü�U‹|Ðä—Z‘Z Ó'¬¯©°FÓ);ˆF€FÜ%Ø� m¸5ô€Iô �J‰J�v }Ô5€EÜ(Ø� ]¸%ô€Kð ˆy˜;Ñ&Ñ&Ð&rD   c                óØ  — t        | ||«      \  }} }}t        | ||«       t        |«      dk  r'd}t        j                  |t
        «       t        d«      S t        | |||d¬«      }|€;t        j                  t        j                  | |dz  d¬	«      t        | «      d
f«      }n<t        || «      }t        j                  t        | ||dz  ¬«      t        | «      d
f«      }t        | |||d¬«      }	|dk7  }
|	dk7  }|
|z  }t        j                  | j                  d
   «      }d
||   |	|   z  z
  ||<   d||
| z  <   t!        |t"        «      r
|dk(  r|S d}n|}t        j$                  ||¬«      S )uò
  
    :math:`D^2` regression score function, fraction of pinball loss explained.

    Best possible score is 1.0 and it can be negative (because the model can be
    arbitrarily worse). A model that always uses the empirical alpha-quantile of
    `y_true` as constant prediction, disregarding the input features,
    gets a :math:`D^2` score of 0.0.

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

    .. versionadded:: 1.1

    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 target values.

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

    alpha : float, default=0.5
        Slope of the pinball deviance. It determines the quantile level alpha
        for which the pinball deviance and also D2 are optimal.
        The default `alpha=0.5` is equivalent to `d2_absolute_error_score`.

    multioutput : {'raw_values', 'uniform_average'} or array-like of shape             (n_outputs,), default='uniform_average'
        Defines aggregating of multiple output values.
        Array-like value defines weights used to average scores.

        'raw_values' :
            Returns a full set of errors in case of multioutput input.

        'uniform_average' :
            Scores of all outputs are averaged with uniform weight.

    Returns
    -------
    score : float or ndarray of floats
        The :math:`D^2` score with a pinball deviance
        or ndarray of scores if `multioutput='raw_values'`.

    Notes
    -----
    Like :math:`R^2`, :math:`D^2` score may be negative
    (it need not actually be the square of a quantity D).

    This metric is not well-defined for a single point and will return a NaN
    value if n_samples is less than two.

     References
    ----------
    .. [1] Eq. (7) of `Koenker, Roger; Machado, JosÃ© A. F. (1999).
           "Goodness of Fit and Related Inference Processes for Quantile Regression"
           <https://doi.org/10.1080/01621459.1999.10473882>`_
    .. [2] Eq. (3.11) of Hastie, Trevor J., Robert Tibshirani and Martin J.
           Wainwright. "Statistical Learning with Sparsity: The Lasso and
           Generalizations." (2015). https://hastie.su.domains/StatLearnSparsity/

    Examples
    --------
    >>> from sklearn.metrics import d2_pinball_score
    >>> y_true = [1, 2, 3]
    >>> y_pred = [1, 3, 3]
    >>> d2_pinball_score(y_true, y_pred)
    np.float64(0.5)
    >>> d2_pinball_score(y_true, y_pred, alpha=0.9)
    np.float64(0.772...)
    >>> d2_pinball_score(y_true, y_pred, alpha=0.1)
    np.float64(-1.045...)
    >>> d2_pinball_score(y_true, y_true, alpha=0.1)
    np.float64(1.0)
    r   r¢   rˆ   r.   rV   Néd   r   )ÚqrL   r,   )rF   Ú
percentilerv   rM   )rC   r   r   rg   rh   r   rx   r   rN   Útiler¨   r:   r   r   rw   r5   r8   r9   rO   )r;   r<   rF   rT   r=   rA   rŒ   ry   Ú
y_quantilerz   r~   r|   r   r}   r€   s                  rB   r%   r%   B  s�  € ôx +=Ø�˜ó+Ñ'€FˆF�F˜Kô ˜F F¨MÔ:ä�FÓ˜aÒØIˆÜ�‰�cÔ1Ô2Ü�U‹|Ðä!ØØØ#ØØ ô€Ið ÐÜ—W‘WÜ�M‰M˜& E¨C¡K°aÔ8¼3¸v»;ÈÐ:Jó
‰
ô -¨]¸FÓCˆÜ—W‘WÜ Ø mÀÈÁôô �‹[˜!Ðó	
ˆ
ô $ØØØ#ØØ ô€Kð " Q™ÐØ%¨Ñ*ÐØ#Ð&9Ñ9€KÜ—G‘G˜FŸL™L¨™OÓ,€Mà!" i°Ñ&<¸{È;Ñ?WÑ&WÑ!X€M�+ÑØ>A€MÐ#Ð':Ð&:Ñ:Ñ;ä�+œsÔ#Ø˜,Ò&à Ð ð ‰Kà!ˆä�:‰:�m¨[Ô9Ð9rD   c                ó"   — t        | ||d|¬«      S )a  
    :math:`D^2` regression score function, fraction of absolute error explained.

    Best possible score is 1.0 and it can be negative (because the model can be
    arbitrarily worse). A model that always uses the empirical median of `y_true`
    as constant prediction, disregarding the input features,
    gets a :math:`D^2` score of 0.0.

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

    .. versionadded:: 1.1

    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 target values.

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

    multioutput : {'raw_values', 'uniform_average'} or array-like of shape             (n_outputs,), default='uniform_average'
        Defines aggregating of multiple output values.
        Array-like value defines weights used to average scores.

        'raw_values' :
            Returns a full set of errors in case of multioutput input.

        'uniform_average' :
            Scores of all outputs are averaged with uniform weight.

    Returns
    -------
    score : float or ndarray of floats
        The :math:`D^2` score with an absolute error deviance
        or ndarray of scores if 'multioutput' is 'raw_values'.

    Notes
    -----
    Like :math:`R^2`, :math:`D^2` score may be negative
    (it need not actually be the square of a quantity D).

    This metric is not well-defined for single samples and will return a NaN
    value if n_samples is less than two.

     References
    ----------
    .. [1] Eq. (3.11) of Hastie, Trevor J., Robert Tibshirani and Martin J.
           Wainwright. "Statistical Learning with Sparsity: The Lasso and
           Generalizations." (2015). https://hastie.su.domains/StatLearnSparsity/

    Examples
    --------
    >>> from sklearn.metrics import d2_absolute_error_score
    >>> y_true = [3, -0.5, 2, 7]
    >>> y_pred = [2.5, 0.0, 2, 8]
    >>> d2_absolute_error_score(y_true, y_pred)
    np.float64(0.764...)
    >>> y_true = [[0.5, 1], [-1, 1], [7, -6]]
    >>> y_pred = [[0, 2], [-1, 2], [8, -5]]
    >>> d2_absolute_error_score(y_true, y_pred, multioutput='uniform_average')
    np.float64(0.691...)
    >>> d2_absolute_error_score(y_true, y_pred, multioutput='raw_values')
    array([0.8125    , 0.57142857])
    >>> y_true = [1, 2, 3]
    >>> y_pred = [1, 2, 3]
    >>> d2_absolute_error_score(y_true, y_pred)
    np.float64(1.0)
    >>> y_true = [1, 2, 3]
    >>> y_pred = [2, 2, 2]
    >>> d2_absolute_error_score(y_true, y_pred)
    np.float64(0.0)
    >>> y_true = [1, 2, 3]
    >>> y_pred = [3, 2, 1]
    >>> d2_absolute_error_score(y_true, y_pred)
    np.float64(-1.0)
    rU   rV   )r%   rE   s       rB   r&   r&   Ú  s   € ô~ Ø� m¸3ÈKôð rD   )ÚnumericN)2Ú__doc__rg   Únumbersr   ÚnumpyrN   Úscipy.specialr   Ú
exceptionsr   Úutils._array_apir   r   r	   r
   r   Úutils._param_validationr   r   r   r   Úutils.statsr   Úutils.validationr   r   r   r   r   Ú__ALL__rC   r   r   r   r   r   r   r   r   r‚   r    r   r   r•   r!   r"   r#   r$   r%   r&   © rD   rB   ú<module>r¸      s	  ðñó: Ý ã Ý å /÷õ ÷ TÓ SÝ .÷õ ò€ó*J/ñZ à�.Ø�.Ø&¨Ð-Ù" LÐ2CÐ#DÓEÀ|ÐTñ	ð #'ôð &*Ð7HóC:óðC:ñL à�.Ø�.Ø&¨Ð-Ù˜4  A¨fÔ5Ð6Ù" LÐ2CÐ#DÓEÀ|ÐTñð #'ô	ð &*°ÐBSóM:ó	ðM:ñ` à�.Ø�.Ø&¨Ð-Ù" LÐ2CÐ#DÓEÀ|ÐTñ	ð #'ôð &*Ð7HóS:óðS:ñl à�.Ø�.Ø&¨Ð-Ù" LÐ2CÐ#DÓEÀ|ÐTÙ™: | nÓ5Ó6¸	ÐBñð #'ô	ð Ø!Øó]:ó	ð]:ñ@ à�.Ø�.Ø&¨Ð-Ù" LÐ2CÐ#DÓEÀ|ÐTñ	ð #'ôð &*Ð7Hó>:óð>:ñB à�.Ø�.Ø&¨Ð-Ù" LÐ2CÐ#DÓEÀ|ÐTÙ™: | nÓ5Ó6¸	ÐBñð #'ô	ð Ø!Øócó	ðcñL à�.Ø�.Ø&¨Ð-Ù" LÐ2CÐ#DÓEÀ|ÐTñ	ð #'ôð &*Ð7Hó=óð=ñ@ à�.Ø�.Ù" LÐ2CÐ#DÓEÀ|ÐTØ&¨Ð-ñ	ð #'ôð $5ÀDóI:óðI:òX/ñd à�.Ø�.Ø&¨Ð-áÒMÓNØð
ð #˜ñ	ð #'ôð" Ø!Øó}óð}ñ@ à�.Ø�.Ø&¨Ð-áÒMÓNØØð
ð
 #˜ñ
ð #'ôð$ Ø!ØócóðcñL à�.Ø�.ñð #'ôñ+óð+òB2ñ: à�.Ø�.Ø&¨Ð-á�T˜4 ¨7Ô3Ù�T˜1˜d¨6Ô2ð
ñ	ð #'ôð <@Àqó QóðQñh à�.Ø�.Ø&¨Ð-ñð
 #'ôð <@ó  Wóð WñF à�.Ø�.Ø&¨Ð-ñð
 #'ôð :>ó !Wóð!WñH à�.Ø�.Ø&¨Ð-á�T˜4 ¨7Ô3Ù�T˜1˜d¨6Ô2ð
ñ	ð #'ôð 7;À!ó b'óðb'ñJ à�.Ø�.Ø&¨Ð-Ù˜4  A¨fÔ5Ð6á˜Ð&7Ð8Ó9Øð
ñ	ð #'ôð &*°ÐBSóH:óðH:ñV à�.Ø�.Ø&¨Ð-á˜Ð&7Ð8Ó9Øð
ñ	ð #'ôð &*Ð7HóUóñUrD   