Before you build a forecasting model, you need a number to beat. A baseline is the simplest guess there is. If a model can't do better than it, the model isn't worth building.
Two baselines for weekly revenue: guess each week as last week's revenue, with .shift(1), or as the average of the 4 weeks before, with .rolling(4).mean().shift(1). The .shift(1) at the end matters: without it, a week's average would include that week's own revenue, the very number you're guessing.
mean_absolute_error(real, guesses) from sklearn.metrics gives back how far off the guesses are on average, in the same units as the data. On a small series:
temps = pd.Series([20, 22, 21, 25])
guess = temps.shift(1) # NaN, 20, 22, 21
print(mean_absolute_error(temps.iloc[1:], guess.iloc[1:])) # (2 + 1 + 4) / 3 = 2.333…
The starting code builds table, one row per week with its revenue. Your script must print the last 8 weeks (the same test weeks as in the last lesson) with both guesses, then each baseline's error:
revenue last_week avg_4 date 2026-10-11 2122 3084.0 2428.50 2026-10-18 2451 2122.0 2631.75 2026-10-25 2692 2451.0 2616.00 2026-11-01 3110 2692.0 2587.25 2026-11-08 3549 3110.0 2593.75 2026-11-15 3200 3549.0 2950.50 2026-11-22 2671 3200.0 3137.75 2026-11-29 3090 2671.0 3132.50 Last week MAE: 460.8 Average of 4 MAE: 350.0
Your task: add the columns last_week and avg_4, keep the last 8 rows of table in test, print it with .to_string(), and print the mean absolute error of each guess on those weeks, rounded to 1 decimal.
Assignment
Follow the Coding Tutorial to add the two baseline columns and print their errors on the test weeks.
Hint
Each guess for a week may use only the weeks before it, so both columns end with .shift(1). iloc[-8:] gives back the last 8 rows; they have no NaN, so mean_absolute_error works on them.
Free plan: 30 tutor messages. PRO is unlimited.
