Skip to content

Instantly share code, notes, and snippets.

@erykml
Created July 28, 2022 20:27
Show Gist options
  • Save erykml/0fa1aabdf55f9682bdddb4db287e3b70 to your computer and use it in GitHub Desktop.
Save erykml/0fa1aabdf55f9682bdddb4db287e3b70 to your computer and use it in GitHub Desktop.
X_2 = X.copy()
X_2["month"] = X_2.index.month
X_2["month_sin"] = sin_transformer(12).fit_transform(X_2)["month"]
X_2["month_cos"] = cos_transformer(12).fit_transform(X_2)["month"]
X_2["day_sin"] = sin_transformer(365).fit_transform(X_2)["day_of_year"]
X_2["day_cos"] = cos_transformer(365).fit_transform(X_2)["day_of_year"]
fig, ax = plt.subplots(2, 1, sharex=True, figsize=(16,8))
X_2[["month_sin", "month_cos"]].plot(ax=ax[0])
X_2[["day_sin", "day_cos"]].plot(ax=ax[1])
plt.suptitle("Cyclical encoding with sine/cosine transformation");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment