concept

Train, validation and test sets

Partition time-ordered observations with two increasing boundaries. Train precedes validation, which precedes test; account for actual outcome availability, group dependence and sufficient evaluation counts. This is teaching syntax, not a public library API.

Formal Syntax & Structure

artificial-intelligence syntaxartificial-intelligence
chronological_split(records, validation_start, test_start)

Working Example

Example Snippetartificial-intelligence
def chronological_split(records, validation_start, test_start):    if validation_start >= test_start:        raise ValueError('Cutoffs must be increasing')    train, validation, test = [], [], []    for day, order in sorted(records):        if day < validation_start:            train.append(order)        elif day < test_start:            validation.append(order)        else:            test.append(order)    return [train, validation, test]
records = [(6, 'F'), (1, 'A'), (4, 'D'),           (2, 'B'), (5, 'E'), (3, 'C')]print(chronological_split(records, 4, 6))