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).
A bucketized_column can also be crossed with another categorical column
using crossed_column:
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.feature_column.bucketized_column\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/feature_column/feature_column_v2.py#L917-L1001) |\n\nRepresents discretized dense input bucketed by `boundaries`. (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.bucketized_column`](https://www.tensorflow.org/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\n### Used in the notebooks\n\n| Used in the guide | Used in the tutorials |\n|--------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Migrate \\`tf.feature_column\\`s to Keras preprocessing layers](https://www.tensorflow.org/guide/migrate/migrating_feature_columns) | - [Classify structured data with feature columns](https://www.tensorflow.org/tutorials/structured_data/feature_columns) - [End to end example for BigQuery TensorFlow reader](https://www.tensorflow.org/io/tutorials/bigquery) |\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\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\nA `bucketized_column` can also be crossed with another categorical column\nusing `crossed_column`: \n\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"]]