- 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 with Estimators for feature engineering the model?
Tensorflow can be used with estimators for feature engineering by first defining the columns and iterating through the categorical columns. The unique names of features are obtained, and is appended to an empty list.
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. Estimators use feature columns to describe how the model would interpret the raw input features. An Estimator expects a vector of numeric inputs, and feature columns will help describe how the model should convert every feature in the dataset.
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.
The linear estimator uses as well as numeric and categorical features. Feature columns work with all the TensorFlow estimators. Their goal is to define the features used for modeling. They also have feature engineering capabilities like one-hot-encoding, normalization, and bucketization.
Example
print("Feature engineering") CATEGORICAL_COLUMNS = ['sex', 'n_siblings_spouses', 'parch', 'class', 'deck', 'embark_town', 'alone'] NUMERIC_COLUMNS = ['age', 'fare'] feature_columns = [] print("Iterating through categorical columns") for feature_name in CATEGORICAL_COLUMNS: vocabulary = dftrain[feature_name].unique() feature_columns.append(tf.feature_column.categorical_column_with_vocabulary_list(feature_name, vocabulary)) print("Iterating through numeric columns") for feature_name in NUMERIC_COLUMNS: feature_columns.append(tf.feature_column.numeric_column(feature_name, dtype=tf.float32))
Code credit −https://www.tensorflow.org/tutorials/estimator/linear
Output
Feature engineering Iterating through categorical columns Iterating through numeric columns
Explanation
- Here, feature engineering is performed.
- The columns ar eiterated over, and are appended to a list.
- Related Articles
- How can Tensorflow be used with Estimators to optimize the model?
- How can Tensorflow be used with Estimators to train the model for titanic dataset?
- How can Tensorflow be used with Estimators to evaluate the model using Python?
- How can Tensorflow be used with Estimators to create feature columns and input functions?
- How can Tensorflow and pre-trained model be used for feature extraction?
- How can Tensorflow be used with Estimators to split the iris dataset?
- 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 with Estimators to perform data transformation?
- How can Tensorflow be used with Estimators to display metadata about the dataset?
- How can Tensorflow be used with Estimator to transform the feature column?
- How can Tensorflow be used with Estimators to inspect the titanic dataset using Python?
- How can Tensorflow be used with Estimators to return a two element tuple?
- How can Tensorflow be used with Estimators to visualize the data, and the ROC curve?
- How can Tensorflow be used with Estimators to add a column to the titanic dataset?
