Practice✓ Mathematical
◆ The PatternTurning raw timestamps into predictive signals
Time series features fall into three categories: lag features (past values), rolling statistics (windowed mean/std/min/max), and calendar features (day of week, month, holiday flags). Fourier features encode seasonality as continuous sine/cosine pairs.
// Interactive — feature construction
| Feature Type | Examples | Captures |
|---|---|---|
| Lag features | y(t-1), y(t-7), y(t-30) | Autoregressive patterns |
| Rolling stats | rolling_mean(7), rolling_std(30) | Trend, volatility |
| Calendar | day_of_week, month, is_holiday | Seasonal effects |
| Fourier | sin(2πt/365), cos(2πt/365) | Smooth cyclicality |
# Python — time series features df['lag_1'] = df['y'].shift(1) df['lag_7'] = df['y'].shift(7) df['roll_mean_7'] = df['y'].rolling(7).mean() df['roll_std_30'] = df['y'].rolling(30).std() df['dow'] = df.index.dayofweek df['month'] = df.index.month # Fourier features for yearly seasonality df['sin_365'] = np.sin(2 * np.pi * df.index.dayofyear / 365) df['cos_365'] = np.cos(2 * np.pi * df.index.dayofyear / 365)
Pattern bridge: Lag features are the tabular version of what AR models learn implicitly. Rolling statistics like rolling mean and rolling std are exactly moving averages and Bollinger Bands from technical analysis.