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


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.

Example

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")
train.head()

Code credit −https://www.tensorflow.org/tutorials/estimator/premade#first_things_first

Output

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

Explanation

  • The ‘species’ feature is deleted.
  • The remaining columns are displayed on the console along with sample data.

Updated on: 22-Feb-2021

126 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements