Spatial machine learning
Features, spatial cross-validation, prediction rasters and the area a model can honestly speak for.
Machine learning on spatial data breaks two assumptions at once. Rows are not independent, because neighbouring observations are nearly the same observation; and prediction usually extends over ground the training data never covered.
Both show up as an accuracy figure that is too good. A random train/test split puts a sample and its neighbour on opposite sides of the split, so the model is scored on data it has effectively seen — block or spatial cross-validation is what measures whether it transfers. Adding raw coordinates as features makes this worse in an interesting way: they genuinely capture structure the covariates miss, and they are also a lookup table for this study area and meaningless outside it.
The pages below cover what the effective sample size actually is, how to split and validate spatially, how to build a prediction raster, and how to state the area a model can honestly speak for.
🧭 Start with the concepts
The ideas the how-to guides below assume you already have.
⚙️ Then do the task
Step-by-step walkthroughs with code you can copy and adapt.
- How to Classify Land Cover from Satellite Imagery in Python
- How to Sample Training Points from Rasters and Polygons
- How to Build Spatial Features for a Machine Learning Model
- How to Do Spatial Cross-Validation in Python
- How to Predict a Continuous Surface with Random Forest
- How to Turn Model Predictions Back into a Raster
Show every how-to guide in this topic
- How to Evaluate a Spatial Model Honestly
- How to Handle Class Imbalance in a Spatial Classifier
- How to classify crop types from a satellite time series
- How to fit a species distribution model in Python
- How to Build a Land-Use Regression Model for NO2 in Python
- How to Cluster Urban Fabric Types in Python
🔧 When it breaks
The errors this topic produces, with the cause explained rather than just the command.
Learning paths through this topic
A curated route rather than a list — the guides in the order that builds on itself.
Related topics
Subjects that keep coming up alongside this one, most overlap first.