Cyclical encoding

Cyclical encoding represents a periodic variable (hour, month, day of the week) by its sine and cosine, so that extreme values are close, like 11 pm and midnight. A plain integer would place these values at opposite ends of the scale, which is misleading.

Example

df['mois_sin'] = np.sin(2 * np.pi * df['mois'] / 12)
df['mois_cos'] = np.cos(2 * np.pi * df['mois'] / 12)

Related concepts

The whole glossary