
    Ug                        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          d0             Z*d1 Z+ edgdgddg eeddd2           eeddd3          gd4d          ddd5d6            Z, edgdgddgd7d          dd8d9            Z- edgdgddgd7d          dd8d:            Z. edgdgddg eeddd2           eeddd3          gd4d          ddd5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=            Z1dS )?zMetrics 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_scorenumericc                 4   t          | |||          \  }}t          | |           t          | d|          } t          |d|          }| j        dk    r|                    | d          } |j        dk    r|                    |d          }| j        d         |j        d         k    r9t          d                    | j        d         |j        d                             | j        d         }d}t          |t                    r(||vr#t          d                    ||                    n\|Zt          |d
          }|dk    rt          d          |t          |          k    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}N)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	            Z/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/sklearn/metrics/_regression.py_check_reg_targetsrD   K   s   D &&+"===EBFF+++5>>>F5>>>F{aFG,,{aFG,,|A&,q/))JQQQa 
 
 	
 QIT+s## 555006+[1 1   6 
	 !+???>>TUUU#k****Q{##Y/0   '!^^\\1IF66;..    z
array-liker/   r0   r<   r=   sample_weightr>   T)prefer_skip_nested_validationrG   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/   r0   NrL   )rD   r   npaverageabsr9   r:   )r<   r=   rG   r>   rB   output_errorss         rC   r   r      s    @ +=+ +'FFFK FFM:::Jrvfvo66TUVVVM+s## ,&&  ---K:m[9999rE   r-   both)closed)r<   r=   rG   alphar>         ?rG   rU   r>   c                   t          | ||          \  }} }}t          | ||           | |z
  }|dk                        |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-   rK   r/   r0   NrN   )rD   r   astyper,   rO   rP   r9   r:   )
r<   r=   rG   rU   r>   rB   diffsignlossrR   s
             rC   r   r      s    N +=+ +'FFFK FFM:::F?DAIdj))D4<$!e)D!9D!@@DJt]CCCM+s## |(C(C+s## 7H(H(H:m[9999rE   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   rK   r/   r0   NrN   )rD   r   rO   finfofloat64epsrQ   maximumrP   r9   r:   )r<   r=   rG   r>   rB   epsilonmaperR   s           rC   r   r   A  s    \ +=+ +'FFFK FFM:::hrz""&G6&6/""RZv%H%HHDJt]CCCM+s## ,&&  ---K:m[9999rE   
deprecatedboolean)r<   r=   rG   r>   squared)rG   r>   rf   c                j   |dk    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...)
    rd   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'.rI   r   r   )rM   rL   r/   r0   NrN   )
warningswarnFutureWarningr   rD   r   rO   rP   r9   r:   )r<   r=   rG   r>   rf   rB   rR   s          rC   r   r     s    V ,-
 	
 	
 	
  	*m    +=+ +'FFFK FFM:::JA5A}UUUM+s## ,&&  ---K:m[9999rE   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/   rI   r0   NrN   )rO   sqrtr   r9   r:   rP   )r<   r=   rG   r>   rR   s        rC   r   r   
  s|    t GF-\	
 	
 	
 M +s## ,&&  ---K:m[9999rE   c                   |dk    r/t          j        dt                     |st          | |||          S t	          | ||          \  }} }}t          | ||           | dk                                     s|dk                                     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...)
    rd   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'.rI   r   zSMean Squared Logarithmic Error cannot be used when targets contain negative values.)rh   ri   rj   r   rD   r   anyr7   r   rO   log1p)r<   r=   rG   r>   rf   rB   s         rC   r   r   T  s   \ ,1
 	
 	
 	
  	.m    +=+ +'FFFK FFM:::
 
fqj--// 
/
 
 	

 

#	   rE   c                <   t          | ||          \  }} }}t          | ||           | dk                                     s|dk                                     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.rI   )rD   r   rn   r7   r   rO   ro   )r<   r=   rG   r>   r?   s        rC   r   r     s    p &8%T%T"Avv{FFM:::
 
fqj--// 
/
 
 	

 #

#	   rE   )r<   r=   r>   rG   )r>   rG   c                l   t          | ||          \  }} }}|,t          j        t          j        || z
            d          }n6t	          ||          }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   rM   rG   r/   r0   rN   )	rD   rO   medianrQ   r   r   r9   r:   rP   )r<   r=   r>   rG   rB   rR   s         rC   r   r     s    B +=+ +'FFFK 	"&&"9"9BBB,]FCC,F6F?##=
 
 
 +s## ,&&  ---K:m[9999rE   c                    | j         }|dk    }|s	d| |z  z
  }	nD| dk    }
|                    |g||          }	||
z  }d| |         ||         z  z
  |	|<   d|	|
| z  <   t          |t                    r1|dk    r|	S |dk    rd}n"|dk    r|}|                    |          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/   r0   Nr1   rN   )r,   onesr9   r:   rn   r   r   float)	numeratordenominatorr@   r>   force_finiter*   rv   r,   nonzero_denominatoroutput_scoresnonzero_numeratorvalid_scoreavg_weightsresults                 rC   _assemble_r2_explained_variancer   b  s6    OE%* FY45%N F%HH),==%&k"[%==&
k" CF'+>*>>?+s## ",&&  ---KK///%K66-.. # #!m[999FF||qV}}MrE   >   r/   r0   r1   )r<   r=   rG   r>   r|   )rG   r>   r|   c          
         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   rK   r   r-   Nrz   r{   r@   r>   r|   r*   rv   )rD   r   rO   rP   r   r6   r	   )
r<   r=   rG   r>   r|   rB   
y_diff_avgrz   
y_true_avgr{   s
             rC   r    r      s    h +=+ +'FFFK FFM:::FVO]KKKJ
	&:	%!+]  I FMBBBJ*fz1a7UVWWWK*,q/!  #	 	 	 	rE   c          
      L   t          | |||          \  }}}t          | |||          }t          | ||||          \  }} }}t          | ||           t	          |          dk     r+d}	t          j        |	t                     t          d          S |t          ||          }|dddf         }
nd}
|
                    |
| |z
  dz  z  d	
          }|
                    |
| 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   rr   )rM   rL   r*   r-   r   )r
   r   rD   r   r   rh   ri   r   ry   r   sumr   r   r6   )r<   r=   rG   r>   r|   r*   r?   device_r,   msgweightrz   r{   s                rC   r   r   !  su   Z .{ NB7 *&&-BOOOE%75R& & &"Avv{ FFM:::FaIc1222U|| $]%@@@qqq$w'v&Q 66Q??I&&&8FMbQQQQVWWW   K
 +,q/!   rE   )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)
    Nr3   z&Multioutput not supported in max_error)rD   r7   rO   maxrQ   )r<   r=   rB   r?   s       rC   r   r     sX    D !3664 H HFFFA)))ABBB6"&&))***rE   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  }nhd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-   rN   )rO   powerra   r   logrP   )r<   r=   rG   r   pdevs         rC   _mean_tweedie_deviancer     s   A1uuHRZ**AE22q1uQ6GHrxA...!a%89hvq1u%%Q/0

 
a1$	
a5&11F:VCD	
a26&6/**Vf_<q@AHVQU##A!a%'89rxA...!a%89hvq1u%%Q/0
 :c=1111rE   rightleft)r<   r=   rG   r   rG   r   c                   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                                    rt	          |dz             n|dk    rnd	|cxk    rd
k     rFn nC| dk                                     s|dk                                    rt	          |dz             nP|d
k    rC| dk                                    s|dk                                    rt	          |dz             n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   r3   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   )
rD   rO   r_   float32r7   r   r   newaxisrn   r   )r<   r=   rG   r   rB   r?   messages          rC   r!   r!     s   x !3RZ$<! ! !FFFA )))MNNNFFM::: $]33%aaam4TTTTGqyyaK 	DW'BBCCC	D	!	
eaQJ 	W&A+!2!2!4!4 	WW'UUVVV	W	!aK 	J6Q;"3"3"5"5 	JW'HHIII	J !m5   rE   r<   r=   rG   rs   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      rC   r"   r"   z  s    P !}TUVVVVrE   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      rC   r#   r#     s    R !}TUVVVVrE   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   r3   z-Multioutput not supported in d2_tweedie_scorer   9D^2 score is not well-defined with less than two samples.r   r   rN   r-   )rD   rO   r_   r   r7   r   rh   ri   r   ry   squeezer!   rP   r   )
r<   r=   rG   r   rB   r?   r   rz   y_avgr{   s
             rC   r$   r$     s   r !3RZ$<! ! !FFFA )))HIIIFaIc1222U||Z''F););FF%m5  I Jv}555E(]%  K y;&&&rE   c                8   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          }nGt          ||           }t          j	        t          | ||dz            t          |           d
f          }t          | |||d          }	|dk    }
|	dk    }|
|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/   rW   Nd   r   )qrM   r-   )rG   
percentilerw   rN   )rD   r   r   rh   ri   r   ry   r   rO   tiler   r;   r   r   rx   r6   r9   r:   rP   )r<   r=   rG   rU   r>   rB   r   rz   
y_quantiler{   r   r}   r   r~   r   s                  rC   r%   r%   B  s   x +=+ +'FFFK FFM:::FaIc1222U||!#   I WM&ECKa8883v;;:J
 


 -]FCCW m   [[!	
 

 $#   K "Q%*#&99KGFLO,,M!"i&<{;?W&W!XM+>AM#':&::;+s## ",&&   KK!:m[9999rE   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)
    rV   rW   )r%   rF   s       rC   r&   r&     s'    ~ m3K   rE   )r'   N)2__doc__rh   numbersr   numpyrO   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__rD   r   r   r   r   r   r   r   r   r   r    r   r   r   r!   r"   r#   r$   r%   r&    rE   rC   <module>r      sL
   :                  / / / / / /              T S S S S S S S S S S S . . . . . .               *J/ J/ J/ J/Z ..&-"
L2C#DEE|T	  #'   &*7HC: C: C: C: C:L ..&-(4Af5556"
L2C#DEE|T  #'	 	 	 &*BSM: M: M: M:	 	M:` ..&-"
L2C#DEE|T	  #'   &*7HS: S: S: S: S:l ..&-"
L2C#DEE|TF::|n5566	B  #'	 	 	 !]: ]: ]: ]:	 	]:@ ..&-"
L2C#DEE|T	  #'   &*7H>: >: >: >: >:B ..&-"
L2C#DEE|TF::|n5566	B  #'	 	 	 !c c c c	 	cL ..&-"
L2C#DEE|T	  #'   &*7H= = = = =@ .."
L2C#DEE|T&-	  #'   $5DI: I: I: I: I:X/ / /d ..&-JMMMNN
 #	 	 #'  " !} } } } }@ ..&-JMMMNN

 #
 
 #'  $ !c c c c cL ..  #'  + + +B2 2 2: ..&-HT47333HT1d6222
	  #'   <@q Q Q Q Q Qh ..&- 
 #'   <@  W  W  W  W  WF ..&- 
 #'   :> !W !W !W !W !WH ..&-HT47333HT1d6222
	  #'   7;! b' b' b' b' b'J ..&-(4Af5556J&7899
	 	 #'   &*BSH: H: H: H: H:V ..&-J&7899
	  #'   &*7HU U U U U U UrE   