def train_and_predict(
    prediction_function,
    train,
    val,
    test=None
):
    """Train on a training set and predict on a validation and optional test set.

    The prediction function has the signature:
    prediction_function[Dataset, Dataset, Dataset] -> Results

    Args:
        prediction_function: callable
        train: Dataset instance
        val: Dataset instance
        test: Dataset instance

    Returns:
        Results instance
    """
    results = prediction_function(train, val, test)
    return results