All problems
Holt Forecast
Problem
Fit Holt's linear trend model with double exponential smoothing and forecast h steps ahead as level + h * trend. Seed the states with level = x[0] and trend = x[1] - x[0], and use the usual updates new_level = alpha * x[t] + (1 - alpha) * (level + trend) and new_trend = beta * (new_level - level) + (1 - beta) * trend.
A single-element series returns x[0]; an empty series returns 0.0.
Hint
Extrapolate the trend linearly: each extra step adds one more b.
Test cases
case 1
in: [[1,2,3,4,5],0.5,0.5,1]
expected: 6
case 2
in: [[1,2,3,4,5],0.5,0.5,2]
expected: 7
case 3
in: [[10,12,14,16],0.3,0.2,1]
expected: 18
case 4
in: [[10,12,14,16],0.5,0.5,3]
expected: 22
Starter codePython
def holt_forecast(series, alpha, beta, h):
# Your code here
pass4 test cases · run your code against them in the editor