Calculator Inputs
Formula Used
Lag feature: Lag_k(t) = x(t - k) Difference: Δ_k(t) = x(t) - x(t - k) Percentage change: ((x(t) - x(t - k)) / x(t - k)) × 100 Ratio: x(t) / x(t - k) Log difference: ln(x(t)) - ln(x(t - k)) Rolling mean: sum of selected past values / window size
A lag feature shifts earlier values into the current row. It gives models access to historical behavior. Grouping prevents unrelated sequences from sharing values.
How to Use
- Paste time-series data or upload a CSV file.
- Identify the value, date, and optional group columns.
- Enter lag values or enable the range generator.
- Select transformations and rolling statistics.
- Choose a missing-value strategy and dataset split.
- Generate, inspect, copy, or download the results.
Keep observations in their real chronological order. Exclude current values from predictive rolling features. Review leakage warnings before training any forecasting model.
Example Data
| Date | Group | Value | Lag 1 | Difference 1 |
|---|---|---|---|---|
| 2026-01-01 | A | 120 | Missing | Missing |
| 2026-01-02 | A | 124 | 120 | 4 |
| 2026-01-03 | A | 121 | 124 | -3 |
The first row has no earlier observation. Its first lag must therefore remain missing. Later rows receive values from the previous sequence position.
Frequently Asked Questions
What is a lag feature?
It is an earlier observation aligned with a later row. Models use it to learn temporal dependence. Each lag represents a specific historical distance.
Why do lag features create missing values?
Early rows lack enough previous observations for every lag. Larger lags create more initial missing cells. Choose a suitable filling or removal strategy.
Can I calculate several lags together?
Yes, enter multiple integers separated by commas or spaces. The range generator adds regular lag intervals. Duplicate values are removed automatically.
How are grouped lags handled?
Each group receives its own independent sequence. Values never shift across different group labels. Sort groups correctly before creating features.
What causes target leakage?
Leakage occurs when future information enters training features. Lead values are a common source. Past-only rolling windows reduce this risk.
Which lag should I select?
Use domain cycles, autocorrelation, and validation performance together. Daily data may use weekly seasonal lags. Test candidates on future time periods.
Are rolling features different from lags?
A lag stores one historical observation. A rolling feature summarizes several observations. Both can describe short-term and seasonal behavior.
Should I split data before lagging?
Create features with strict chronological controls and inspect boundaries. Never use future test values for training rows. Preserve realistic forecasting conditions throughout evaluation.
Can irregular timestamps be used?
Yes, but row-based lags represent observation positions. They may not represent equal time intervals. Resample externally when fixed intervals are required.