Numeric Columns
Learn about the numeric feature columns for the ML model's input layer.
We'll cover the following
Chapter Goals:
- Process the numeric feature columns used for the machine learning model’s input layer
A. Model input layer
Our dataset now contains the feature data and label for each observation. In the Model Creation section, we’ll convert the feature data into an input layer for the machine learning model. To do that, we first need to set up the necessary feature columns.
Similar to how the Example spec provided specifications for how to parse each Example object, the feature columns give specifications for how the feature data can be aggregated into an input layer. There are three types of feature columns that we’ll use: numeric columns, indicator columns, and embedding columns.
B. Numeric data
Numeric feature columns are used for the numeric data in our dataset, i.e. the quantifiable data. There are five features that contain numeric data: 'Size'
, 'Temperature'
, 'Fuel_Price'
, 'CPI'
, and 'Unemployment'
. We use the same process to create numeric feature columns for each of these features.
import tensorflow as tfdef add_numeric_columns(feature_columns):numeric_features = ['Size', 'Temperature', 'Fuel_Price', 'CPI', 'Unemployment']for feature_name in numeric_features:feature_col = tf.feature_column.numeric_column(feature_name, shape=())feature_columns.append(feature_col)# Add the numeric feature columns to the list of dataset feature columnsdataset_feature_columns = []add_numeric_columns(dataset_feature_columns)print(dataset_feature_columns)
Get hands-on with 1300+ tech skills courses.