Introduction
Time-based forecasting differs from regular tabular ML in one very important way: time order is the core. If you do the wrong way to divide data or create features, it's easy to trick yourself with beautiful results that are useless when actually deployed.
Lesson objectives
- Understand the difference between forecasting and regular regression.
- Know how to create basic time features.
- Avoid leakage in time series.
Characteristics of time series
- Data is in previous order.
- There may be trends, seasons, cycles.
- Close observations often depend on each other.
Popular features
- Lag features like sales_t-1, sales_t-7.
- Rolling statistics such as 7-day, 30-day average.
- Calendar features such as days of the week, months, quarters, and holidays.
How to divide data correctly
Doesn't shuffle randomly like regular tabular. Let's divide it along the time axis: train is in the past, validation is closer to the present, test is the latest segment.
Baseline is very important
Before using complex models, compare with a baseline such as the previous period's value, a moving average or the same period last week.
Common mistakes
- Random split time series.
- Create a rolling feature that looks into the future.
- Do not compare with naive baseline.
Practice exercises
- Forecast daily revenue using lag features and a simple tree-based model.
- Compare with baseline of the same period the previous day.
- Write comments when the model learns more signals beyond the baseline.
Completion criteria
- Divide data by time logically.
- Create basic lag and rolling features.
- Compare the model with the time baseline.
Practice step by step (advanced)
- Build train/validation/test on the time axis.
- Create lag features and rolling window features.
- Compare ML model with naive baseline.
- Evaluate by MAE, MAPE and error by stage.
- Test performance at important seasonal milestones.
Artifact should be submitted
- Forecast vs actual chart over time.
- Error table by week or month.
- Comment on seasonal drift and suggest model updates.
Self-test questions
- Why does random split cause serious errors in forecasting?
- When is the baseline over the same period good enough to use immediately?
- Which features easily cause leakage in time series?