def compute_train_val_test(X, y, model, scale=False, test_size=0.2, time_series=False, random_state=123, n_folds=5, regr=True):
    "\n    Compute the training-validation-test scores for the given model on the given dataset.\n\n    The training and test scores are simply computed by splitting the dataset into the training and test sets. The validation\n    score is performed applying the cross validation on the training set.\n\n    Parameters\n    ----------\n    X: np.array\n        Two-dimensional np.array, containing the explanatory features of the dataset.\n    y: np.array\n        Mono dimensional np.array, containing the response feature of the dataset.\n    model: sklearn.base.BaseEstimator\n        Model to evaluate.\n    scale: bool\n        Indicates whether to scale or not the features in `X`.\n        (The scaling is performed using the sklearn MinMaxScaler).\n    test_size: float\n        Decimal number between 0 and 1, which indicates the proportion of the test set.\n    time_series: bool\n        Indicates if the given dataset is a time series dataset (i.e. datasets indexed by days).\n        (This affects the computing of the scores).\n    random_state: int\n        Used in the training-test splitting of the dataset.\n    n_folds: int\n        Indicates how many folds are made in order to compute the k-fold cross validation.\n        (It's used only if `time_series` is False).\n    regr: bool\n        Indicates if it's either a regression or a classification problem.\n\n    Returns\n    ----------\n    train_score: float\n    val_score: float\n    test_score: float\n\n    Notes\n    ----------\n    - If `regr` is True, the returned scores are errors, computed using the MSE formula (i.e. Mean Squared Error).\n      Otherwise, the returned scores are accuracy measures.\n    - If `time_series` is False, the training-test splitting of the dataset is made randomly. In addition, the cross\n      validation strategy performed is the classic k-fold cross validation: the number of folds is specified by `n_folds`.\n      Otherwise, if `time_series` is True, the training-test sets are obtained simply by splitting the dataset into two\n      contiguous parts. In addition, the cross validation strategy performed is the sklearn TimeSeriesSplit.\n    "
    if regr:
        scoring = 'neg_mean_squared_error'
    else:
        scoring = 'accuracy'
    if (not time_series):
        (X_train_80, X_test, y_train_80, y_test) = train_test_split(X, y, test_size=test_size, random_state=random_state)
    else:
        train_len = int((X.shape[0] * (1 - test_size)))
        X_train_80 = X[:train_len]
        y_train_80 = y[:train_len]
        X_test = X[train_len:]
        y_test = y[train_len:]
    if scale:
        scaler = MinMaxScaler()
        scaler.fit(X_train_80)
        X_train_80 = scaler.transform(X_train_80)
        X_test = scaler.transform(X_test)
    if (not time_series):
        cv = n_folds
    else:
        cv = TimeSeriesSplit(n_splits=n_folds)
    scores = cross_val_score(model, X_train_80, y_train_80, cv=cv, scoring=scoring)
    val_score = scores.mean()
    if regr:
        val_score = (- val_score)
    model.fit(X_train_80, y_train_80)
    train_score = 0
    test_score = 0
    if regr:
        train_score = mean_squared_error(y_true=y_train_80, y_pred=model.predict(X_train_80))
        test_score = mean_squared_error(y_true=y_test, y_pred=model.predict(X_test))
    else:
        train_score = accuracy_score(y_true=y_train_80, y_pred=model.predict(X_train_80))
        test_score = accuracy_score(y_true=y_test, y_pred=model.predict(X_test))
    return (train_score, val_score, test_score)
Compute the training-validation-test scores for the given model on the given dataset.

The training and test scores are simply computed by splitting the dataset into the training and test sets. The validation
score is performed applying the cross validation on the training set.

Parameters
----------
X: np.array
    Two-dimensional np.array, containing the explanatory features of the dataset.
y: np.array
    Mono dimensional np.array, containing the response feature of the dataset.
model: sklearn.base.BaseEstimator
    Model to evaluate.
scale: bool
    Indicates whether to scale or not the features in `X`.
    (The scaling is performed using the sklearn MinMaxScaler).
test_size: float
    Decimal number between 0 and 1, which indicates the proportion of the test set.
time_series: bool
    Indicates if the given dataset is a time series dataset (i.e. datasets indexed by days).
    (This affects the computing of the scores).
random_state: int
    Used in the training-test splitting of the dataset.
n_folds: int
    Indicates how many folds are made in order to compute the k-fold cross validation.
    (It's used only if `time_series` is False).
regr: bool
    Indicates if it's either a regression or a classification problem.

Returns
----------
train_score: float
val_score: float
test_score: float

Notes
----------
- If `regr` is True, the returned scores are errors, computed using the MSE formula (i.e. Mean Squared Error).
  Otherwise, the returned scores are accuracy measures.
- If `time_series` is False, the training-test splitting of the dataset is made randomly. In addition, the cross
  validation strategy performed is the classic k-fold cross validation: the number of folds is specified by `n_folds`.
  Otherwise, if `time_series` is True, the training-test sets are obtained simply by splitting the dataset into two
  contiguous parts. In addition, the cross validation strategy performed is the sklearn TimeSeriesSplit.
def compute_train_val_test(X, y, model, scale=False, test_size=0.2, time_series=False, random_state=123, n_folds=5, regr=True):
    "\n    Compute the training-validation-test scores for the given model on the given dataset.\n\n    The training and test scores are simply computed by splitting the dataset into the training and test sets. The validation\n    score is performed applying the cross validation on the training set.\n\n    Parameters\n    ----------\n    X: np.array\n        Two-dimensional np.array, containing the explanatory features of the dataset.\n    y: np.array\n        Mono dimensional np.array, containing the response feature of the dataset.\n    model: sklearn.base.BaseEstimator\n        Model to evaluate.\n    scale: bool\n        Indicates whether to scale or not the features in `X`.\n        (The scaling is performed using the sklearn MinMaxScaler).\n    test_size: float\n        Decimal number between 0 and 1, which indicates the proportion of the test set.\n    time_series: bool\n        Indicates if the given dataset is a time series dataset (i.e. datasets indexed by days).\n        (This affects the computing of the scores).\n    random_state: int\n        Used in the training-test splitting of the dataset.\n    n_folds: int\n        Indicates how many folds are made in order to compute the k-fold cross validation.\n        (It's used only if `time_series` is False).\n    regr: bool\n        Indicates if it's either a regression or a classification problem.\n\n    Returns\n    ----------\n    train_score: float\n    val_score: float\n    test_score: float\n\n    Notes\n    ----------\n    - If `regr` is True, the returned scores are errors, computed using the MSE formula (i.e. Mean Squared Error).\n      Otherwise, the returned scores are accuracy measures.\n    - If `time_series` is False, the training-test splitting of the dataset is made randomly. In addition, the cross\n      validation strategy performed is the classic k-fold cross validation: the number of folds is specified by `n_folds`.\n      Otherwise, if `time_series` is True, the training-test sets are obtained simply by splitting the dataset into two\n      contiguous parts. In addition, the cross validation strategy performed is the sklearn TimeSeriesSplit.\n    "
    if regr:
        scoring = 'neg_mean_squared_error'
    else:
        scoring = 'accuracy'
    if (not time_series):
        (X_train_80, X_test, y_train_80, y_test) = train_test_split(X, y, test_size=test_size, random_state=random_state)
    else:
        train_len = int((X.shape[0] * (1 - test_size)))
        X_train_80 = X[:train_len]
        y_train_80 = y[:train_len]
        X_test = X[train_len:]
        y_test = y[train_len:]
    if scale:
        scaler = MinMaxScaler()
        scaler.fit(X_train_80)
        X_train_80 = scaler.transform(X_train_80)
        X_test = scaler.transform(X_test)
    if (not time_series):
        cv = n_folds
    else:
        cv = TimeSeriesSplit(n_splits=n_folds)
    scores = cross_val_score(model, X_train_80, y_train_80, cv=cv, scoring=scoring)
    val_score = scores.mean()
    if regr:
        val_score = (- val_score)
    model.fit(X_train_80, y_train_80)
    train_score = 0
    test_score = 0
    if regr:
        train_score = mean_squared_error(y_true=y_train_80, y_pred=model.predict(X_train_80))
        test_score = mean_squared_error(y_true=y_test, y_pred=model.predict(X_test))
    else:
        train_score = accuracy_score(y_true=y_train_80, y_pred=model.predict(X_train_80))
        test_score = accuracy_score(y_true=y_test, y_pred=model.predict(X_test))
    return (train_score, val_score, test_score)