All problems
Naive Forecast MAPE
Problem
Compute the mean absolute percentage error of the one-step naive forecast over the last h observations, where each forecast is the previous observation. Each error is 100 * |actual - forecast| / |actual|.
Observations equal to zero are skipped because the percentage error is undefined. Return 0.0 when no valid observation remains or when h is outside the range 1 to n - 1.
Hint
MAPE is undefined at zero actuals, so those points cannot contribute an error.
Test cases
case 1
in: [[100,110,99],2]
expected: 10.1010101010101
case 2
in: [[0,5],1]
expected: 100
case 3
in: [[0,0],1]
expected: 0
case 4
in: [[1,0,5],2]
expected: 100
case 5
in: [[1,2,3],5]
expected: 0
Starter codePython
def naive_mape(series, h):
# Your code here
pass5 test cases · run your code against them in the editor