IntermediateData Analysis25 points

Forecast bake-off: naive, average or smoothing?

A budget airline in Madrid needs a quick forecast of daily seat sales. The analysts compare three simple methods on past data and use the winner to forecast tomorrow.

  • Naive: prediction for day t is the value of day t-1.
  • SMA3: the mean of the three days before day t.
  • EMA: ema[0] = x[0], ema[i] = alpha * x[i] + (1 - alpha) * ema[i-1]; the prediction for day t is ema[t-1].

Task: line 1 is alpha (a decimal between 0 and 1). Line 2 is the daily series (at least 4 numbers). Days are numbered from 0. Score each method on days t = 3, 4, ..., n-1 with the mean absolute error (MAE). Print four lines: Naive MAE: a, SMA3 MAE: b, EMA MAE: c (3 decimals each) and Best: NAME. The best method has the lowest MAE; when two MAEs are equal after rounding to 6 decimals, prefer in the order Naive, SMA3, EMA. Then print Forecast for day n: F with 2 decimals, where F is the best method's prediction for the next day (naive: last value, SMA3: mean of the last three values, EMA: the final ema value).

Sample tests

Input

0.5
120 135 128 150 160 155 170 182 176 190

Expected output

Naive MAE: 12.000
SMA3 MAE: 15.714
EMA MAE: 15.468
Best: Naive
Forecast for day 10: 190.00

Input

0.3
50 52 51 53

Expected output

Naive MAE: 2.000
SMA3 MAE: 2.000
EMA MAE: 2.280
Best: Naive
Forecast for day 4: 53.00

Your answer is also checked against 3 hidden tests.

Need a hint?

Write one helper that returns the prediction of a method for day t, then reuse it for scoring and for the final forecast.