Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-348

Drift Forecast Holdout MAE

Problem

Backtest a drift forecast on the last h observations of a series. Estimate the drift from the training prefix, forecast the test suffix as train_last + step * drift for each step, and return the mean absolute error of those h forecasts.

Return 0.0 when h is not positive or when fewer than two observations would remain for training (h greater than n - 2).

Hint

The drift comes only from the training prefix; never use test values to fit it.

Test cases

case 1
in: [[1,2,4,7,11],2]
expected: 2.75
case 2
in: [[10,10,10,10],1]
expected: 0
case 3
in: [[1,2,3],1]
expected: 0
case 4
in: [[1,2],1]
expected: 0
case 5
in: [[1,2,3],5]
expected: 0
Starter codePython
def drift_holdout_mae(series, h):
    # Your code here
    pass

5 test cases · run your code against them in the editor