def time_series_cross_validation(ml, database, params, number_folds=10,
                                 dataprocess=None):
    """
        Performs a k-fold cross-validation on a Time Series as described by
        Rob Hyndman.

        See Also:
            http://robjhyndman.com/hyndsight/crossvalidation/

        Arguments:
            ml (:class:`ELMKernel` or :class:`ELMRandom`):
            database (numpy.ndarray): uses 'data' matrix to perform
                cross-validation.
            params (list): list of parameters from *ml* to train/test.
            number_folds (int): number of folds to be created from training and
                testing matrices.
            dataprocess (:class:`DataProcess`): an object that will pre-process
                database before training. Defaults to None.

        Returns:
            tuple: tuple of :class:`CVError` from training and testing.
    """

    if number_folds < 2:
        print("Error: Must have at least 2-folds.")
        return

    number_patterns = database.shape[0]
    fold_size = round(number_patterns / number_folds)

    folds = []
    for k in range(number_folds):
        folds.append(database[k * fold_size:(k + 1) * fold_size, :])

    training_errors = []
    testing_errors = []

    training_matrix = folds[0]
    testing_matrix = []
    for k in range(number_folds - 1):
        if k > 0:
            training_matrix = \
                np.concatenate((training_matrix, testing_matrix), axis=0)

        testing_matrix = folds[k + 1]

        # If dataprocess is available applies defined processes
        if dataprocess is not None:
            training_matrix, testing_matrix = \
                dataprocess.auto(training_matrix, testing_matrix)

        tr_error = ml.train(training_matrix, params)
        te_error = ml.test(testing_matrix)

        training_errors.append(tr_error)
        testing_errors.append(te_error)

    cv_training_error = CVError(training_errors)
    cv_testing_error = CVError(testing_errors)

    return cv_training_error, cv_testing_error
dataset/ETHPy150Open acba/elm/elm/mltools.py/time_series_cross_validation/original