Why Random Train-Test Splits Flatter Flood Models
The usual way to test a machine-learning model is to shuffle the data, keep a fifth aside and score on it. For a fast flood model trained on gridded simulator runs, that habit measures the wrong thing. Neighbouring cells carry almost the same depth, and the same terrain appears under every storm, so a shuffled test set is mostly made of cells the model has already seen in all but name. The score it gives is real, but it answers a question nobody asked.
This post shows how much the choice of held-out data moves a flood model's score, why, and how to choose the split that matches the claim you want to make. It also covers a quieter problem: training sets that fill up with runs where nothing happens, which flatter some metrics and not others. The numbers come from a small synthetic lab; the habits come from building fast flood models, where holding out whole areas changed the picture.
This is the second post in a series on checking flood models. The first, on verification and validation, explains why a score against the simulator is not a score against reality. Everything here is about making the score against the simulator honest.
In short
- In the lab, averaged over ten seeds, a nearest-neighbour model scores 0.751 with random cells held out and 0.611 with whole tiles of terrain held out; boosted trees score 0.693 and 0.591. Random cells beat whole tiles in all ten seeds, for both models. Only the tile split estimates how a model does on ground it has not seen.
- Holding out one storm of four is a single draw: the nearest-neighbour score runs from 0.49 to 0.86 depending mostly on which storm is left out.
- A feature that names the place, such as position, raises the random-split score and lowers the score on new terrain.
- Neighbouring cells are nearly copies of each other, so a random split's test set has far fewer independent cases than it has cells.
- Runs where almost nothing floods lift accuracy from 0.77 to 0.87 and leave the critical success index roughly where it was. Check the corpus before training.
Why cells leak
A flood depth map is smooth. Water at one cell is at almost the same level as water at the next, and the depth differs only by the change in ground height. Hold out a random quarter of the cells and almost every test cell has its neighbours in the training set:
How much information does such a test set really hold? For a series whose neighbours are correlated with coefficient ρ, the effective number of independent values among n is roughly, by a rule borrowed from time-series practice (Bretherton et al. 1999),
neff ≈ n (1 − ρ) / (1 + ρ)
In the lab, ρ for neighbouring wet cells is 0.951, which by this formula makes a 400-cell tile worth about 10 independent values. Read that as an order of magnitude, not a count: the formula assumes the correlation shrinks by the same factor at every step, and the lab's falls faster, as the next figure shows. Strictly, a test score depends on how correlated the model's errors are, not the depths; the depths are used here because they need no model. Real terrain grids are finer than the lab's, which makes neighbours more alike, not less.
The resemblance fades with distance. In the lab, the correlation falls by half at about four cells and is close to zero by seven:
The formula above turns that correlation into a count of independent cases, which collapses as neighbours become more alike:
A test score built on millions of cells can rest on a much smaller number of genuinely different situations.
Three ways to hold out
A corpus for a fast flood model is a set of runs: each one a piece of terrain under one storm. Test cases can be held out by cell, by storm or by piece of terrain, and each choice answers a different question:
| Held out | What still leaks into training | What the score estimates |
|---|---|---|
| Random cells | Neighbouring cells of the same run | Filling gaps inside runs already simulated |
| Whole storms | The same terrain under other storms | New storms on terrain already in the corpus |
| Whole tiles | Nothing from those tiles | New terrain under storms like those in the corpus |
In the lab, two models are trained and scored on the same synthetic corpus, split each of the three ways: a k-nearest-neighbour model, which predicts from the most similar training cells, and gradient-boosted trees, a standard choice for tabular data. Each split is repeated over ten seeds, with new terrain every time:
The same results as numbers, with accuracy for comparison, which falls less because it also counts dry cells:
| Held out | Model | CSI: mean (range) | Depth error | Accuracy |
|---|---|---|---|---|
| Random cells | Nearest neighbours | 0.751 (0.69 to 0.78) | 0.32 m | 0.87 |
| Random cells | Boosted trees | 0.693 (0.61 to 0.76) | 0.28 m | 0.82 |
| Whole storms | Nearest neighbours | 0.705 (0.49 to 0.86) | 0.42 m | 0.85 |
| Whole storms | Boosted trees | 0.664 (0.47 to 0.83) | 0.41 m | 0.81 |
| Whole tiles | Nearest neighbours | 0.611 (0.48 to 0.67) | 0.48 m | 0.77 |
| Whole tiles | Boosted trees | 0.591 (0.45 to 0.70) | 0.38 m | 0.74 |
Nothing about either model changed between the bars. The random split credits a model with knowing what it was shown; the storm split, with knowing the terrain; only the tile split asks it to handle ground it has never seen. Random cells scored above whole tiles in every seed, by 0.14 on average for nearest neighbours (0.08 to 0.25) and by 0.10 for the trees (0.01 to 0.24). A model meant for new places should be scored on new places.
The storm split is the unstable one. With four storms, holding out a quarter means holding out one, and the score depends on which. When the lightest storm is left out, its thin, patchy wet area is hard to predict from heavier storms and the index falls to about 0.49 for nearest neighbours and 0.47 for the trees; for each of the other three it lies between 0.68 and 0.86. Over ten seeds the random split beat the storm split only five times. A split with few groups is a single draw, and the honest report is one score per held-out group, which here would show the light storm plainly.
The second model does not settle which is better, because that depends on the metric. The trees have lower depth error in most seeds and a lower critical success index in nearly all: they miss fewer wet cells but raise more false alarms, mostly shallow ones, at a median of about 0.16 m against about 0.3 m for nearest neighbours in two seeds checked. What both models agree on is the direction of the gap between random cells and new terrain.
The same lesson has been learned in other fields that map from gridded data. Ploton et al. (2020) reproduced the method behind large-scale maps of forest biomass and showed that tests ignoring the similarity of nearby points overstated its predictive power. Roberts et al. (2017) review the remedies for data with spatial, temporal or grouped structure; the core of them is to split by group, not by row.
Features that name the place
Leakage also runs through the inputs. A feature that identifies where a cell is (its coordinates, a tile identifier, a distance to a fixed landmark) lets a model recall nearby training cells instead of learning how water moves. Under a random split that looks like skill. Under a tile split it misleads:
Dropping position costs the random split 0.03 and gains the tile split 0.05. A team that chose features by the random-split score would have kept the feature that makes the model worse where it will be used. Features should be chosen on the split that matches the claim, for the same reason the headline score should be.
One score per area
A pooled score over several held-out areas is an average, and averages hide the hard places. Leaving out one tile at a time in the lab gives ten scores:
The spread, 0.15, is about as large as the average gap between the random and tile splits above, 0.14. For a model meant for new places, the weakest held-out area is as informative as the mean, and the number of areas tested is part of the result.
Storms leak too
Holding out storms is weaker than it looks when storms are variations on one event. A corpus built by scaling one recorded storm up and down, or shifting it by an hour, contains many near-copies. Holding out one of them tests the model on a storm it has seen in all but scale. The split has to follow the real unit of independence: distinct weather events, not distinct runs.
Terrain has the same trap at a larger scale. Two tiles cut from the same valley share its slope, soils and drainage pattern. Holding out one of them tests less than holding out a different valley. When there are few independent places, the honest statement is the number of places the model has been tested on, beside the score.
Choosing the split
The right split follows from the claim:
| If the claim is | Hold out | Report beside the score |
|---|---|---|
| Fast answers for new storms on a place already simulated | Whole storms, as distinct weather events | The number of distinct events |
| It works in a new place | Whole areas, with a buffer between training and test | A score per area, and the number of areas |
| It works in a new kind of place | Whole regions or terrain types | The number of regions, and how they differ |
Three practical details matter as much as the choice itself. Leave a buffer: if test tiles touch training tiles, the cells along the shared edge still leak, so drop a strip at the boundary at least as wide as the distance over which neighbours stop resembling each other, four to seven cells in the lab, or pick tiles apart from each other.
Report scores per held-out area, not only pooled; one easy area can hide two hard ones. And keep one area untouched until the end. Every decision made while looking at a test score (a threshold, a feature, a stopping point) leaks a little of that test into the model.
Runs where nothing happens
A corpus fills up with degenerate runs without anyone choosing them. A light storm on high ground leaves every cell dry; a huge storm on a basin floods all of it. Such runs are cheap to predict and inflate any metric that rewards getting dry cells right. In the lab, adding runs where almost nothing floods, on the same terrain, moves accuracy and leaves the critical success index roughly where it was, between 0.62 and 0.66:
Depth error falls in the same way, from 0.44 m to 0.31 m, because a dry cell predicted dry has no error at all. A metric that improves when the corpus gets easier is measuring the corpus, not the model.
Two checks catch most of this before any training, at almost no cost:
| Check | Rule | Flagged in the lab |
|---|---|---|
| Nearly dry or nearly full runs | Wet share below 5% or above 95% | 20 of 70 runs |
| Near-duplicate runs | Same terrain, wet areas overlapping by more than 95% | 9 pairs, storms of 60 and 62 units |
Flagged runs are not always wrong to keep. Dry runs teach a model where water does not go. But they should be there by choice, counted, and kept out of the headline score or reported beside a score that ignores them.
A small lab you can run
The lab is synthetic: square tiles of random terrain, water that fills from the lowest cell, and two models with six features per cell, both in plain Python. Download the lab (zip), then run python run_all.py and python -m pytest -q. Its seven experiments produce the other figures, and python seeds.py produces the two-model comparison over ten seeds. The boosted trees are a short implementation in the lab; scikit-learn's histogram gradient boosting with the same settings gave scores within 0.02 on one seed. Each experiment draws its own terrain and test sets, so the same split can score a few hundredths differently from one figure to another: compare within a figure, not across figures. Its eight tests check each claim against the alternative it rejects, for example that a random split shares terrain between training and test while a tile split shares none.
Limits of this post
- The lab's water fills by volume on small tiles. Real floods flow and drain, and real grids are larger and finer.
- Two models are a small sample. Both put random cells above new terrain in every seed, with gaps of different size; other models will differ again in size, and the lab has not tested them.
- Ten seeds give a range, not a confidence interval. The ranges quoted are the lowest and highest seed.
- The effective-sample formula assumes one correlation between neighbours. Real depth fields are correlated over many distances at once.
Sources
- C. S. Bretherton et al., The effective number of spatial degrees of freedom of a time-varying field, Journal of Climate 12, 1990 (1999).
- D. R. Roberts et al., Cross-validation strategies for data with temporal, spatial, hierarchical, or phylogenetic structure, Ecography 40, 913 (2017).
- P. Ploton et al., Spatial validation reveals poor predictive performance of large-scale ecological mapping models, Nature Communications 11, 4540 (2020).