Why is a cyclical feature like hour of day represented using sine and cosine components?

Quick Overview

A feature engineering question about encoding cyclical values such as hour of day, day of week or month with sine and cosine. Tests whether you can explain what goes wrong with the raw value, why two components are needed, and which models gain from the encoding.

Why is a cyclical feature like hour of day represented using sine and cosine components?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: easy

Interview Round: Other

Why is a cyclical feature like hour of day represented using sine and cosine components? ```hint Look at the wrap-around Compare how far apart the raw encoding puts the last hour of one day and the first hour of the next, and how far apart they really are. ``` ### What a Strong Answer Covers - The problem with the raw integer encoding at the point where the cycle wraps. - The sine and cosine formulas and the geometry they produce. - Why one of the two components alone is not enough. - Which model families gain from the encoding, and its limits for trees and for patterns with several peaks. ### Follow-up Questions - Would you use this encoding for a gradient-boosted tree model? Why or why not? - A linear model has to fit demand that peaks at both the morning and evening commute. How would you extend the encoding? - How would you encode day of month, given that months have different lengths? - Should the sine and cosine columns be standardized like other features?

Overview: A feature engineering question about encoding cyclical values such as hour of day, day of week or month with sine and cosine. Tests whether you can explain what goes wrong with the raw value, why two components are needed, and which models gain from the encoding.

General logo
General
Nov 25, 2026
easyMachine Learning EngineerOtherMachine Learning
0
0

Why is a cyclical feature like hour of day represented using sine and cosine components?

What a Strong Answer Covers Guidance

  • The problem with the raw integer encoding at the point where the cycle wraps.
  • The sine and cosine formulas and the geometry they produce.
  • Why one of the two components alone is not enough.
  • Which model families gain from the encoding, and its limits for trees and for patterns with several peaks.

Follow-up Questions Guidance

  • Would you use this encoding for a gradient-boosted tree model? Why or why not?
  • A linear model has to fit demand that peaks at both the morning and evening commute. How would you extend the encoding?
  • How would you encode day of month, given that months have different lengths?
  • Should the sine and cosine columns be standardized like other features?