concept

Generalization and validation

Evaluate a fresh mean baseline on each fixed round-robin fold; return MAE by fold.

Formal Syntax & Structure

artificial-intelligence syntaxartificial-intelligence
mean_baseline_cv(values, folds)

Working Example

Example Snippetartificial-intelligence
def mean_baseline_cv(values, folds):    n = len(values)    if not 2 <= folds <= n:        raise ValueError("Need between 2 and n folds")    errors = []    for f in range(folds):        train = [v for i, v in enumerate(values) if i % folds != f]        valid = [v for i, v in enumerate(values) if i % folds == f]        prediction = sum(train) / len(train)        errors.append(sum(abs(v - prediction) for v in valid) / len(valid))    return errors
scores = mean_baseline_cv([2, 4, 6, 8, 10, 12], 3)print(scores)print(sum(scores) / len(scores))