Feature column describe a set of transformations to the inputs.
For example, to "bucketize" feature a, wrap the a column in a
feature_column.bucketized_column.
Providing 5 bucket boundaries, the bucketized_column api
will bucket this feature in total of 6 buckets.
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.
Returns
A NumericColumn.
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
[null,null,["Last updated 2023-10-06 UTC."],[],[],null,["# tf.feature_column.numeric_column\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/feature_column/feature_column_v2.py#L1020-L1117) |\n\nRepresents real valued or numerical features. (deprecated)\n| **Warning:** tf.feature_column is not recommended for new code. Instead, feature preprocessing can be done directly using either [Keras preprocessing\n| layers](https://www.tensorflow.org/guide/migrate/migrating_feature_columns) or through the one-stop utility [`tf.keras.utils.FeatureSpace`](https://www.tensorflow.org/api_docs/python/tf/keras/utils/FeatureSpace) built on top of them. See the [migration guide](https://tensorflow.org/guide/migrate) for details.\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`](https://www.tensorflow.org/api_docs/python/tf/feature_column/numeric_column)\n\n\u003cbr /\u003e\n\n tf.feature_column.numeric_column(\n key,\n shape=(1,),\n default_value=None,\n dtype=../../tf/dtypes#float32,\n normalizer_fn=None\n )\n\n| **Deprecated:** THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use Keras preprocessing layers instead, either directly or via the [`tf.keras.utils.FeatureSpace`](../../tf/keras/utils/FeatureSpace) utility. Each of `tf.feature_column.*` has a functional equivalent in `tf.keras.layers` for feature preprocessing when training a Keras model.\n\n#### Example:\n\nAssume we have data with two features `a` and `b`. \n\n data = {'a': [15, 9, 17, 19, 21, 18, 25, 30],\n 'b': [5.0, 6.4, 10.5, 13.6, 15.7, 19.9, 20.3 , 0.0]}\n\nLet us represent the features `a` and `b` as numerical features. \n\n a = tf.feature_column.numeric_column('a')\n b = tf.feature_column.numeric_column('b')\n\nFeature column describe a set of transformations to the inputs.\n\nFor example, to \"bucketize\" feature `a`, wrap the `a` column in a\n[`feature_column.bucketized_column`](../../tf/feature_column/bucketized_column).\nProviding `5` bucket boundaries, the bucketized_column api\nwill bucket this feature in total of `6` buckets. \n\n a_buckets = tf.feature_column.bucketized_column(a,\n boundaries=[10, 15, 20, 25, 30])\n\nCreate a `DenseFeatures` layer which will apply the transformations\ndescribed by the set of [`tf.feature_column`](../../tf/feature_column) objects: \n\n feature_layer = tf.keras.layers.DenseFeatures([a_buckets, b])\n print(feature_layer(data))\n tf.Tensor(\n [[ 0. 0. 1. 0. 0. 0. 5. ]\n [ 1. 0. 0. 0. 0. 0. 6.4]\n [ 0. 0. 1. 0. 0. 0. 10.5]\n [ 0. 0. 1. 0. 0. 0. 13.6]\n [ 0. 0. 0. 1. 0. 0. 15.7]\n [ 0. 0. 1. 0. 0. 0. 19.9]\n [ 0. 0. 0. 0. 1. 0. 20.3]\n [ 0. 0. 0. 0. 0. 1. 0. ]], shape=(8, 7), dtype=float32)\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"]]