metrax.BinaryAccuracy#
- class metrax.BinaryAccuracy(total: Array, count: Array)#
Bases:
AverageComputes binary classification accuracy for predictions and labels.
This metric calculates the proportion of correct predictions by comparing predictions >= threshold and labels element-wise. It is the ratio of the sum of weighted correct predictions to the sum of all corresponding weights. If no sample_weights are provided, weights default to 1 for each element.
Methods
__init__(total, count)compute()Computes final metrics from intermediate values.
compute_value()Wraps compute() and returns a values.Value.
empty()Returns an empty instance (i.e. .merge(Metric.empty()) is a no-op).
from_fun(fun)Calls cls.from_model_output with the return value from fun.
from_model_output(predictions, labels[, ...])Updates the metric state with new predictions and labels.
from_output(name)Calls cls.from_model_output with model output named name.
merge(other)Returns Metric that is the accumulation of self and other.
reduce()Reduces the metric along it first axis by calling _reduce_merge().
replace(**updates)Returns a new object replacing the specified fields with new values.
Attributes
totalcount- classmethod from_model_output(predictions: Array, labels: Array, sample_weights: Array | None = None, threshold: float = 0.5) BinaryAccuracy#
Updates the metric state with new predictions and labels.
- Parameters:
predictions – JAX array of predicted values. Expected to have a shape compatible with labels for element-wise comparison (e.g., (batch_size,), (batch_size, 1)).
labels – JAX array of true values. Expected to have a shape compatible with predictions for element-wise comparison.
sample_weights – Optional JAX array of weights. If provided, it must be broadcastable to the shape of labels (which should also be compatible with predictions’ shape).
threshold – The threshold parameter used to convert predicted probabilities to binary decisions.
- Returns:
An updated instance of BinaryAccuracy metric.
- replace(**updates)#
Returns a new object replacing the specified fields with new values.