Creating Feature Engineering Flow Graphs in Keras

Fernando Nieuwveldt
3 min readSep 2, 2022

--

In this blog we will look at creating plots while building up our feature engineering flow graph natively with Keras layers. At each step we will plot the status of our feature graph. At the end we will have an informative graph of how our features were created and how they flow into each other. We will also see the interdependency of the features or steps. For illustration purposes we will utilise Lambda layers too easily create new feature layers. The code here is similar to this blog post. For this article we only focus on creating informative feature graphs.

(Click on the Graphs to enlarge)

We will use the same dataset used in the article mentioned above.

Next we define a function to create our Input layers:

To create our feature graphs we need a Keras model object with inputs and outputs. So far we only have the Input layer so both our inputs and outputs will be the feature layer inputs:

Feature Engineering with Keras Lambda Layers

Lets define the feature engineering functions:(The engineered features are only for illustration purposes)

Create custom Feature Engineering Layer

Visualise the Feature Engineering Layers

So far we have our input layer where the inputs feeds into the different Lambda layers. Below is our feature graph we have thus far. Note that some of the input layer’s features does not feed into any other layers. We will add this in the next section. Our inputs to the network is still our feature layer inputs, but our outputs of the network is our feature layer computed with the Lambda layers:

Combine all feature to create a complete Feature Layer:

Lets combine the layers

Visualising the Feature Layer Graph

This our complete Feature Engineering Flow Graph. This is a good way to see if you apply certain preprocessing layers for example the batch norm to the correct features. Initially I had the categorical features batch normalised as well which I noticed when looking at my feature graph. In the below graph only the numerical were normalised. And only after they are normalised the categorical and numerical features gets joined as our complete feature layer.

For completeness we will train the model to show that everything works as expected:

The complete network graph:

--

--

Fernando Nieuwveldt
Fernando Nieuwveldt

Written by Fernando Nieuwveldt

I am an ML Engineer | Data scientist with interests in Deep learning and building systems and software for ML. https://www.linkedin.com/in/fernandonieuwveldt

No responses yet