Table Of Contents
Table Of Contents


class mxnet.metric.CustomMetric(feval, name=None, allow_extra_outputs=False, output_names=None, label_names=None)[source]

Computes a customized evaluation metric.

The feval function can return a tuple of (sum_metric, num_inst) or return an int sum_metric.

  • feval (callable(label, pred)) – Customized evaluation function.

  • name (str) – The name of the metric. (the default is None).

  • allow_extra_outputs (bool, optional) – If true, the prediction outputs can have extra outputs. This is useful in RNN, where the states are also produced in outputs for forwarding. (the default is False).

  • name – Name of this metric instance for display.

  • output_names (list of str, or None) – Name of predictions that should be used when updating with update_dict. By default include all predictions.

  • label_names (list of str, or None) – Name of labels that should be used when updating with update_dict. By default include all labels.


>>> predicts = [mx.nd.array(np.array([3, -0.5, 2, 7]).reshape(4,1))]
>>> labels = [mx.nd.array(np.array([2.5, 0.0, 2, 8]).reshape(4,1))]
>>> feval = lambda x, y : (x + y).mean()
>>> eval_metrics = mx.metric.CustomMetric(feval=feval)
>>> eval_metrics.update(labels, predicts)
>>> print eval_metrics.get()
('custom(<lambda>)', 6.0)
__init__(feval, name=None, allow_extra_outputs=False, output_names=None, label_names=None)[source]

Initialize self. See help(type(self)) for accurate signature.


__init__(feval[, name, allow_extra_outputs, …])

Initialize self.


Gets the current evaluation result.


Save configurations of metric.


Gets the current global evaluation result.


Returns zipped name and value pairs for global results.


Returns zipped name and value pairs.


Resets the internal evaluation result to initial state.


Resets the local portion of the internal evaluation results to initial state.

update(labels, preds)

Updates the internal evaluation result.

update_dict(label, pred)

Update the internal evaluation with named label and pred