Following a Tensorflow time series analysis tutorial, I came across a particular way of converting data timestamps into a time-of-day periodic signal, that could help the model interpret the data better than just providing the timestamp.
timestamp_s = date_time.map(pd.Timestamp.timestamp)
day = 24*60*60
year = (365.2425)*day
df['Day sin'] = np.sin(timestamp_s * (2 * np.pi / day))
df['Day cos'] = np.cos(timestamp_s * (2 * np.pi / day))
df['Year sin'] = np.sin(timestamp_s * (2 * np.pi / year))
df['Year cos'] = np.cos(timestamp_s * (2 * np.pi / year))
plt.plot(np.array(df['Day sin'])[:25])
plt.plot(np.array(df['Day cos'])[:25])
plt.xlabel('Time [h]')
plt.title('Time of day signal')
I am not sure I understand how time of day and day of year periodic structure was extracted from the time stamp, so I would appreciate any pointers regarding this.
Lastly, would a simple normalized time_of_day
and day_of_year
extra new columns from date_time
column suffice?