A model is only as smart as the features you give it. In time series, this means extracting the hidden patterns buried in the calendar.
1Calendar Components
The most basic step is extracting Calendar Features from your datetime index. Features like Day of Week, Is Weekend, or Is Holiday are powerful predictors for many industries. For example, electricity demand is significantly lower on weekends, and retail sales spike on holidays. By explicitly giving these features to your model, you allow it to 'learn' these recurring patterns without needing complex time-series logic.
2Temporal Memory
To help a model understand the past, we use Lag Features. A 'Lag 1' feature for today is simply 'Yesterday's Price.' This provides the model with the most recent context. We also use Rolling Window Features, such as a 7-day average or 30-day standard deviation. These features summarize the recent history and help the model distinguish between a temporary spike and a long-term trend change.
3Cyclical Continuity
Time is circular, but numbers are linear. To a standard model, Hour 0 and Hour 23 are as far apart as possible (0 vs 23). However, in reality, they are only one hour apart. Cyclical Encoding solves this by mapping time components to Sine and Cosine coordinates on a circle. This preserves the 'closeness' of December and January, or midnight and 1:00 AM, leading to significantly better model performance on periodic data.
