tf.keras.metrics.TruePositives

Calculates the number of true positives.

Inherits From: Metric

Used in the notebooks

Used in the tutorials

If sample_weight is given, calculates the sum of the weights of true positives. This metric creates one local variable, true_positives that is used to keep track of the number of true positives.

If sample_weight is None, weights default to 1. Use sample_weight of 0 to mask values.

thresholds (Optional) Defaults to 0.5. A float value, or a Python list/tuple of float threshold values in [0, 1]. A threshold is compared with prediction values to determine the truth value of predictions (i.e., above the threshold is True, below is False). If used with a loss function that sets from_logits=True (i.e. no sigmoid applied to predictions), thresholds should be set to 0. One metric value is generated for each threshold value.
name (Optional) string name of the metric instance.
dtype (Optional) data type of the metric result.

Example:

m = keras.metrics.TruePositives()
m.update_state([0, 1, 1, 1], [1, 0, 1, 1])
m.result()
2.0
m.reset_state()
m.update_state([0, 1, 1, 1], [1, 0, 1, 1], sample_weight=[0, 0, 1, 0])
m.result()
1.0

dtype

variables

Methods

add_variable

View source

add_weight

View source

from_config

View source

get_config

View source

Return the serializable config of the metric.

reset_state

View source

Reset all of the metric state variables.

This function is called between epochs/steps, when a metric is evaluated during training.

result

View source

Compute the current metric value.

Returns
A scalar tensor, or a dictionary of scalar tensors.

stateless_reset_state

View source

stateless_result

View source

stateless_update_state

View source

update_state

View source

Accumulates the metric statistics.

Args
y_true The ground truth values.
y_pred The predicted values.
sample_weight Optional weighting of each example. Defaults to 1. Can be a tensor whose rank is either 0, or the same rank as y_true, and must be broadcastable to y_true.

__call__

View source

Call self as a function.