INNER CODE UNIT · Python
set_objective
joeddav/devol · devol/devol.py:68
def set_objective(self, metric):
"""
Set the metric for optimization. Can also be done by passing to
`run`.
Args:
metric (str): either 'acc' to maximize classification accuracy, or
else 'loss' to minimize the loss function
"""
if metric == 'acc':
metric = 'accuracy'
if metric not in ['loss', 'accuracy']:
raise ValueError(('Invalid metric name {} provided - should be'
'"accuracy" or "loss"').format(metric))
self._metric = metric
self._objective = "max" if self._metric == "accuracy" else "min"
self._metric_index = 1 if self._metric == 'loss' else -1
self._metric_op = METRIC_OPS[self._objective == 'max']