cross_validate (loo, kfold, spatial_block); grid_search; compare_methods; why LOO is optimistic. This notebook is Part 7. Spatial Interpolation (Chapter 7.5 of 8). The worked example uses CA_pm25_2025.csv (159 California monitors); CA_pm25_grid_predictions.csv (pre-computed surface, for a visual comparison only). The methods come from geolattice.spatial_statistics.interpolate.
Overview
Chapters 7.3-7.4 compared methods by eye. This chapter replaces that with a real, quantified answer: which method actually predicts best, held out fairly, and how much does the answer depend on how it is held out.
Step
What we do
Three CV strategies
loo, kfold, spatial_block(block_size=...): and what each one actually tests
Compare everything
compare_methods: every Chapter 7.3-7.4 method, one shared protocol
The lesson
Leave-one-out is optimistic for a clustered network; spatial blocks show the honest picture
Tune
grid_search over IDW’s power/k
A caveat, revisited
One more look at the undocumented pre-computed surface: comparison only, never validation
Locate the repository root, import the spatial-statistics helpers, and point DATA at the example files.
Installation. This notebook needs installation option 3 (core, spatial analysis and spatial statistics): pip install "geolattice[statistics]". See “Installation options” in the GeoLattice README.
cross_validate(model, coords, values, method=...) supports three fold strategies:
loo: leave-one-out: hold out each point in turn, predict it from every other point. Maximizes training data per fold, but every held-out point still has its closest neighbours available to help predict it.
kfold: ordinary \(k\)-fold: partition randomly into \(k\) groups, ignoring spatial location entirely when assigning folds.
spatial_block(block_size=...): partition into spatial blocks of the given size, then hold out whole blocks. This is the only strategy that mimics what actually matters in practice: predicting into a region with no nearby training data at all, not just a single point removed from an otherwise-intact neighbourhood.
Ordinary kriging comes out on top by every metric, lowest RMSE, lowest MAE, highest \(R^2\), with IDW and TIN close behind, and nearest-neighbour clearly the weakest. This matches the reference validation this Part was built around almost exactly.
Every method’s RMSE rises substantially moving from LOO to spatial-block CV: by roughly a quarter for nearest-neighbour up to more than 50% for kriging and IDW: and \(R^2\) collapses to somewhere near zero for all of them. This is not a sign that these methods are secretly bad: it is LOO revealing its own optimism. In a clustered monitor network (Bay Area, Los Angeles: many stations within a few kilometres of each other), leaving out one monitor still leaves its near-duplicate neighbours in the training set, so LOO tests something close to “can this method interpolate between two adjacent, highly correlated monitors”: a much easier problem than the one that actually matters in practice: predicting PM2.5 somewhere with no nearby monitor at all. Spatial-block CV, holding out entire 120 km blocks, tests exactly that harder, more honest question: and with the variogram’s own $$133 km range (Chapter 7.4) larger than the 120 km block size, held-out blocks sit almost entirely beyond the range where any training data can help, which is exactly why every method’s skill collapses toward \(R^2\approx0\).
The ranking itself changes, too: kriging is the clear winner under LOO, but under spatial-block CV TIN takes over as the best method, with kriging dropping to third. This is a genuinely useful, non-obvious finding rather than a coincidence of one random seed: kriging’s advantage over simpler methods comes largely from correctly down-weighting redundant nearby observations (Chapter 7.4, Section 5), a skill that stops mattering once nearby observations are exactly what spatial-block CV removes. Which method looks “best” is not fixed, it depends on which prediction problem the validation protocol actually poses. This same clustered-network-vs-holdout-region distinction is exactly what Part 8 (Spatial Sampling and Design) addresses from the design side: choosing where to place monitors in the first place, rather than living with whatever network already exists.
Tuning IDW by Grid Search
grid_search tries every combination of hyperparameters and reports cross-validated performance, sorted by the chosen metric: replacing “power=2 because that is the textbook default” with an actual answer for this specific network.
The best combination (printed at the top of the table) sits close to the conventional default of power=2, reassuring, but worth having actually checked rather than assumed, since a genuinely different optimum would have been just as easy for grid_search to reveal.
A Visual Check Against the Pre-Computed Surface
Chapter 7.2 flagged CA_pm25_grid_predictions.csv’s undocumented provenance. A visual comparison: not a validation: against this chapter’s own cross-validated kriging fit is still worth doing, as a sanity check that the two broadly agree in overall pattern.
The broad spatial pattern agrees, both surfaces show similar high/low regions, which is a reasonable sanity check that nothing has gone badly wrong with either. It is not evidence that either surface is “correct”: without knowing how the pre-computed file was produced, agreement could just as easily mean both interpolators share the same weaknesses (e.g., both trained on annual rather than monthly means, or both smoothing over the same sparse region in the same way) as it could mean both are accurate. Section 4-6’s cross-validated RMSE remains the only real evidence of accuracy in this chapter.
Summary and Conclusions
This chapter replaced visual comparison with an honest, quantified evaluation of every interpolator introduced so far.
What we did
Explained the three cross-validation strategies this library supports and what each one actually tests.
Compared five methods by leave-one-out: kriging wins, nearest-neighbour is clearly worst, consistent with this Part’s reference validation.
Re-ran the identical comparison under spatial-block CV and found every method’s RMSE rises substantially (roughly 25% to over 50%, depending on the method), with \(R^2\) collapsing toward zero: a concrete, measured demonstration that LOO substantially overstates real-world predictive skill for this clustered monitor network. The ranking itself flips: kriging wins under LOO but TIN wins under spatial-block CV, because kriging’s main advantage, down-weighting redundant nearby observations, stops mattering once nearby observations are exactly what gets held out.
Tuned IDW’s power/k by grid search, confirming the conventional power=2 default is close to optimal here: checked, not assumed.
Compared this chapter’s own validated kriging surface against the undocumented pre-computed file, treating agreement as a sanity check only, never as validation.
Practical takeaways
Report spatial-block (or another holdout-region) cross-validation whenever the real use case is predicting into genuinely unsampled areas: LOO answers a different, easier question.
A cross-validated grid search beats defaulting to a textbook hyperparameter value, even when the two happen to agree in the end.
Never treat an undocumented “reference” surface as ground truth; use it only for a sanity-check comparison against a method that has actually been cross-validated.
Next steps
Chapter 7.6 (Covariate-Assisted Interpolation) asks whether letting a model use covariates, not just spatial location, can outperform every method compared in this chapter.
Further reading
Textbooks
Reference
Notes
Roberts, D. R. et al. (2017). Cross-validation strategies for data with temporal, spatial, hierarchical, or phylogenetic structure. Ecography, 40, 913-929.
The case for spatial-block CV over naive random/LOO splits, directly motivating Sections 5-6