Type LinearRegressor
Namespace tensorflow.contrib.learn
Parent Estimator
Interfaces ILinearRegressor
Linear regressor model. THIS CLASS IS DEPRECATED. See
[contrib/learn/README.md](https://www.tensorflow.org/code/tensorflow/contrib/learn/README.md)
for general migration instructions. Train a linear regression model to predict label value given observation of
feature values. Example:
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`):
{key=id column name, value=a `SparseTensor`,
key=weight column name, value=a `SparseTensor`}
- if isinstance(column, `RealValuedColumn`):
key=column.name, value=a `Tensor`
Show Example
sparse_column_a = sparse_column_with_hash_bucket(...) sparse_column_b = sparse_column_with_hash_bucket(...) sparse_feature_a_x_sparse_feature_b = crossed_column(...) estimator = LinearRegressor( feature_columns=[sparse_column_a, sparse_feature_a_x_sparse_feature_b]) # 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)
Methods
Properties
Public static methods
LinearRegressor NewDyn(object feature_columns, object model_dir, object weight_column_name, object optimizer, object gradient_clip_norm, ImplicitContainer<T> enable_centered_bias, ImplicitContainer<T> label_dimension, ImplicitContainer<T> _joint_weights, object config, object feature_engineering_fn)
Construct a `LinearRegressor` estimator object.
Parameters
-
object
feature_columns - An iterable containing all the feature columns used by the model. All items in the set should be instances of classes derived from `FeatureColumn`.
-
object
model_dir - Directory to save model parameters, graph, etc. This can also be used to load checkpoints from the directory into a estimator to continue training a previously saved model.
-
object
weight_column_name - A string defining feature column name representing weights. It is used to down weight or boost examples during training. It will be multiplied by the loss of the example.
-
object
optimizer - An instance of `tf.Optimizer` used to train the model. If `None`, will use an Ftrl optimizer.
-
object
gradient_clip_norm - A `float` > 0. If provided, gradients are clipped
to their global norm with this clipping ratio. See
tf.clip_by_global_norm
for more details. -
ImplicitContainer<T>
enable_centered_bias - A bool. If True, estimator will learn a centered bias variable for each class. Rest of the model structure learns the residual after centered bias.
-
ImplicitContainer<T>
label_dimension - Number of regression targets per example. This is the size of the last dimension of the labels and logits `Tensor` objects (typically, these have shape `[batch_size, label_dimension]`).
-
ImplicitContainer<T>
_joint_weights - If True use a single (possibly partitioned) variable to store the weights. It's faster, but requires all feature columns are sparse and have the 'sum' combiner. Incompatible with SDCAOptimizer.
-
object
config - `RunConfig` object to configure the runtime settings.
-
object
feature_engineering_fn - Feature engineering function. Takes features and labels which are the output of `input_fn` and returns features and labels which will be fed into the model.
Returns
-
LinearRegressor
- A `LinearRegressor` estimator.