How can Tensorflow be used with Estimators to perform data transformation?

TensorflowServer Side ProgrammingProgramming

Data transformation can be performed on the titanic dataset with the help of the ‘DenseFeatures’ method. The columns that need to be transformed, are converted into a Numpy array.

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. 

An Estimator is TensorFlow's high-level representation of a complete model. It is designed for easy scaling and asynchronous training. Estimators use feature columns to describe how the model would interpret the raw input features. An Estimator expects a vector of numeric inputs, and feature columns will help describe how the model should convert every feature in the dataset.

Selecting and using the right set of feature columns is essential to learning an effective model. A feature column can be one of the raw inputs in the original features dict, or a new column created using transformations that are defined on one or multiple base columns.

The linear estimator uses as well as numeric and categorical features. Feature columns work with all the TensorFlow estimators. Their goal is to define the features used for modeling. They also have feature engineering capabilities like one-hot-encoding, normalization, and bucketization.


print("A categorial column is transformed to an indicator column")
gender_column = feature_columns[0]

Code credit −


A categorial column is transformed to an indicator column
array([[1., 0.],
   [0., 1.],
   [0., 1.],
   [1., 0.],
   [1., 0.],
   [1., 0.],
   [0., 1.],
   [0., 1.],
   [1., 0.],
   [1., 0.]], dtype=float32)


  • DenseFeatures accepts dense tensors.

  • This is done to inspect a categorical column which needs to be transformed.

  • It is transformed to an indicator column first before any other computation.

Published on 12-Feb-2021 16:48:34