# tf.feature_column.bucketized_column

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/feature_column/feature_column_v2.py#L1120-L1204) |

Represents discretized dense input bucketed by `boundaries`. (deprecated)

> [!WARNING]
> **Warning:** tf.feature_column is not recommended for new code. Instead, feature preprocessing can be done directly using either [Keras preprocessing
> 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.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.feature_column.bucketized_column`](https://www.tensorflow.org/api_docs/python/tf/feature_column/bucketized_column)

<br />

    tf.feature_column.bucketized_column(
        source_column, boundaries
    )

> [!WARNING]
> **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`](https://www.tensorflow.org/versions/r2.13/api_docs/python/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.

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)

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)

<br />

<br />

<br />

| ## 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. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A `BucketizedColumn`. ||

<br />

<br />

<br />

<br />

| ## 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. |

<br />