Metrics
Metric#
A Metric
to let optimizers know how to
handle numeric values properly.
A Metric
is defined by a .name: str
and whether it is better to .minimize: bool
the metric. Further, you can specify .bounds: tuple[lower, upper]
which can
help optimizers and other code know how to treat metrics.
To easily convert between loss
,
score
of a
a value in a Metric.Value
object.
If the metric is bounded, you can also get the
distance_to_optimal
which is the distance to the optimal value.
from amltk.optimization import Metric
acc = Metric("accuracy", minimize=False, bounds=(0.0, 1.0))
acc_value = acc.as_value(0.9)
print(f"Cost: {acc_value.distance_to_optimal}") # Distance to optimal.
print(f"Loss: {acc_value.loss}") # Something that can be minimized
print(f"Score: {acc_value.score}") # Something that can be maximized