tf.feature_column.bucketized_column
Stay organized with collections
Save and categorize content based on your preferences.
Represents discretized dense input bucketed by boundaries
.
tf.feature_column.bucketized_column(
source_column, boundaries
)
Buckets include the left boundary, and exclude the right boundary. Namely,
boundaries=[0., 1., 2.]
generates buckets (-inf, 0.)
, [0., 1.)
,
[1., 2.)
, and [2., +inf)
.
For example, if the inputs are
boundaries = [0, 10, 100]
input tensor = [[-5, 10000]
[150, 10]
[5, 100]]
then the output will be
output = [[0, 3]
[3, 2]
[1, 3]]
Example:
price = tf.feature_column.numeric_column('price')
bucketized_price = tf.feature_column.bucketized_column(
price, boundaries=[...])
columns = [bucketized_price, ...]
features = tf.io.parse_example(
..., features=tf.feature_column.make_parse_example_spec(columns))
dense_tensor = tf.keras.layers.DenseFeatures(columns)(features)
`bucketized_column` can also be crossed with another categorical column using
`crossed_column`:
```python
price = tf.feature_column.numeric_column('price')
# bucketized_column converts numerical feature to a categorical one.
bucketized_price = tf.feature_column.bucketized_column(
price, boundaries=[...])
# 'keywords' is a string feature.
price_x_keywords = tf.feature_column.crossed_column(
[bucketized_price, 'keywords'], 50K)
columns = [price_x_keywords, ...]
features = tf.io.parse_example(
..., features=tf.feature_column.make_parse_example_spec(columns))
dense_tensor = tf.keras.layers.DenseFeatures(columns)(features)
linear_model = tf.keras.experimental.LinearModel(units=...)(dense_tensor)
Args |
source_column
|
A one-dimensional dense column which is generated with
numeric_column .
|
boundaries
|
A sorted list or tuple of floats specifying the boundaries.
|
Returns |
A BucketizedColumn .
|
Raises |
ValueError
|
If source_column is not a numeric column, or if it is not
one-dimensional.
|
ValueError
|
If boundaries is not a sorted list or tuple.
|
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.bucketized_column\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/feature_column/bucketized_column) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.1.0/tensorflow/python/feature_column/feature_column_v2.py#L1341-L1423) |\n\nRepresents discretized dense input bucketed by `boundaries`.\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.bucketized_column`](/api_docs/python/tf/feature_column/bucketized_column)\n\n\u003cbr /\u003e\n\n tf.feature_column.bucketized_column(\n source_column, boundaries\n )\n\nBuckets include the left boundary, and exclude the right boundary. Namely,\n`boundaries=[0., 1., 2.]` generates buckets `(-inf, 0.)`, `[0., 1.)`,\n`[1., 2.)`, and `[2., +inf)`.\n\nFor example, if the inputs are \n\n boundaries = [0, 10, 100]\n input tensor = [[-5, 10000]\n [150, 10]\n [5, 100]]\n\nthen the output will be \n\n output = [[0, 3]\n [3, 2]\n [1, 3]]\n\n#### Example:\n\n price = tf.feature_column.numeric_column('price')\n bucketized_price = tf.feature_column.bucketized_column(\n price, boundaries=[...])\n columns = [bucketized_price, ...]\n features = tf.io.parse_example(\n ..., features=tf.feature_column.make_parse_example_spec(columns))\n dense_tensor = tf.keras.layers.DenseFeatures(columns)(features)\n\n `bucketized_column` can also be crossed with another categorical column using\n `crossed_column`:\n\n ```python\n price = tf.feature_column.numeric_column('price')\n # bucketized_column converts numerical feature to a categorical one.\n bucketized_price = tf.feature_column.bucketized_column(\n price, boundaries=[...])\n # 'keywords' is a string feature.\n price_x_keywords = tf.feature_column.crossed_column(\n [bucketized_price, 'keywords'], 50K)\n columns = [price_x_keywords, ...]\n features = tf.io.parse_example(\n ..., features=tf.feature_column.make_parse_example_spec(columns))\n dense_tensor = tf.keras.layers.DenseFeatures(columns)(features)\n linear_model = tf.keras.experimental.LinearModel(units=...)(dense_tensor)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------------|--------------------------------------------------------------------------|\n| `source_column` | A one-dimensional dense column which is generated with `numeric_column`. |\n| `boundaries` | A sorted list or tuple of floats specifying the boundaries. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `BucketizedColumn`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|------------------------------------------------------------------------------|\n| `ValueError` | If `source_column` is not a numeric column, or if it is not one-dimensional. |\n| `ValueError` | If `boundaries` is not a sorted list or tuple. |\n\n\u003cbr /\u003e"]]