After normalization, how can Tensorflow be used to train and build the model?

PythonServer Side ProgrammingProgrammingTensorflow

Training and building the model with respect to the abalone data can be done using the ‘compile’ and ‘fit’ methods respectively. The ‘fit’ method also takes the number of epochs as the parameter.

Read More: What is TensorFlow and how Keras work with TensorFlow to create Neural Networks?

We will be using the abalone dataset, which contains a set of measurements of abalone. Abalone is a type of sea snail. The goal is to predict the age based on other measurements.

We are using the Google Colaboratory to run the below code. Google Colab or Colaboratory helps run Python code over the browser and requires zero configuration and free access to GPUs (Graphical Processing Units). Colaboratory has been built on top of Jupyter Notebook.

print("The model is being compiled")
norm_abalone_model.compile(loss = tf.losses.MeanSquaredError(),optimizer = tf.optimizers.Adam())
print("The model is being fit to the data"), abalone_labels, epochs=8)

Code credit:


The model is being compiled
The model is being fit to the data
Epoch 1/8
104/104 [==============================] - 0s 989us/step - loss: 98.3651
Epoch 2/8
104/104 [==============================] - 0s 945us/step - loss: 65.4568
Epoch 3/8
104/104 [==============================] - 0s 922us/step - loss: 21.7297
Epoch 4/8
104/104 [==============================] - 0s 912us/step - loss: 6.3429
Epoch 5/8
104/104 [==============================] - 0s 988us/step - loss: 5.0949
Epoch 6/8
104/104 [==============================] - 0s 958us/step - loss: 4.9868
Epoch 7/8
104/104 [==============================] - 0s 1ms/step - loss: 4.8982
Epoch 8/8
104/104 [==============================] - 0s 1ms/step - loss: 4.7936
<tensorflow.python.keras.callbacks.History at 0x7fda8213c898>


  • Once the normalization layers are built, the model is trained with the training data.
  • Once the training is complete, the features and labels are passed to the data using the '' method.
Updated on 19-Feb-2021 18:09:57