#006 TF 2.0 An implementation of a Shallow Neural Network in tf.keras – Moons dataset

#006 TF 2.0 An implementation of a Shallow Neural Network in tf.keras – Moons dataset

In this post we will learn how to make a classification of Moons dataset with a shallow Neural network. The Neural Net we will implemented in TensorFlow 2.0 using Keras API. With the following code we are going to import all libraries that we will need.

First, we will generate a random dataset, then we will split it into train and test set. We will also print dimensions of these datasets.

With the following code we will design a Neural Network. In Keras, the input layer itself is not a layer, but a tensor. It is the starting tensor that we will pass to the first hidden layer. Our shallow Neural Network will have an input of size \(2\), because that is the shape of our training and test sets. This will be the input to the hidden layer with \( 12\) hidden units followed by the second layer with just \(6\) units hidden. An output layer consists of a single neuron.

After creating a model, we need to train its parameters to make it powerful. This is the next step.

When the model is trained, we can evaluate it to see the accuracy and loss values.

Let’s see how loss and accuracy of our predictions change over training epochs.

It is always nice to visually explore how predictions look like. Hence, that would be the next thing to solve. After this, we can visualize the function decision boundary of our model.


In the next post we will learn how to perform a classification using a shallow neural network on Spiral dataset implemented in tf.keras.


More resources on the topic: