0

I am trying to understand sklearn's new MAPE function. It is mentioned in the documentation that

we do not represent the output as a percentage in range [0, 100]. Instead, we represent it in range [0, 1/eps]. Read more in the User Guide.

What is eps? And how can I possibly convert the values obtained from this MAPE to percentage?

sklearn MAPE documentation formula

desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • Related: [Value for epsilon in Python](https://stackoverflow.com/q/9528421/11082165) and [machine epsilon](https://en.wikipedia.org/wiki/Machine_epsilon). – Brian61354270 Nov 05 '21 at 23:56

1 Answers1

1

The User Guide link that you already know about explains that "ε is an arbitrary small yet strictly positive number to avoid undefined results when y is zero", but it doesn't state what that value actually is.

You can find the definition in the code to be:

    epsilon = np.finfo(np.float64).eps

which is the smallest positive 64 bit floating point number such that 1 + eps ≠ 1. The value is 2⁻⁵² ≈ 2.22e-16. (See the documentation for numpy.finfo for more information.)

To convert to a percentage, just multiply the return value of mean_absolute_percentage_error by 100.


Note: The comment "we do not represent the output as a percentage in range [0, 100]" is potentially misleading. When expressed as a percentage by multiplying by 100, the MAPE will not necessarily be in the range [0, 100]. For example, if the data is, say, y_true = [1, 1, 1] and y_pred = [1, 4, 2.5], the MAPE computed by

mean_absolute_percentage_error(y_true, y_pred)

is 1.5, which expressed as a percentage is 150%. I think the intent of the comment is to make clear that--despite what the name might imply--they don't multiply by 100, so the result is a fraction, not a percentage. That fraction can certainly be greater than 1, and so the percentage can be greater than 100.

Warren Weckesser
  • 110,654
  • 19
  • 194
  • 214