How can Tensorflow be used with Estimators to split the iris dataset?

TensorflowServer Side ProgrammingProgramming

The key features/column names from the iris dataset can be extracted, by deleting the irrelevant features. This can be done using the ‘pop’ method.

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

We will use the Keras Sequential API, which is helpful in building a sequential model that is used to work with a plain stack of layers, where every layer has exactly one input tensor and one output tensor.

A neural network that contains at least one layer is known as a convolutional layer. We can use the Convolutional Neural Network to build learning model. 

TensorFlow Text contains collection of text related classes and ops that can be used with TensorFlow 2.0. The TensorFlow Text can be used to preprocess sequence modelling.

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.

An Estimator is TensorFlow's high-level representation of a complete model. It is designed for easy scaling and asynchronous training.


print("Species feature is deleted")
train_y = train.pop('Species')
test_y = test.pop('Species')
print("After deleting the column, sample data is being displayed")

Code credit −


Species feature is deleted
After deleting the column, sample data is being displayed
SepalLength SepalWidth PetalLength PetalWidth
0  6.4  2.8  5.6  2.2
1  5.0  2.3  3.3  1.0
2  4.9  2.5  4.5  1.7
3  4.9  3.1  1.5  0.1
4  5.7  3.8  1.7  0.3


  • The ‘species’ feature is deleted.
  • The remaining columns are displayed on the console along with sample data.
Published on 12-Feb-2021 16:06:23