tft.apply_buckets
Stay organized with collections
Save and categorize content based on your preferences.
Returns a bucketized column, with a bucket index assigned to each input.
tft.apply_buckets(
x: common_types.ConsistentTensorType,
bucket_boundaries: common_types.BucketBoundariesType,
name: Optional[str] = None
) -> common_types.ConsistentTensorType
Each element e
in x
is mapped to a positive index i
for which
bucket_boundaries[i-1] <= e < bucket_boundaries[i]
, if it exists.
If e < bucket_boundaries[0]
, then e
is mapped to 0
. If
e >= bucket_boundaries[-1]
, then e
is mapped to len(bucket_boundaries)
.
NaNs are mapped to len(bucket_boundaries)
.
Example:
x = tf.constant([[4.0, float('nan'), 1.0], [float('-inf'), 7.5, 10.0]])
bucket_boundaries = tf.constant([[2.0, 5.0, 10.0]])
tft.apply_buckets(x, bucket_boundaries)
<tf.Tensor: shape=(2, 3), dtype=int64, numpy=
array([[1, 3, 0],
[0, 2, 3]])>
Args |
x
|
A numeric input Tensor , SparseTensor , or RaggedTensor whose values
should be mapped to buckets. For CompositeTensor s, the non-missing
values will be mapped to buckets and missing value left missing.
|
bucket_boundaries
|
A rank 2 Tensor or list representing the bucket
boundaries sorted in ascending order.
|
name
|
(Optional) A name for this operation.
|
Returns |
A Tensor , SparseTensor , or RaggedTensor of the same shape as x , with
each element in the returned tensor representing the bucketized value.
Bucketized value is in the range [0, len(bucket_boundaries)].
|
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 2024-11-01 UTC.
[null,null,["Last updated 2024-11-01 UTC."],[],[],null,["# tft.apply_buckets\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/transform/blob/v1.16.0/tensorflow_transform/mappers.py#L2101-L2151) |\n\nReturns a bucketized column, with a bucket index assigned to each input. \n\n tft.apply_buckets(\n x: common_types.ConsistentTensorType,\n bucket_boundaries: common_types.BucketBoundariesType,\n name: Optional[str] = None\n ) -\u003e common_types.ConsistentTensorType\n\nEach element `e` in `x` is mapped to a positive index `i` for which\n`bucket_boundaries[i-1] \u003c= e \u003c bucket_boundaries[i]`, if it exists.\nIf `e \u003c bucket_boundaries[0]`, then `e` is mapped to `0`. If\n`e \u003e= bucket_boundaries[-1]`, then `e` is mapped to `len(bucket_boundaries)`.\nNaNs are mapped to `len(bucket_boundaries)`.\n\n#### Example:\n\n x = tf.constant([[4.0, float('nan'), 1.0], [float('-inf'), 7.5, 10.0]])\n bucket_boundaries = tf.constant([[2.0, 5.0, 10.0]])\n tft.apply_buckets(x, bucket_boundaries)\n \u003ctf.Tensor: shape=(2, 3), dtype=int64, numpy=\n array([[1, 3, 0],\n [0, 2, 3]])\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `x` | A numeric input `Tensor`, `SparseTensor`, or `RaggedTensor` whose values should be mapped to buckets. For `CompositeTensor`s, the non-missing values will be mapped to buckets and missing value left missing. |\n| `bucket_boundaries` | A rank 2 `Tensor` or list representing the bucket boundaries sorted in ascending order. |\n| `name` | (Optional) A name for this operation. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Tensor`, `SparseTensor`, or `RaggedTensor` of the same shape as `x`, with each element in the returned tensor representing the bucketized value. Bucketized value is in the range \\[0, len(bucket_boundaries)\\]. ||\n\n\u003cbr /\u003e"]]