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-04-26 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{"lastModified": "Last updated 2024-04-26 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 2024-04-26 UTC."],[],[]]