1. Leak-free data split
medium25 XPWrite split(records, key, ratios=(0.8, 0.1, 0.1), seed=0) returning (train, val, test). Records sharing the same key(record) (e.g. same customer) must land in the same split to prevent leakage. Shuffle the unique keys with random.Random(seed) (sorted first, for determinism), then assign keys to splits by the cumulative ratios over the number of keys.
Ctrl/⌘ + Enter runs the tests · Esc then Tab leaves the editor