Cyclical Encoding Visualizer

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.


Unit Circle Encoding
Point = (cos θ, sin θ), θ = 2π · value / period
Current Trail Radial steps Cyclic distance wraps endpoints (e.g., 23 ↔ 0 is close)

About This Tool & Methodology

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.

Learning Outcomes

  • Why raw numeric encodings break cyclic adjacency at boundaries.
  • How sin/cos restore continuity and help linear models learn cyclic patterns.
  • Effect on metrics (R²/MAE/Accuracy/F1) under different periods and noise.

Authorship & Review

  • Author: 8gwifi.org engineering team
  • Reviewed by: Anish Nath
  • Last updated: 2025-11-19

Trust & Privacy

  • Runs entirely in your browser; no data is uploaded.
Model Demo and Metrics Raw numeric vs cyclical sin/cos; smoother decision boundaries with sin/cos
R²: — MAE: — Accuracy: — F1: —
Feature Importances (sin/cos)
sin
0.50
cos
0.50
Model Size vs Performance
Bars: parameters/features (gray) vs performance (blue/green)
Feature & Value
Pick a cyclical feature to encode.
Drag to move around the circle.
Encoding
Typical values: hour=24, month=12, day-of-week=7, angle=360.
Simulate measurement noise in the target.
Task & Model
Mock models to show effect of encoding.

How to interpret

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.

  • Radial lines mark discrete steps; note that 23 and 0 are neighbors on the circle though far numerically.
  • In regression, sin/cos yields smoother fits; raw numeric can break across the seam.
  • In classification, decision boundaries in sin/cos space are smoother than raw integer thresholds.
Tip: One-hot (e.g., 24 for hour) increases model size; sin/cos preserves continuity with just 2 features.

Support This Free Tool

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.

500K+ users
200+ tools
100% private
Privacy Guarantee: Private keys you enter or generate are never stored on our servers. All tools are served over HTTPS.