What Would We Predict Before Fitting Anything?
Tomorrow's water demand is unknown. Yesterday's demand gives Botie a prediction he can actually make, and a reference that a more complicated forecast should improve on.
13 sections · 4 questions · 2 coding challenges
The arrow keys move between sections too.
Giving a Forecast a Reference to Beat
BOTIE
We will begin by predicting that tomorrow's demand equals the latest observed demand. This is a naive, or persistence, forecast. Our greenhouse record is invented so we can check every prediction. A more complicated method should be compared with this rule on the same future days.
Sources for this history
How Much Water Should Botie Prepare for Tomorrow?
Botie records how many litres the greenhouse uses each day. He needs to prepare tomorrow's supply before tomorrow's measurement exists. The order of these observations now matters: a good explanation of yesterday is not necessarily a useful prediction made the day before.
Let's begin with a rule that requires no fitted coefficients. Predict the most recently observed demand. We can make that prediction, wait for the next day, and record the difference. That small procedure gives every later model a fair starting comparison.
The daily water totals are invented and measured in litres.
Step 1 of 3
Stop at the prediction time
Only three daily totals have arrived. Tomorrow's value must remain outside the input.
Recorded history → prediction time → future
- Recorded
Day 1
10litres
- Recorded
Day 2
12litres
- Recorded
Day 3
11litres
- Predict this day
Day 4
?not observed yet
Keep out of the inputs
Step 2 of 3
Write a prediction before looking
The persistence rule copies the latest available total.
Recorded history → prediction time → future
- Recorded
Day 1
10litres
- Recorded
Day 2
12litres
- Recorded
Day 3
11litres
- Predict this day
Day 4
?not observed yet
Keep out of the inputs
Day 4 prediction
11 litres
Step 3 of 3
Reveal the next observation
Suppose the next day uses 14 litres. Keep the earlier prediction rather than rewriting it after seeing this result.
Day 4 prediction: 11 litres Day 4 observation: 14 litres Absolute error = |14 − 11| = 3 litres
A simple forecast gives a model something to improve on
Absolute values stop positive and negative errors from cancelling. Each pair must describe the same target date.
How far did yesterday's demand leave us from today's?
A saved prediction must stay fixed when its target arrives. Change an observed total below and compare the error with the forecast that was already recorded for that day.
Make the forecast before revealing the next day
BOTIE
Smoothing starts at the first observation, then moves its level halfway toward each newly revealed value. Changing the rule restarts the comparison on the same sequence.
Known days: 1 to 1
Forecast for day 2: 8
BOTIE
Mean absolute forecast error
2
Follow the operations
1. Later observed litres
- 012
- 111
- 214
2. Previously recorded forecasts
- 010
- 112
- 211
3. Subtract
- 02
- 1-1
- 23
4. Absolute value
- 02
- 11
- 23
5. Mean
2
6. Result
2
These are supplied historical forecasts. This calculation does not fit a model or estimate uncertainty.
1. Separate the Forecast Origin From Its Target
The forecast origin is when we make a prediction. The horizon is how far ahead its target lies. A daily one-step forecast predicts the next day's value using information available now.
Keep timestamps, measurement units, and sampling intervals with the series. Missing days are not automatically zero-demand days, and a list of irregular readings is not automatically a daily series.
Origin: end of Tuesday
Horizon: one day
Target: Wednesday's total demandThe information boundary matters more than whether a rule is simple or learned.
2. Try Persistence and a Historical Mean
Persistence copies the latest observation. A historical-mean forecast averages a chosen training history. The first follows recent level changes quickly; the second smooths fluctuations but can lag behind a real change.
Choose the history before seeing the target. For a multiple-day forecast made at one origin, persistence repeats the same last known value for every horizon; it cannot copy future observations.
Known values = [10,12,11]
Persistence forecast = 11
Historical-mean forecast = (10 + 12 + 11) / 3 = 11Agreement on this short record does not make the rules equivalent.
3. Score Predictions That Were Made in Time
Compare each recorded prediction with its later observation. Absolute error keeps the size of a mistake in the original units. Average it over the same target days for every competing method.
Do not confuse fitted residuals with genuine forecast errors. A model fitted using the target's own date has received information unavailable at the earlier origin.
Observations = [10,12,11,14]
One-step persistence predictions = [10,12,11]
Targets = [12,11,14]
MAE = (2 + 1 + 3) / 3 = 2The first observation has no preceding value here, so it is not scored.
One forecast, recorded before the next reading
Suppose the last three daily totals are known. We copy the most recent one before revealing the next day's water use, then measure the size of the miss.
import numpy as np
history = np.array([10., 12., 11.])
forecast = history[-1]
observed_next_day = 14.0
print(float(forecast))
print(float(abs(observed_next_day - forecast)))11.0
3.0The forecast stays at eleven litres when the fourteen-litre observation arrives. The later value belongs in the error calculation, not in the earlier prediction.
4. Keep the Baseline While the Model Changes
Weather, opening hours, and planting schedules might improve the prediction. We will add those kinds of structure gradually, retaining a baseline on the same held-out dates.
A forecast is not a stock decision by itself. Preparing too little water may have a different cost from preparing too much. This lesson establishes point predictions; later evaluation can account for those consequences.
Botie's construction compares the preceding-day predictions and target days supplied separately.
5. Yesterday May Be the Wrong Day to Copy
If greenhouse demand follows a watering schedule, the most recent day in the same schedule position can be a stronger baseline than yesterday. A seasonal-naive forecast repeats that earlier observation.
The seasonal period must describe the actual calendar or process. Seven array positions mean one week only when the record really contains one position per day. Missing days need explicit treatment before we use a positional lag.
6. Forecast a Whole Schedule from One Origin
At a single forecast origin, none of the future observations are available. A multi-step seasonal baseline repeats values from the most recent observed cycle, wrapping around that cycle when necessary.
Keep those forecasts together as one issued forecast. Updating them after tomorrow's reading arrives creates a forecast from a later origin, which should be scored separately.
Repeat a three-day irrigation cycle
The most recent complete cycle used 10, 14 and 8 litres. Botie needs five future daily forecasts now.
import numpy as np
last_cycle = np.array([10.,14.,8.])
horizon = 5
forecast = last_cycle[np.arange(horizon) % len(last_cycle)]
print(forecast.tolist())[10.0, 14.0, 8.0, 10.0, 14.0]The cycle repeats because that is the baseline assumption. A changed watering schedule is a direct reason for the rule to fail.
7. Keep a Separate Error for Each Horizon
A method that is useful tomorrow may be poor a week ahead. Retain origin, target date, horizon, forecast and eventual observation for every prediction. Compare methods only where those keys match.
Inspect peak-demand days and under-prediction as well as overall absolute error. If running out of water is much more costly than carrying excess, the decision may require a quantile or a stock policy rather than a mean forecast alone.
Check yourself
Questions on Parts 1 to 7
Question 1 of 4
What does one-step persistence predict?
Use the information below.
Known daily litres: [10,12,11]. The next day's total is unknown.Try it with Botie
Build with Botie
Write and run Python