Artificial intelligence • Original RRTutors lesson
Training, Validation, and Test Sets
Use separate data partitions to fit model parameters, choose settings, and estimate final performance.
Concept and explanation
The training set fits model parameters. Validation data supports hyperparameter and model selection. A test set should be consulted sparingly after choices are complete. For temporal or grouped data, a random split can leak related or future information, so split design must reflect real deployment.
How to apply it
Choose a split that matches the prediction setting, stratify where appropriate, and prevent the same person or entity crossing partitions when that would leak information.
Worked example
A demand forecast should train on earlier dates and evaluate on later dates to simulate future use.
Illustrative Python example
train = records[:train_end]
validation = records[train_end:validation_end]
test = records[validation_end:]
print(len(train), len(validation), len(test))
Expected result
Chronological partitions preserve the direction of time.
Limitations and cautions
Repeatedly tuning against a test set turns it into another validation set and biases reported performance.
Practice exercise
Design a split for repeated customer records and explain how you avoid customer leakage.
Key takeaway: Evaluation is trustworthy only when the split mirrors the intended generalization task.