Solved – Encoding Date/Time (cyclic data) for Neural Networks

deep learningneural networks

How to encode the date and time of an event for a neural network?

I do not have a continuous time series, but some events with date and time, and I analyze some kind of interest. This interest differs between mornings and evenings, and differs between weekdays, and between summer and winter, and before Christmas and Easter and so on. And the events themselves have a strong non-uniform distribution over time (more at day than at night, some kinds more during the week, some more at the weekend).

I tried encoding it as Number of Week in year, as Weekday 1-7 and as Hour of day. But playing around with a sparse autoencoder gave me the impression that my data does not make any sense to a neural network, it could not even reproduce anything near the input even with a big hidden layer. Neither as categorial 0-1 nor as normalized values.

But searching for the encoding of time for a neural network mostly gives information about time series, so im a bit blindfolded by the forest but looking for the tree.

Of course I could look at the data and roughly categorize it more or less despotic. But the concept of Deep Learning seems to sweep away all the hand-crafted manual feature extraction. And the categorization would insert big jumps in a naturally continuous input variable.

My "natural encoding" in my brain is more like a fuzzy membership to some categories like "night", "morning", "weekday" and so on.

To make the whole thing more interesting, also the dependend variable contains those date/time data, but that is a different question.

EDIT:
Somehow related to the cyclic kind of data are some recent questions, like

Which statistical tests are reasonable with this time of day data set?

Best Answer

I was looking for an answer to a similar problem and stumbled on this thread. The sinusoidal encoding idea is explored in this blog post:

Encoding cyclical continuous features - 24-hour time

Ian's answer fully addressed my needs, so I thought about posting it here for future memory.