View source on GitHub |
Computes F-1 Score.
Inherits From: FBetaScore
, Metric
tf.keras.metrics.F1Score(
average=None, threshold=None, name='f1_score', dtype=None
)
Formula:
f1_score = 2 * (precision * recall) / (precision + recall)
This is the harmonic mean of precision and recall.
Its output range is [0, 1]
. It works for both multi-class
and multi-label classification.
Returns | |
---|---|
F-1 Score: float. |
Example:
metric = keras.metrics.F1Score(threshold=0.5)
y_true = np.array([[1, 1, 1],
[1, 0, 0],
[1, 1, 0]], np.int32)
y_pred = np.array([[0.2, 0.6, 0.7],
[0.2, 0.6, 0.6],
[0.6, 0.8, 0.0]], np.float32)
metric.update_state(y_true, y_pred)
result = metric.result()
array([0.5 , 0.8 , 0.6666667], dtype=float32)
Attributes | |
---|---|
dtype
|
|
variables
|
Methods
add_variable
add_variable(
shape, initializer, dtype=None, aggregation='sum', name=None
)
add_weight
add_weight(
shape=(), initializer=None, dtype=None, name=None
)
from_config
@classmethod
from_config( config )
get_config
get_config()
Returns the serializable config of the metric.
reset_state
reset_state()
Reset all of the metric state variables.
This function is called between epochs/steps, when a metric is evaluated during training.
result
result()
Compute the current metric value.
Returns | |
---|---|
A scalar tensor, or a dictionary of scalar tensors. |
stateless_reset_state
stateless_reset_state()
stateless_result
stateless_result(
metric_variables
)
stateless_update_state
stateless_update_state(
metric_variables, *args, **kwargs
)
update_state
update_state(
y_true, y_pred, sample_weight=None
)
Accumulate statistics for the metric.
__call__
__call__(
*args, **kwargs
)
Call self as a function.