I'm relatively new to Tensor Flow. What is this feature column and how does it affect the training?
When I implement a code like below, this numeric column is created as a feature column. I would like to understand the use.
feature_columns = [tf.feature_column.numeric_column("x", shape=[1])]
estimator = tf.estimator.LinearRegressor(feature_columns=feature_columns)
x_train = np.array([1., 2., 3., 4.])
y_train = np.array([0., -1., -2., -3.])
x_eval = np.array([2., 5., 8., 1.])
y_eval = np.array([-1.01, -4.1, -7, 0.])
input_fn = tf.estimator.inputs.numpy_input_fn(
{"x": x_train}, y_train, batch_size=4, num_epochs=None, shuffle=True)
train_input_fn = tf.estimator.inputs.numpy_input_fn(
{"x": x_train}, y_train, batch_size=4, num_epochs=1000, shuffle=False)
eval_input_fn = tf.estimator.inputs.numpy_input_fn(
{"x": x_eval}, y_eval, batch_size=4, num_epochs=1000, shuffle=False)
estimator.train(input_fn=input_fn, steps=10000)
train_metrics = estimator.evaluate(input_fn=train_input_fn)
eval_metrics = estimator.evaluate(input_fn=eval_input_fn)
print("\n\ntrain metrics: %r"% train_metrics)
print("eval metrics: %r"% eval_metrics)
Based on what I can glean from the documentation on feature columns, it seems they are used to convert some sort of input data feature into continuous variables that can be used by a regression or neural network model.
For instance, in regression, if we have a categorical variable, it is common to convert this to a set of dummy variables first. tf.feature_column.indicator_column could be used to make this conversion for us. Then we could just feed categorical data in our feed dict, and the conversion to dummy variables would happen internally.
In the case of a numeric_column
, there is no such conversion needed, so the class basically just acts like a tf.placeholder
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With