Date Parsing as a Model Layer in Tensorflow-Keras

Basically, training my model after some feature engineering from the raw data. The feature engineering includes converting an Order_date column (from a pandas dataframe having dtype: Object) to four separate features, i.e. date in month, month, year and weekday. See the following screenshot.

Screenshot from 2021-07-20 18-38-56

It is a simple task using pandas functionalities, but recently, I read from some keras and tensorflow documentation that the best models are end to end, i.e. take the raw data, then implement all feature engineering as layers before the neural network. So trying to adhere to that philosophy, but being somewhat noob in tensorflow api, not sure if this is possible here. I also looked up the tf.data pipelines and methods available tf.feature_column, but seems they do not fit my use case. So any help regarding the cleanest way to achieve it while sticking with tensorflow layer philosophy?

I can potentially use a custom layer subclassing from the base layer class which takes a batch of yyyy-mm-dd strings and spits out the four features as output, using pandas timestamp (which I want to avoid) and actually have not implemented that yet. There should still be a cleaner way using tf APIs.

I think you want something like the second bullet point in:

1 Like