Skip to content

Bug: Not Multiplying by 100 in Mean Absolute Percentage Error #23408

Closed

Description

@ShivKJ

Hi,

I am using Scikit-learn version 1.1.0`.

As I was looking into the implementation of mean_absolute_percentate_error, I found that the implementation is missing multiplication by 100 to convert it into a percentage.

See the code below,

y_type, y_true, y_pred, multioutput = _check_reg_targets(
y_true, y_pred, multioutput
)
check_consistent_length(y_true, y_pred, sample_weight)
epsilon = np.finfo(np.float64).eps
mape = np.abs(y_pred - y_true) / np.maximum(np.abs(y_true), epsilon)
output_errors = np.average(mape, weights=sample_weight, axis=0)
if isinstance(multioutput, str):
if multioutput == "raw_values":
return output_errors
elif multioutput == "uniform_average":
# pass None as weights to np.average: uniform mean
multioutput = None
return np.average(output_errors, weights=multioutput)

I see the corresponding scikit documentation for this metric and there too, multiplication with 100 is missing/avoided.

On wiki, they have mentioned multiplication by 100.

Please check if multiplication by 100 is required?

Activity

  1. added
    Needs Triage
    on May 18, 2022
  2. glemaitre commented on May 18, 2022

    @glemaitre
    Member

    It was done on purpose and documented in the API documentation:

    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
    
  3. ShivKJ commented on May 19, 2022

    @ShivKJ
    Author

    It came as a surprise to me. "Percentage" in function name can cause confusion. Could you let me know the reasoning behind having such behaviour of the function?

  4. glemaitre commented on May 19, 2022

    @glemaitre
    Member

    You can refer to the original PR where it was debated: #15007 (comment)

    I think the reason is that we stick to the Wikipedia definition.

  5. ShivKJ commented on May 19, 2022

    @ShivKJ
    Author

    In the wiki definition, they have used multiplication by 100. Please check.

  6. glemaitre commented on May 19, 2022

    @glemaitre
    Member

    It is multiplied by 100% and not 100:

    image

  7. Bouncner commented on Aug 28, 2024

    @Bouncner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs Triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions