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.