tft.histogram
Stay organized with collections
Save and categorize content based on your preferences.
Computes a histogram over x, given the bin boundaries or bin count.
tft.histogram(
x: common_types.TensorType,
boundaries: Optional[Union[tf.Tensor, int]] = None,
categorical: Optional[bool] = False,
name: Optional[str] = None
) -> Tuple[tf.Tensor, tf.Tensor]
Ex (1):
counts, boundaries = histogram([0, 1, 0, 1, 0, 3, 0, 1], range(5))
counts: [4, 3, 0, 1, 0]
boundaries: [0, 1, 2, 3, 4]
Ex (2):
Can be used to compute class weights.
counts, classes = histogram([0, 1, 0, 1, 0, 3, 0, 1], categorical=True)
probabilities = counts / tf.reduce_sum(counts)
class_weights = dict(map(lambda (a, b): (a.numpy(), 1.0 / b.numpy()),
zip(classes, probabilities)))
Args |
x
|
A Tensor , SparseTensor , or RaggedTensor .
|
boundaries
|
(Optional) A Tensor or int used to build the histogram;
ignored if categorical is True. If possible, provide boundaries as
multiple sorted values. Default to 10 intervals over the 0-1 range, or
find the min/max if an int is provided (not recommended because
multi-phase analysis is inefficient).
|
categorical
|
(Optional) A bool that treats x as discrete values if true.
|
name
|
(Optional) A name for this operation.
|
Returns |
counts
|
The histogram, as counts per bin.
|
boundaries
|
A Tensor used to build the histogram representing 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.
[[["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-11-01 UTC."],[],[],null,["# tft.histogram\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/transform/blob/v1.16.0/tensorflow_transform/analyzers.py#L677-L739) |\n\nComputes a histogram over x, given the bin boundaries or bin count. \n\n tft.histogram(\n x: common_types.TensorType,\n boundaries: Optional[Union[tf.Tensor, int]] = None,\n categorical: Optional[bool] = False,\n name: Optional[str] = None\n ) -\u003e Tuple[tf.Tensor, tf.Tensor]\n\nEx (1):\ncounts, boundaries = histogram(\\[0, 1, 0, 1, 0, 3, 0, 1\\], range(5))\ncounts: \\[4, 3, 0, 1, 0\\]\nboundaries: \\[0, 1, 2, 3, 4\\]\n\nEx (2):\nCan be used to compute class weights.\ncounts, classes = histogram(\\[0, 1, 0, 1, 0, 3, 0, 1\\], categorical=True)\nprobabilities = counts / tf.reduce_sum(counts)\nclass_weights = dict(map(lambda (a, b): (a.numpy(), 1.0 / b.numpy()),\nzip(classes, probabilities)))\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `x` | A `Tensor`, `SparseTensor`, or `RaggedTensor`. |\n| `boundaries` | (Optional) A `Tensor` or `int` used to build the histogram; ignored if `categorical` is True. If possible, provide boundaries as multiple sorted values. Default to 10 intervals over the 0-1 range, or find the min/max if an int is provided (not recommended because multi-phase analysis is inefficient). |\n| `categorical` | (Optional) A `bool` that treats `x` as discrete values if true. |\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| `counts` | The histogram, as counts per bin. |\n| `boundaries` | A `Tensor` used to build the histogram representing boundaries. |\n\n\u003cbr /\u003e"]]