Explore how cyclical features like hour, month, and day-of-week are better represented with sin/cos on the unit circle. Drag the controls to see the dot move around the circle, and compare model performance using raw numeric vs cyclical encoding.
Maps a cyclical scalar x (e.g., hour, month, day‑of‑week) to the unit circle via (cos θ, sin θ) where θ = 2π·x/period. This preserves wrap‑around distances (e.g., 23 and 0 are close). Demo models compare raw numeric vs sin/cos encodings on downstream tasks.
What: This visualizer maps a cyclical value (hour, month, day-of-week, or angle) onto the unit circle as (cos θ, sin θ), where θ = 2π · value / period. The blue point shows the current value and the faded trail shows recent positions as you drag.
Why: Raw integers treat endpoints as far apart (e.g., 23 vs 0) even though they are neighbors on a cycle. Encoding with sin/cos preserves circular geometry, giving models smoother fits, better distance behavior, and more stable decision boundaries.
Purpose: Experiment with the period and noise to see how cyclical structure affects learning. Compare “raw numeric” versus “sin/cos” in the demo below and observe the metrics (R²/MAE for regression, Accuracy/F1 for classification).
How to interpret: Small arc distance on the circle means “close in time/phase,” even if numbers differ a lot. If sin/cos curves look smoother and metrics improve over raw numeric, the cyclical encoding is helping. Use the model toggle to see how linear, tree, and kNN respond to each representation.
Every coffee helps keep the servers running. Every book sale funds the next tool I'm dreaming up. You're not just supporting a site — you're helping me build what developers actually need.