tf.keras.ops.in_top_k
Stay organized with collections
Save and categorize content based on your preferences.
Checks if the targets are in the top-k predictions.
tf.keras.ops.in_top_k(
targets, predictions, k
)
Args |
targets
|
A tensor of true labels.
|
predictions
|
A tensor of predicted labels.
|
k
|
An integer representing the number of predictions to consider.
|
Returns |
A boolean tensor of the same shape as targets , where each element
indicates whether the corresponding target is in the top-k predictions.
|
Example:
targets = keras.ops.convert_to_tensor([2, 5, 3])
predictions = keras.ops.convert_to_tensor(
[[0.1, 0.4, 0.6, 0.9, 0.5],
[0.1, 0.7, 0.9, 0.8, 0.3],
[0.1, 0.6, 0.9, 0.9, 0.5]])
in_top_k(targets, predictions, k=3)
array([ True False True], shape=(3,), dtype=bool)
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. Some content is licensed under the numpy license.
Last updated 2024-06-07 UTC.
[null,null,["Last updated 2024-06-07 UTC."],[],[],null,["# tf.keras.ops.in_top_k\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/ops/math.py#L178-L203) |\n\nChecks if the targets are in the top-k predictions. \n\n tf.keras.ops.in_top_k(\n targets, predictions, k\n )\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------|----------------------------------------------------------------|\n| `targets` | A tensor of true labels. |\n| `predictions` | A tensor of predicted labels. |\n| `k` | An integer representing the number of predictions to consider. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A boolean tensor of the same shape as `targets`, where each element indicates whether the corresponding target is in the top-k predictions. ||\n\n\u003cbr /\u003e\n\n#### Example:\n\n targets = keras.ops.convert_to_tensor([2, 5, 3])\n predictions = keras.ops.convert_to_tensor(\n [[0.1, 0.4, 0.6, 0.9, 0.5],\n [0.1, 0.7, 0.9, 0.8, 0.3],\n [0.1, 0.6, 0.9, 0.9, 0.5]])\n in_top_k(targets, predictions, k=3)\n array([ True False True], shape=(3,), dtype=bool)"]]