tf.feature_column.bucketized_column
Stay organized with collections
Save and categorize content based on your preferences.
Represents discretized dense input.
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 = numeric_column('price')
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)
# or
columns = [bucketized_price, ...]
features = tf.io.parse_example(..., features=make_parse_example_spec(columns))
dense_tensor = input_layer(features, columns)
bucketized_column
can also be crossed with another categorical column using
crossed_column
:
price = numeric_column('price')
# bucketized_column converts numerical feature to a categorical one.
bucketized_price = bucketized_column(price, boundaries=[...])
# 'keywords' is a string feature.
price_x_keywords = crossed_column([bucketized_price, 'keywords'], 50K)
columns = [price_x_keywords, ...]
features = tf.io.parse_example(..., features=make_parse_example_spec(columns))
linear_prediction = linear_model(features, columns)
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.
[[["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 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.0.0/tensorflow/python/feature_column/feature_column_v2.py#L1340-L1422) |\n\nRepresents discretized dense input.\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 = numeric_column('price')\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 # or\n columns = [bucketized_price, ...]\n features = tf.io.parse_example(..., features=make_parse_example_spec(columns))\n dense_tensor = input_layer(features, columns)\n\n`bucketized_column` can also be crossed with another categorical column using\n`crossed_column`: \n\n price = numeric_column('price')\n # bucketized_column converts numerical feature to a categorical one.\n bucketized_price = bucketized_column(price, boundaries=[...])\n # 'keywords' is a string feature.\n price_x_keywords = crossed_column([bucketized_price, 'keywords'], 50K)\n columns = [price_x_keywords, ...]\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| `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"]]