def find_best_model(checkpoint, history):
    """
    Finds the best model saved by the checkpoint.

    :param checkpoint: the checkpoint
    :type checkpoint: ModelCheckpoint
    :param history: a dictionary with the metrics and their values for
    each epoch.
    :type history: dict[str, np.ndarray]
    :return: the path of the best model
    :rtype: str or None
    """
    if checkpoint.save_best_only:
        return checkpoint.filepath

    period = checkpoint.period
    monitor = checkpoint.monitor

    best = checkpoint.best
    monitor_op = checkpoint.monitor_op

    values = history.get(monitor, None)
    if values is None:
        return None
    best_epoch = 0
    for i in range(len(values)):
        if monitor_op(values[i], best):
            best = values[i]
            best_epoch = i

    return checkpoint.filepath.format(epoch=(best_epoch + 1) * period)