tf.contrib.learn.LinearRegressor

class tf.contrib.learn.LinearRegressor

Linear regressor model.

Train a linear regression model to predict target variable value given observation of feature values.

Example:

education = sparse_column_with_hash_bucket(column_name="education",
                                           hash_bucket_size=1000)
occupation = sparse_column_with_hash_bucket(column_name="occupation",
                                            hash_bucket_size=1000)

education_x_occupation = crossed_column(columns=[education, occupation],
                                        hash_bucket_size=10000)

estimator = LinearRegressor(
    feature_columns=[occupation, education_x_occupation])

# Input builders
def input_fn_train: # returns x, y
  ...
def input_fn_eval: # returns x, y
  ...
estimator.fit(input_fn=input_fn_train)
estimator.evaluate(input_fn=input_fn_eval)
estimator.predict(x=x)

Input of fit and evaluate should have following features, otherwise there will be a KeyError:

  • if weight_column_name is not None: key=weight_column_name, value=a Tensor
  • for column in feature_columns:
    • if isinstance(column, SparseColumn): key=column.name, value=a SparseTensor
    • if isinstance(column, WeightedSparseColumn):
    • if isinstance(column, RealValuedColumn): key=column.name, value=a Tensor - - -
doc_TensorFlow
2016-10-14 13:05:51
Comments
Leave a Comment

Please login to continue.