All problems
Drift Forecast at Horizon
Problem
Produce a drift forecast h steps beyond the end of a series. The drift is the average first difference, and the forecast is x[-1] + h * drift.
Return 0.0 for an empty series or a negative horizon, and return the last value when the series has a single observation.
Hint
With a perfectly linear series the drift forecast extends the line exactly.
Test cases
case 1
in: [[1,3,5],2]
expected: 9
case 2
in: [[10,20,30],1]
expected: 40
case 3
in: [[5],3]
expected: 5
case 4
in: [[],2]
expected: 0
Starter codePython
def drift_forecast(series, h):
# Your code here
pass4 test cases · run your code against them in the editor