Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this feature column and how does it affect the training?

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)
like image 615
Sudharshan Srinivasan Avatar asked Sep 26 '17 09:09

Sudharshan Srinivasan


1 Answers

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.

like image 87
nlml Avatar answered Nov 10 '22 23:11

nlml