Datetime Feature Extraction
A raw timestamp is nearly useless to most models, but it hides rich structure. Extracting calendar parts and cyclical encodings exposes seasonality and routine.
Useful extracted parts
- Calendar fields such as year, month, day, hour, and day of week.
- Flags like is weekend, is holiday, or is business hours.
- Elapsed time since a reference event, such as days since signup.
These let a model learn that sales spike on weekends or that traffic peaks at certain hours.
Cyclical encoding
Hour twenty three and hour zero are adjacent in time but far apart as numbers. Encoding a cyclic field with its sine and cosine places the values on a circle, so the model sees that late night and early morning are close.
Cautions
- Beware of leakage from future timestamps that would not be known at prediction time.
- Time zones and daylight saving shifts can silently corrupt extracted hours.
Key idea
Datetime extraction unpacks timestamps into calendar parts, flags, and cyclical sine cosine encodings, surfacing seasonality while guarding against leakage and time zone errors.