FEATURE ENGINEERING FOR DATES • TEMPORAL DYNAMICS • CYCLICAL ENCODING • LAG FEATURES • TIME SERIES ML •
FEATURE ENGINEERING FOR DATES • TEMPORAL DYNAMICS • CYCLICAL ENCODING • LAG FEATURES • TIME SERIES ML •
← Back to Module 1

Feature Engineering for Dates

Convert static timestamps into dynamic features that capture Seasonality and Trends.

DATE_ENGINEER.py

Tutor Insight:

Raw timestamps like '2026-03-30 15:30:00' are useless for most ML models. We must extract temporal features.

1. The Lagrangian Shift

Lag features are values at prior time steps. If you are predicting sales today, the most important feature is often sales yesterday ($t-1$) or sales last week ($t-7$).

df['lag_1'] = df['target'].shift(1)
df['rolling_mean_7'] = df['target'].shift(1).rolling(window=7).mean()

⚠️ Warning: Never use the current target value in a rolling mean for forecasting; that is "data leakage". Always shift first!

Mission: 24-Hour Cycle

TASK: Use the formula $sin(2 * \pi * x / max\_val)$ to encode the 'hour' feature (0-23) into a cyclical format.

Expert Stats

Total XP:0

Consult A.I.D.E.

"How should I handle holidays? Should they be a binary flag or a proximity score?"

Unlocked Capabilities

🔄
📉
📅

Forecasting Collective

Join 5,000+ Quant researchers and Data Engineers.