def compute_bias_variance_error(X, y, model, scale=False, N_TESTS=20, sample_size=0.67):
    '\n    Compute the bias^2-variance-error scores for the given model on the given dataset.\n\n    These measures are computed in an approximate way, using `N_TESTS` random samples of size `sample_size` from the\n    dataset.\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    N_TESTS: int\n        Number of samples that are made in order to compute the measures.\n    sample_size: float\n        Decimal number between 0 and 1, which indicates the proportion of the sample.\n\n    Returns\n    ----------\n    bias: float\n    variance: float\n    error: float\n    '
    if scale:
        scaler = MinMaxScaler()
        scaler.fit(X)
        X = scaler.transform(X)
    vector_ypred = []
    for i in range(N_TESTS):
        (Xs, ys) = resample(X, y, n_samples=int((sample_size * len(y))))
        model.fit(Xs, ys)
        vector_ypred.append(list(model.predict(X)))
    vector_ypred = np.array(vector_ypred)
    vector_bias = ((y - np.mean(vector_ypred, axis=0)) ** 2)
    vector_variance = np.var(vector_ypred, axis=0)
    vector_error = (np.sum(((vector_ypred - y) ** 2), axis=0) / N_TESTS)
    bias = np.mean(vector_bias)
    variance = np.mean(vector_variance)
    error = np.mean(vector_error)
    return (bias, variance, error)
Compute the bias^2-variance-error scores for the given model on the given dataset.

These measures are computed in an approximate way, using `N_TESTS` random samples of size `sample_size` from the
dataset.

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).
N_TESTS: int
    Number of samples that are made in order to compute the measures.
sample_size: float
    Decimal number between 0 and 1, which indicates the proportion of the sample.

Returns
----------
bias: float
variance: float
error: float
def compute_bias_variance_error(X, y, model, scale=False, N_TESTS=20, sample_size=0.67):
    '\n    Compute the bias^2-variance-error scores for the given model on the given dataset.\n\n    These measures are computed in an approximate way, using `N_TESTS` random samples of size `sample_size` from the\n    dataset.\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    N_TESTS: int\n        Number of samples that are made in order to compute the measures.\n    sample_size: float\n        Decimal number between 0 and 1, which indicates the proportion of the sample.\n\n    Returns\n    ----------\n    bias: float\n    variance: float\n    error: float\n    '
    if scale:
        scaler = MinMaxScaler()
        scaler.fit(X)
        X = scaler.transform(X)
    vector_ypred = []
    for i in range(N_TESTS):
        (Xs, ys) = resample(X, y, n_samples=int((sample_size * len(y))))
        model.fit(Xs, ys)
        vector_ypred.append(list(model.predict(X)))
    vector_ypred = np.array(vector_ypred)
    vector_bias = ((y - np.mean(vector_ypred, axis=0)) ** 2)
    vector_variance = np.var(vector_ypred, axis=0)
    vector_error = (np.sum(((vector_ypred - y) ** 2), axis=0) / N_TESTS)
    bias = np.mean(vector_bias)
    variance = np.mean(vector_variance)
    error = np.mean(vector_error)
    return (bias, variance, error)