PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/tensorflow/g3doc/api_docs/python/functions_and_classes/shard0/tf.contrib.learn.LinearRegressor.md

https://gitlab.com/github-cloud-corporation/tensorflow
Markdown | 326 lines | 197 code | 129 blank | 0 comment | 0 complexity | 5b58e769001052a79973bd80ec6a2ac8 MD5 | raw file
  1. Linear regressor model.
  2. Train a linear regression model to predict target variable value given
  3. observation of feature values.
  4. Example:
  5. ```python
  6. education = sparse_column_with_hash_bucket(column_name="education",
  7. hash_bucket_size=1000)
  8. occupation = sparse_column_with_hash_bucket(column_name="occupation",
  9. hash_bucket_size=1000)
  10. education_x_occupation = crossed_column(columns=[education, occupation],
  11. hash_bucket_size=10000)
  12. estimator = LinearRegressor(
  13. feature_columns=[occupation, education_x_occupation])
  14. # Input builders
  15. def input_fn_train: # returns x, y
  16. ...
  17. def input_fn_eval: # returns x, y
  18. ...
  19. estimator.fit(input_fn=input_fn_train)
  20. estimator.evaluate(input_fn=input_fn_eval)
  21. estimator.predict(x=x)
  22. ```
  23. Input of `fit` and `evaluate` should have following features,
  24. otherwise there will be a KeyError:
  25. * if `weight_column_name` is not `None`:
  26. key=weight_column_name, value=a `Tensor`
  27. * for column in `feature_columns`:
  28. - if isinstance(column, `SparseColumn`):
  29. key=column.name, value=a `SparseTensor`
  30. - if isinstance(column, `WeightedSparseColumn`):
  31. {key=id column name, value=a `SparseTensor`,
  32. key=weight column name, value=a `SparseTensor`}
  33. - if isinstance(column, `RealValuedColumn`):
  34. key=column.name, value=a `Tensor`
  35. - if `feature_columns` is `None`:
  36. input must contains only real valued `Tensor`.
  37. - - -
  38. #### `tf.contrib.learn.LinearRegressor.__init__(feature_columns, model_dir=None, weight_column_name=None, optimizer=None, gradient_clip_norm=None, enable_centered_bias=True, target_dimension=1, config=None)` {#LinearRegressor.__init__}
  39. Construct a `LinearRegressor` estimator object.
  40. ##### Args:
  41. * <b>`feature_columns`</b>: An iterable containing all the feature columns used by
  42. the model. All items in the set should be instances of classes derived
  43. from `FeatureColumn`.
  44. * <b>`model_dir`</b>: Directory to save model parameters, graph, etc. This can
  45. also be used to load checkpoints from the directory into a estimator
  46. to continue training a previously saved model.
  47. * <b>`weight_column_name`</b>: A string defining feature column name representing
  48. weights. It is used to down weight or boost examples during training. It
  49. will be multiplied by the loss of the example.
  50. * <b>`optimizer`</b>: An instance of `tf.Optimizer` used to train the model. If
  51. `None`, will use an Ftrl optimizer.
  52. * <b>`gradient_clip_norm`</b>: A `float` > 0. If provided, gradients are clipped
  53. to their global norm with this clipping ratio. See
  54. `tf.clip_by_global_norm` for more details.
  55. * <b>`enable_centered_bias`</b>: A bool. If True, estimator will learn a centered
  56. bias variable for each class. Rest of the model structure learns the
  57. residual after centered bias.
  58. * <b>`target_dimension`</b>: dimension of the target for multilabels.
  59. * <b>`config`</b>: `RunConfig` object to configure the runtime settings.
  60. ##### Returns:
  61. A `LinearRegressor` estimator.
  62. - - -
  63. #### `tf.contrib.learn.LinearRegressor.bias_` {#LinearRegressor.bias_}
  64. - - -
  65. #### `tf.contrib.learn.LinearRegressor.dnn_bias_` {#LinearRegressor.dnn_bias_}
  66. Returns bias of deep neural network part.
  67. - - -
  68. #### `tf.contrib.learn.LinearRegressor.dnn_weights_` {#LinearRegressor.dnn_weights_}
  69. Returns weights of deep neural network part.
  70. - - -
  71. #### `tf.contrib.learn.LinearRegressor.evaluate(x=None, y=None, input_fn=None, feed_fn=None, batch_size=None, steps=None, metrics=None, name=None)` {#LinearRegressor.evaluate}
  72. See `Evaluable`.
  73. ##### Raises:
  74. * <b>`ValueError`</b>: If at least one of `x` or `y` is provided, and at least one of
  75. `input_fn` or `feed_fn` is provided.
  76. Or if `metrics` is not `None` or `dict`.
  77. - - -
  78. #### `tf.contrib.learn.LinearRegressor.export(export_dir, signature_fn=None, input_fn=default_input_fn, default_batch_size=1, exports_to_keep=None)` {#LinearRegressor.export}
  79. Exports inference graph into given dir.
  80. ##### Args:
  81. * <b>`export_dir`</b>: A string containing a directory to write the exported graph
  82. and checkpoints.
  83. * <b>`signature_fn`</b>: Function that returns a default signature and a named
  84. signature map, given `Tensor` of `Example` strings, `dict` of `Tensor`s
  85. for features and `Tensor` or `dict` of `Tensor`s for predictions.
  86. * <b>`input_fn`</b>: Function that given `Tensor` of `Example` strings, parses it
  87. into features that are then passed to the model.
  88. * <b>`default_batch_size`</b>: Default batch size of the `Example` placeholder.
  89. * <b>`exports_to_keep`</b>: Number of exports to keep.
  90. - - -
  91. #### `tf.contrib.learn.LinearRegressor.fit(x=None, y=None, input_fn=None, steps=None, batch_size=None, monitors=None, max_steps=None)` {#LinearRegressor.fit}
  92. See `Trainable`.
  93. ##### Raises:
  94. * <b>`ValueError`</b>: If `x` or `y` are not `None` while `input_fn` is not `None`.
  95. * <b>`ValueError`</b>: If both `steps` and `max_steps` are not `None`.
  96. - - -
  97. #### `tf.contrib.learn.LinearRegressor.get_params(deep=True)` {#LinearRegressor.get_params}
  98. Get parameters for this estimator.
  99. ##### Args:
  100. * <b>`deep`</b>: boolean, optional
  101. If `True`, will return the parameters for this estimator and
  102. contained subobjects that are estimators.
  103. ##### Returns:
  104. params : mapping of string to any
  105. Parameter names mapped to their values.
  106. - - -
  107. #### `tf.contrib.learn.LinearRegressor.get_variable_names()` {#LinearRegressor.get_variable_names}
  108. Returns list of all variable names in this model.
  109. ##### Returns:
  110. List of names.
  111. - - -
  112. #### `tf.contrib.learn.LinearRegressor.get_variable_value(name)` {#LinearRegressor.get_variable_value}
  113. Returns value of the variable given by name.
  114. ##### Args:
  115. * <b>`name`</b>: string, name of the tensor.
  116. ##### Returns:
  117. Numpy array - value of the tensor.
  118. - - -
  119. #### `tf.contrib.learn.LinearRegressor.linear_bias_` {#LinearRegressor.linear_bias_}
  120. Returns bias of the linear part.
  121. - - -
  122. #### `tf.contrib.learn.LinearRegressor.linear_weights_` {#LinearRegressor.linear_weights_}
  123. Returns weights per feature of the linear part.
  124. - - -
  125. #### `tf.contrib.learn.LinearRegressor.model_dir` {#LinearRegressor.model_dir}
  126. - - -
  127. #### `tf.contrib.learn.LinearRegressor.partial_fit(x=None, y=None, input_fn=None, steps=1, batch_size=None, monitors=None)` {#LinearRegressor.partial_fit}
  128. Incremental fit on a batch of samples.
  129. This method is expected to be called several times consecutively
  130. on different or the same chunks of the dataset. This either can
  131. implement iterative training or out-of-core/online training.
  132. This is especially useful when the whole dataset is too big to
  133. fit in memory at the same time. Or when model is taking long time
  134. to converge, and you want to split up training into subparts.
  135. ##### Args:
  136. * <b>`x`</b>: Matrix of shape [n_samples, n_features...]. Can be iterator that
  137. returns arrays of features. The training input samples for fitting the
  138. model. If set, `input_fn` must be `None`.
  139. * <b>`y`</b>: Vector or matrix [n_samples] or [n_samples, n_outputs]. Can be
  140. iterator that returns array of targets. The training target values
  141. (class labels in classification, real numbers in regression). If set,
  142. `input_fn` must be `None`.
  143. * <b>`input_fn`</b>: Input function. If set, `x`, `y`, and `batch_size` must be
  144. `None`.
  145. * <b>`steps`</b>: Number of steps for which to train model. If `None`, train forever.
  146. * <b>`batch_size`</b>: minibatch size to use on the input, defaults to first
  147. dimension of `x`. Must be `None` if `input_fn` is provided.
  148. * <b>`monitors`</b>: List of `BaseMonitor` subclass instances. Used for callbacks
  149. inside the training loop.
  150. ##### Returns:
  151. `self`, for chaining.
  152. ##### Raises:
  153. * <b>`ValueError`</b>: If at least one of `x` and `y` is provided, and `input_fn` is
  154. provided.
  155. - - -
  156. #### `tf.contrib.learn.LinearRegressor.predict(*args, **kwargs)` {#LinearRegressor.predict}
  157. Returns predictions for given features. (deprecated arguments)
  158. SOME ARGUMENTS ARE DEPRECATED. They will be removed after 2016-09-15.
  159. Instructions for updating:
  160. The default behavior of predict() is changing. The default value for
  161. as_iterable will change to True, and then the flag will be removed
  162. altogether. The behavior of this flag is described below.
  163. Args:
  164. x: Matrix of shape [n_samples, n_features...]. Can be iterator that
  165. returns arrays of features. The training input samples for fitting the
  166. model. If set, `input_fn` must be `None`.
  167. input_fn: Input function. If set, `x` and 'batch_size' must be `None`.
  168. batch_size: Override default batch size. If set, 'input_fn' must be
  169. 'None'.
  170. outputs: list of `str`, name of the output to predict.
  171. If `None`, returns all.
  172. as_iterable: If True, return an iterable which keeps yielding predictions
  173. for each example until inputs are exhausted. Note: The inputs must
  174. terminate if you want the iterable to terminate (e.g. be sure to pass
  175. num_epochs=1 if you are using something like read_batch_features).
  176. Returns:
  177. A numpy array of predicted classes or regression values if the
  178. constructor's `model_fn` returns a `Tensor` for `predictions` or a `dict`
  179. of numpy arrays if `model_fn` returns a `dict`. Returns an iterable of
  180. predictions if as_iterable is True.
  181. Raises:
  182. ValueError: If x and input_fn are both provided or both `None`.
  183. - - -
  184. #### `tf.contrib.learn.LinearRegressor.set_params(**params)` {#LinearRegressor.set_params}
  185. Set the parameters of this estimator.
  186. The method works on simple estimators as well as on nested objects
  187. (such as pipelines). The former have parameters of the form
  188. ``<component>__<parameter>`` so that it's possible to update each
  189. component of a nested object.
  190. ##### Args:
  191. * <b>`**params`</b>: Parameters.
  192. ##### Returns:
  193. self
  194. ##### Raises:
  195. * <b>`ValueError`</b>: If params contain invalid names.
  196. - - -
  197. #### `tf.contrib.learn.LinearRegressor.weights_` {#LinearRegressor.weights_}