- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# How can Tensorflow be used to train and evaluate the titanic dataset?

Tensorflow can be used to train and evaluate the titanic dataset using the ‘train’ method and the ‘evaluate’ method respectively.

**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. 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

linear_est = tf.estimator.LinearClassifier(feature_columns) print("The model is being trained") linear_est.train(train_input_fn, max_steps=100) print("The model is being evaluated") result = linear_est.evaluate(eval_input_fn) clear_output() print(pd.Series(result))

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

## Output

accuracy 0.765152 accuracy_baseline 0.625000 auc 0.832844 auc_precision_recall 0.789631 average_loss 0.478908 label/mean 0.375000 loss 0.478908 precision 0.703297 prediction/mean 0.350790 recall 0.646465 global_step 100.000000 dtype: float64

## Explanation

- The model is initialized.
- The features and hyperparameters are also mentioned.
- The training data is fed to the model with the help of train_input_fn.
- The model is trained using the train function.
- The model performance is determined using the evaluation set.
- The dfeval DataFrame is used to determine the performance.
- The predictions are verified by checking the labels from y_eval array.
- Before a Boosted Trees model is trained, a linear classifier is trained.
- This is done, i.e starting with a simple model to establish a benchmark.

- Related Articles
- How can Tensorflow be used with Estimators to train the model for titanic dataset?
- How can Tensorflow and Estimators be used to predict the output of the titanic dataset?
- How can Tensorflow and Estimator be used to find the ROC curve on titanic dataset?
- How can Tensorflow be used with Estimators to inspect the titanic dataset using Python?
- How can Tensorflow be used to train the Illiad dataset using Python?
- How can Tensorflow be used with Estimators to add a column to the titanic dataset?
- How can Tensorflow be used with Estimators to inspect a specific column of titanic dataset?
- How can TensorFlow be used to train the model for Fashion MNIST dataset in Python?
- How can Tensorflow and Estimator be used with Boosted trees to train and evaluate the model?
- How can Tensorflow be used to train the model with the stackoverflow question dataset using Python?
- How can TensorFlow be used to define a loss function, an optimizer, train the model and evaluate it on the IMDB dataset in Python?
- How can Tensorflow be used with Estimators to explore the titanic data?
- How can Tensorflow be used with estimators to visualize the titanic data?
- How can Tensorflow be used to standardize the flower dataset?
- How can Tensorflow and Python be used to verify the CIFAR dataset?