# How can Tensorflow be used with estimators to visualize the titanic data?

TensorflowServer Side ProgrammingProgramming

The titanic dataset can be visualized using the ‘hist’ method which visualizes a histogram. A horizontal bar graph can be generated by specifying the type of graph as ‘barh’.

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.

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. We will train a logistic regression model using the tf.estimator API. 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.

## Example

print("Visualizing the data")
print(dftrain.age.hist(bins=20))
print(dftrain.sex.value_counts().plot(kind='barh'))
print(dftrain['class'].value_counts().plot(kind='barh'))
pd.concat([dftrain, y_train], axis=1).groupby('sex').survived.mean().plot(kind='barh').set_xlabel('% survive')

## Output

Visualizing the data

## Explanation

• The various feature columns of the titanic dataset are visualized.
• They are plotted using the ‘plot’ method.
Published on 12-Feb-2021 16:28:45