'Updates the internal evaluation result.
Parameters
labels : list of `NDArray`
The labels of the data.
preds : list of `NDArray`
Predicted values.'

def update(self, labels, preds):

    check_label_shapes(labels, preds)
    for (label, pred) in zip(labels, preds):
        pred = pred.asnumpy()
        label = label.asnumpy().astype('int32')
        pred_label = numpy.argmax(pred, axis=1)
        check_label_shapes(label, pred)
        if (len(numpy.unique(label)) > 2):
            raise ValueError('F1    currently    only    supports    binary    classification.')
        (true_positives, false_positives, false_negatives) = (0.0, 0.0, 0.0)
        for (y_pred, y_true) in zip(pred_label, label):
            if ((y_pred == 1) and (y_true == 1)):
                true_positives += 1.0
            elif ((y_pred == 1) and (y_true == 0)):
                false_positives += 1.0
            elif ((y_pred == 0) and (y_true == 1)):
                false_negatives += 1.0
        if ((true_positives + false_positives) > 0):
            precision = (true_positives / (true_positives + false_positives))
        else:
            precision = 0.0
        if ((true_positives + false_negatives) > 0):
            recall = (true_positives / (true_positives + false_negatives))
        else:
            recall = 0.0
        if ((precision + recall) > 0):
            f1_score = (((2 * precision) * recall) / (precision + recall))
        else:
            f1_score = 0.0
        self.sum_metric += f1_score
        self.num_inst += 1
