tf.feature_column.numeric_column
Stay organized with collections
Save and categorize content based on your preferences.
Represents real valued or numerical features.
tf.feature_column.numeric_column(
key, shape=(1,), default_value=None, dtype=tf.dtypes.float32, normalizer_fn=None
)
Example:
price = numeric_column('price')
columns = [price, ...]
features = tf.io.parse_example(..., features=make_parse_example_spec(columns))
dense_tensor = input_layer(features, columns)
# or
bucketized_price = bucketized_column(price, boundaries=[...])
columns = [bucketized_price, ...]
features = tf.io.parse_example(..., features=make_parse_example_spec(columns))
linear_prediction = linear_model(features, columns)
Args |
key
|
A unique string identifying the input feature. It is used as the
column name and the dictionary key for feature parsing configs, feature
Tensor objects, and feature columns.
|
shape
|
An iterable of integers specifies the shape of the Tensor . An
integer can be given which means a single dimension Tensor with given
width. The Tensor representing the column will have the shape of
[batch_size] + shape .
|
default_value
|
A single value compatible with dtype or an iterable of
values compatible with dtype which the column takes on during
tf.Example parsing if data is missing. A default value of None will
cause tf.io.parse_example to fail if an example does not contain this
column. If a single value is provided, the same value will be applied as
the default value for every item. If an iterable of values is provided,
the shape of the default_value should be equal to the given shape .
|
dtype
|
defines the type of values. Default value is tf.float32 . Must be a
non-quantized, real integer or floating point type.
|
normalizer_fn
|
If not None , a function that can be used to normalize the
value of the tensor after default_value is applied for parsing.
Normalizer function takes the input Tensor as its argument, and returns
the output Tensor . (e.g. lambda x: (x - 3.0) / 4.2). Please note that
even though the most common use case of this function is normalization, it
can be used for any kind of Tensorflow transformations.
|
Raises |
TypeError
|
if any dimension in shape is not an int
|
ValueError
|
if any dimension in shape is not a positive integer
|
TypeError
|
if default_value is an iterable but not compatible with shape
|
TypeError
|
if default_value is not compatible with dtype .
|
ValueError
|
if dtype is not convertible to tf.float32 .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.feature_column.numeric_column\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/feature_column/numeric_column) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.1.0/tensorflow/python/feature_column/feature_column_v2.py#L1264-L1338) |\n\nRepresents real valued or numerical features.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.feature_column.numeric_column`](/api_docs/python/tf/feature_column/numeric_column)\n\n\u003cbr /\u003e\n\n tf.feature_column.numeric_column(\n key, shape=(1,), default_value=None, dtype=tf.dtypes.float32, normalizer_fn=None\n )\n\n#### Example:\n\n price = numeric_column('price')\n columns = [price, ...]\n features = tf.io.parse_example(..., features=make_parse_example_spec(columns))\n dense_tensor = input_layer(features, columns)\n\n # or\n bucketized_price = bucketized_column(price, boundaries=[...])\n columns = [bucketized_price, ...]\n features = tf.io.parse_example(..., features=make_parse_example_spec(columns))\n linear_prediction = linear_model(features, columns)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `key` | A unique string identifying the input feature. It is used as the column name and the dictionary key for feature parsing configs, feature `Tensor` objects, and feature columns. |\n| `shape` | An iterable of integers specifies the shape of the `Tensor`. An integer can be given which means a single dimension `Tensor` with given width. The `Tensor` representing the column will have the shape of \\[batch_size\\] + `shape`. |\n| `default_value` | A single value compatible with `dtype` or an iterable of values compatible with `dtype` which the column takes on during `tf.Example` parsing if data is missing. A default value of `None` will cause [`tf.io.parse_example`](../../tf/io/parse_example) to fail if an example does not contain this column. If a single value is provided, the same value will be applied as the default value for every item. If an iterable of values is provided, the shape of the `default_value` should be equal to the given `shape`. |\n| `dtype` | defines the type of values. Default value is [`tf.float32`](../../tf#float32). Must be a non-quantized, real integer or floating point type. |\n| `normalizer_fn` | If not `None`, a function that can be used to normalize the value of the tensor after `default_value` is applied for parsing. Normalizer function takes the input `Tensor` as its argument, and returns the output `Tensor`. (e.g. lambda x: (x - 3.0) / 4.2). Please note that even though the most common use case of this function is normalization, it can be used for any kind of Tensorflow transformations. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `NumericColumn`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|--------------------------------------------------------------------|\n| `TypeError` | if any dimension in shape is not an int |\n| `ValueError` | if any dimension in shape is not a positive integer |\n| `TypeError` | if `default_value` is an iterable but not compatible with `shape` |\n| `TypeError` | if `default_value` is not compatible with `dtype`. |\n| `ValueError` | if `dtype` is not convertible to [`tf.float32`](../../tf#float32). |\n\n\u003cbr /\u003e"]]