Skip to content

Feature request: add absolute=True/False to regression metric mean_absolute_error #17853

@raybellwaves

Description

@raybellwaves

Apologies if this has been brought up before. I did have a quick check of https://github.com/scikit-learn/scikit-learn/issues?q=is%3Aissue+sort%3Aupdated-desc+mean+error+is%3Aclosed+label%3Amodule%3Ametrics

Describe the workflow you want to enable

I am interested in the sign of the error and if possible I would rather do it in scikit-learn than numpy.

mean_absolute_error(y_true, y_pred, absolute=False) to return np.average(y_pred - y_true)
mean_absolute_error(y_true, y_pred) returns same as before

Describe your proposed solution

Adding the absolute=False will update https://github.com/scikit-learn/scikit-learn/blob/fd237278e/sklearn/metrics/_regression.py#L122L190 to be

                           absolute=True, sample_weight=None,
                           multioutput='uniform_average'):
...
    Parameters
    ----------
    absolute: bool
        Return MAE or ME.
...
    if absolute:
        output_errors = np.average(np.abs(y_pred - y_true),
                                   weights=sample_weight, axis=0)
    else:
        output_errors = np.average(y_pred - y_true,
                                   weights=sample_weight, axis=0)

Describe alternatives you've considered, if relevant

Not sure if a new metric is needed i.e. mean_error.

I believe this approach of a new argument was applied to mean_squared_error (squared=True). See #12895

Additional context

If this is of interest I'll be happy to work on this during the scipy sprint.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions