How can Tensorflow be used with Estimators to visualise the plot of number of males v/s females?


Tensorflow can be used with Estimators to visualise the plot of number of males versus females with the help of ‘matplotlib’ library and ‘show’ 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. 

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. The model is used as a baseline for other algorithms. We use the titanic dataset with the goal of predicting passenger survival, given characteristics such as gender, age, class, etc.

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.

Example

print("Number of females versus males")
print("The predictive feature")
pd.concat([dftrain, y_train], axis=1).groupby('sex').survived.mean().plot(kind='barh').set_xlabel('% survive')
plt.show()

Code credit −https://www.tensorflow.org/tutorials/estimator/boosted_trees

Output

Explanation

  • The number of males and number of females is determined.
  • This is plotted on a graph.
  • This will further be used as a predictive feature.

Updated on: 25-Feb-2021

41 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements