Encode Hour of Day Cyclically for Google Maps Traffic Features
Last updated: November 29, 2026
Quick Overview
A Google Maps traffic speed model uses hour of day as an input. Explain what goes wrong when hour is fed as an integer from 0 to 23, and show how sine and cosine encoding fixes it.
0
0
0 solved
A Google Maps traffic speed model uses hour of day as an input. Explain what goes wrong when hour is fed as an integer from 0 to 23, and show how sine and cosine encoding fixes it.
Time features appear in nearly every Maps, Ads, and YouTube model. This warm-up question checks whether you think about the geometry a model sees, and whether you know when cyclical encoding helps versus when one-hot or tree models make it unnecessary.
What the Interviewer Expects
- Explains the discontinuity between 23 and 0 in integer encoding
- Derives sine and cosine features with the right period
- Explains why both components are needed
- Compares with one-hot buckets and with tree-based models
- Mentions combining with day of week and holidays
Key Topics to Cover
How to Approach This
- Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
- Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
- Feature engineering is often more impactful than model selection.
- Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
- Handle class imbalance with SMOTE, class weights, or appropriate loss functions.
Possible Follow-up Questions
- Would you still use cyclical encoding with a gradient boosted tree model?
- How would you encode day of week and hour together?
- How do you handle time zones for a global model?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Explore ML Interview PrepSample Answer
Clarify
Ask what model family is used (linear, neural network, or trees), whether time is local to the road segment, and whether weekday and weekend patterns differ. Traffic at 11pm and 1am is similar, while ...
Approach
As an integer, hour 23 and hour 0 are 23 units apart, though they are one hour apart in reality. A linear model must fit a single slope across the day, and a neural network has to spend capacity learn...