
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How can Tensorflow be used to instantiate an estimator using Python?
An estimator can be instantiated using Tensorflow by using the ‘DNNClassifier’ method that is present in ‘estimator’ class of Tensorflow library.
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.
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.
The model is trained using iris data set.
Example
print("Build a DNN that has 2 hidden layers with 30 and 10 hidden nodes each") classifier = tf.estimator.DNNClassifier( feature_columns=my_feature_columns, hidden_units=[30, 10], n_classes=3)
Code credit −https://www.tensorflow.org/tutorials/estimator/premade#first_things_first
Output
Build a DNN that has 2 hidden layers with 30 and 10 hidden nodes each INFO:tensorflow:Using default config. WARNING:tensorflow:Using temporary folder as model directory: /tmp/tmpdh8866zb INFO:tensorflow:Using config: {'_model_dir': '/tmp/tmpdh8866zb', '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': None, '_save_checkpoints_secs': 600, '_session_config': allow_soft_placement: true graph_options { rewrite_options { meta_optimizer_iterations: ONE } } , '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_log_step_count_steps': 100, '_train_distribute': None, '_device_fn': None, '_protocol': None, '_eval_distribute': None, '_experimental_distribute': None, '_experimental_max_worker_delay_secs': None, '_session_creation_timeout_secs': 7200, '_checkpoint_save_graph_def': True, '_service': None, '_cluster_spec': ClusterSpec({}), '_task_type': 'worker', '_task_id': 0, '_global_id_in_cluster': 0, '_master': '', '_evaluation_master': '', '_is_chief': True, '_num_ps_replicas': 0, '_num_worker_replicas': 1}
Explanation
- The Iris problem is considered as classification problem.
- Tensorflow comes with many pre-made classifier Estimators, which includes −
- tf.estimator.DNNClassifier for deep models which perform multi-class classification.
- tf.estimator.DNNLinearCombinedClassifier for wide & deep models.
- tf.estimator.LinearClassifier for classifiers based on linear models.
- For Iris problem, we use tf.estimator.
- Related Articles
- How can Tensorflow be used with Estimator to compile the model using Python?
- How can Tensorflow be used with Estimator to predict the output using Python?
- How can Tensorflow be used with Estimator to transform the feature column?
- How can Tensorflow be used with premade estimator to download the Iris dataset?
- How can Tensorflow be used with Estimator to make predictions from trained model?
- How can Tensorflow be used with Estimator to show a sample of the data using boosted trees?
- How can Tensorflow be used to compose layers using Python?
- How can Tensorflow and Estimator be used to view all feature column transformations at once?
- How can Tensorflow and Estimator be used to find the ROC curve on titanic dataset?
- How can Tensorflow be used to visualize the data using Python?
- How can Tensorflow be used to standardize the data using Python?
- How can Tensorflow be used to compile the model using Python?
- How can Tensorflow be used to train the model using Python?
- How can Tensorflow be used to visualize training results using Python?
- How can Tensorflow be used to decode the predictions using Python?
