metrax.FBetaScore#

class metrax.FBetaScore(true_positives: Array, false_positives: Array, false_negatives: Array, beta: float = 1.0)#

Bases: Metric

F-Beta score Metric class.

Computes the F-Beta score for the binary classification given ‘predictions’ and ‘labels’.

Formula for F-Beta Score:

b2 = beta ** 2 f_beta_score = ((1 + b2) * (precision * recall)) / (precision * b2 + recall)

F-Beta turns into the F1 Score when beta = 1.0

true_positives#

The count of true positive instances from the given data, label, and threshold.

Type:

jax.Array

false_positives#

The count of false positive instances from the given data, label, and threshold.

Type:

jax.Array

false_negatives#

The count of false negative instances from the given data, label, and threshold.

Type:

jax.Array

beta#

The beta value used in the F-Score metric.

Type:

float

__init__(true_positives: Array, false_positives: Array, false_negatives: Array, beta: float = 1.0) None#

Methods

__init__(true_positives, false_positives, ...)

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.

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

true_positives: Array#
false_positives: Array#
false_negatives: Array#
beta: float = 1.0#
classmethod empty() FBetaScore#

Returns an empty instance (i.e. .merge(Metric.empty()) is a no-op).

classmethod from_model_output(predictions: Array, labels: Array, beta: float = 1.0, threshold: float = 0.5) FBetaScore#

Updates the metric.

Note: When only predictions and labels are given, the score calculated is the F1 score if the FBetaScore beta value has not been previously modified.

Parameters:
  • predictions – A floating point 1D vector whose values are in the range [0, 1]. The shape should be (batch_size,).

  • labels – True value. The value is expected to be 0 or 1. The shape should be (batch_size,).

  • beta – beta value to use in the F-Score metric. A floating number.

  • threshold – threshold value to use in the F-Score metric. A floating number.

Returns:

The updated FBetaScore object.

Raises:
  • ValueError – If type of labels is wrong or the shapes of predictions

  • and labels are incompatible. If the beta or threshold are invalid

  • values

  • an error is raised as well.

compute() Array#

Computes final metrics from intermediate values.

__init__(true_positives: Array, false_positives: Array, false_negatives: Array, beta: float = 1.0) None#
replace(**updates)#

Returns a new object replacing the specified fields with new values.