- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions

# How can Tensorflow be used with abalone dataset to build a sequential model?

A sequential model can be built in Keras using the ‘Sequential’ method. The number and type of layers are specified inside this method.

**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 sequential model is being built") abalone_model = tf.keras.Sequential([ layers.Dense(64), layers.Dense(1) ]) abalone_model.compile(loss = tf.losses.MeanSquaredError(),optimizer = tf.optimizers.Adam()) print("The data is being fit to the model") abalone_model.fit(abalone_features, abalone_labels, epochs=10)

Code credit: https://www.tensorflow.org/tutorials/load_data/csv

## Output

The sequential model is being built The data is being fit to the model Epoch 1/10 104/104 [==============================] - 0s 963us/step - loss: 84.2213 Epoch 2/10 104/104 [==============================] - 0s 924us/step - loss: 16.0268 Epoch 3/10 104/104 [==============================] - 0s 860us/step - loss: 9.4125 Epoch 4/10 104/104 [==============================] - 0s 898us/step - loss: 8.9159 Epoch 5/10 104/104 [==============================] - 0s 912us/step - loss: 7.9076 Epoch 6/10 104/104 [==============================] - 0s 936us/step - loss: 6.8316 Epoch 7/10 104/104 [==============================] - 0s 992us/step - loss: 7.1021 Epoch 8/10 104/104 [==============================] - 0s 1ms/step - loss: 7.0550 Epoch 9/10 104/104 [==============================] - 0s 1ms/step - loss: 6.2762 Epoch 10/10 104/104 [==============================] - 0s 883us/step - loss: 6.5584 <tensorflow.python.keras.callbacks.History at 0x7fda82a35160>

## Explanation

- A regression model is built to predict the 'age' column of the abalone dataset.
- A sequential model is built, since there is a single input tensor.
- The model is compiled (trained), and then the features and labels are passed to the 'Model.fit' method.

- Related Articles
- How can Tensorflow be used to build a normalization layer for the abalone dataset?
- How can Tensorflow be used with pre-trained model to build the training and validation dataset?
- How can Tensorflow be used to display sample data from abalone dataset?
- How can TensorFlow be used to build the model for Fashion MNIST dataset in Python?
- How can Tensorflow be used to load the csv data from abalone dataset?
- How can a sequential model be built on Auto MPG dataset using TensorFlow?
- How can Tensorflow be used to create a sequential model using Python?
- How can Tensorflow be used with flower dataset to continue training the model?
- How can Tensorflow be used to define a model for MNIST dataset?
- How can TensorFlow be used with keras.Model to track the variables defined using sequential model?
- How can Tensorflow be used with Estimators to train the model for titanic dataset?
- How can Tensorflow be used to download the flower dataset using keras sequential API?
- How can Tensorflow be used to explore the flower dataset using keras sequential API?
- How Tensorflow is used with Estimators to build a linear model to load the titanic dataset?
- How can a sequential model be created incrementally with Tensorflow in Python?

Advertisements