skills/timeseries/multi-lag-target-features/SKILL.md
Generate lag features for multiple targets over N days by shifting evaluation dates and self-joining per entity, creating a wide feature matrix of past target values
npx skillsauth add wenmin-wu/ds-skills timeseries-multi-lag-target-featuresInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
For entity-level time-series forecasting with multiple targets, lagging each target by 1..N days and pivoting into separate columns creates a dense feature matrix capturing recent history. The self-join approach shifts the date column by the lag amount and merges back on (entity_id, date), producing columns like target1_1, target1_2, ..., target4_20 — 80 features for 4 targets x 20 lags.
from datetime import timedelta
TARGETS = ["target1", "target2", "target3", "target4"]
LAGS = list(range(1, 21))
def add_lag(df, lag):
lagged = df[["entity_id", "date"] + TARGETS].copy()
lagged["date"] = lagged["date"] + timedelta(days=lag)
df = df.merge(lagged, on=["entity_id", "date"], suffixes=("", f"_{lag}"), how="left")
return df
for lag in LAGS:
df = add_lag(df, lag)
lag_cols = [f"{t}_{l}" for l in reversed(LAGS) for t in TARGETS]
shift() within groups instead of mergedata-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF