How can Tensorflow be used with Estimators to explore the titanic data?

TensorflowServer Side ProgrammingProgramming

<p>The titanic dataset can be explored using the estimator with Tensorflow by using the &lsquo;head&rsquo; method, the &lsquo;describe&rsquo; method, and the &lsquo;shape&rsquo; method. The head method gives the first few rows of the dataset, and the describe method gives information about the dataset, such as column names, types, mean, variance, standard deviation and so on. The shape method gives the dimensions of the data.</p><p><strong>Read More:</strong> <a class="fr-green" href="https://www.tutorialspoint.com/what-is-tensorflow-and-how-keras-work-with-tensorflow-to-create-neural-networks" rel="nofollow noopener noreferrer" target="_blank">What is TensorFlow and how Keras work with TensorFlow to create Neural Networks?</a></p><p>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.</p><p>A neural network that contains at least one layer is known as a convolutional layer. We can <a class="fr-green" href="https://www.tutorialspoint.com/how-can-a-convolutional-neural-network-be-used-to-build-learning-model" rel="nofollow noopener noreferrer" target="_blank">use the Convolutional Neural Network to build learning model.&nbsp;</a></p><p>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 <a class="fr-green" href="https://www.tutorialspoint.com/how-can-tensorflow-text-be-used-to-preprocess-sequence-modelling" rel="nofollow noopener noreferrer" target="_blank">preprocess sequence modelling.</a></p><p>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.</p><p>An Estimator is TensorFlow&#39;s high-level representation of a complete model. It is designed for easy scaling and asynchronous training.</p><p>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.</p><p>Example</p><pre class="prettyprint notranslate">print(&quot;Sample data is being displayed&quot;) print(dftrain.head()) print(&quot;The metadata about data is being displayed&quot;) print(dftrain.describe()) print(&quot;The dimensions of the data is being displayed&quot;) print(dftrain.shape[0], dfeval.shape[0])</pre><p>Code credit &minus;<a href="%20https%3A//www.tensorflow.org/tutorials/estimator/linear" rel="nofollow" target="_blank">https://www.tensorflow.org/tutorials/estimator/linear</a></p><h2>Output</h2><pre class="result notranslate">Sample data is being displayed &nbsp; &nbsp;sex &nbsp; &nbsp;age &nbsp;n_siblings_spouses parch ... class deck embark_town alone 0 &nbsp;male &nbsp; 22.0 &nbsp;1 0 &nbsp; ... Third unknown Southampton &nbsp; &nbsp; &nbsp;n 1 &nbsp;female 38.0 &nbsp;1 0 &nbsp; ... First C Cherbourg &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;n 2 &nbsp;female 26.0 &nbsp;0 0 &nbsp; ... Third unknown Southampton &nbsp; &nbsp; &nbsp;y 3 &nbsp;female 35.0 &nbsp;1 0 &nbsp; ... First C Southampton &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;n 4 &nbsp;male &nbsp; 28.0 &nbsp;0 0 &nbsp; .. Third unknown Queenstown &nbsp; &nbsp; &nbsp; &nbsp;y [5 rows x 9 columns] The metadata about data is being displayed &nbsp; &nbsp; &nbsp; &nbsp; age &nbsp; &nbsp;n_siblings_spouses &nbsp;parch &nbsp; &nbsp; &nbsp; fare count &nbsp;627.000000 &nbsp;627.000000 &nbsp; 627.000000 &nbsp; 627.000000 mean &nbsp; 29.631308 &nbsp; &nbsp; 0.545455 &nbsp; &nbsp; 0.379585 &nbsp; &nbsp;34.385399 std &nbsp; &nbsp;12.511818 &nbsp; &nbsp; 1.151090 &nbsp; &nbsp; 0.792999 &nbsp; &nbsp;54.597730 min &nbsp; &nbsp; 0.750000 &nbsp; &nbsp; 0.000000 &nbsp; &nbsp; 0.000000 &nbsp; &nbsp; 0.000000 25% &nbsp; &nbsp;23.000000 &nbsp; &nbsp; 0.000000 &nbsp; &nbsp; 0.000000 &nbsp; &nbsp; 7.895800 50% &nbsp; &nbsp;28.000000 &nbsp; &nbsp; 0.000000 &nbsp; &nbsp; 0.000000 &nbsp; &nbsp;15.045800 75% &nbsp; &nbsp;35.000000 &nbsp; &nbsp; 1.000000 &nbsp; &nbsp; 0.000000 &nbsp; &nbsp;31.387500 max &nbsp; &nbsp;80.000000 &nbsp; &nbsp; 8.000000 &nbsp; &nbsp; 5.000000 &nbsp; 512.329200 The dimensions of the data is being displayed 627 264</pre><h2>Explanation</h2><ul class="list"><li><p>Sample data of the titanic dataset is displayed on the console.</p></li><li><p>The describe method is used to provide metadata about the dataset.</p></li><li><p>The shape method gives the dimensions of the dataset.</p></li></ul>
raja
Updated on 22-Feb-2021 10:45:43

Advertisements