Spatial Machine Learning

Why the usual rules break, and what to do instead.

The spatial machine learning path, from why location breaks the usual rules to an honest evaluation. why the usual rules break, and what to do instead1why location breaks itrows are not independent2spatial leakagerandom CV lies3features & samplinggeometry into columns4predict, then evaluateand state the limitsLeakage comes second because every score after it is meaningless until it is dealt with

Spatial data violates the one assumption every default in scikit-learn is built on: that rows are independent. Nearby samples are near-duplicates, so a random train-test split scores a model on data it has effectively seen, and the number that comes out is not wrong so much as answering a question nobody asked. These guides cover leakage and spatial cross-validation, building features that generalise, turning predictions back into a raster, the area of applicability, and reading a prediction map for the artefacts that say the model is extrapolating.

Read the leakage guide second, before any of the modelling ones. A random train/test split on spatial data scores a model on observations it has effectively already seen, and every number after that — accuracy, importance, tuning — is measured against a benchmark that was never real.

The full path, in order

The concepts underneath the work, then each task, then the errors that task produces. Work down, or jump to the step you need.

  1. Spatial Leakage Explained: Why Random Cross-Validation Lies spatial leakage explained 🧭 Concept
  2. Spatial Features Explained: Turning Geometry into Columns spatial features explained 🧭 Concept
  3. How to Sample Training Points from Rasters and Polygons sample training points python ⚙️ How-To
  4. How to Build Spatial Features for a Machine Learning Model build spatial features python ⚙️ How-To
  5. How to Do Spatial Cross-Validation in Python spatial cross validation python ⚙️ How-To
  6. My Model Scores 0.95 in Testing and Fails in the Field model scores high fails in field 🔧 Fix
  7. How to Predict a Continuous Surface with Random Forest random forest spatial prediction python ⚙️ How-To
  8. How to Turn Model Predictions Back into a Raster predictions to raster python ⚙️ How-To
  9. My Prediction Raster Is Striped, Blocky or Full of NoData prediction raster artefacts 🔧 Fix
  10. How to Evaluate a Spatial Model Honestly evaluate spatial model python ⚙️ How-To
  11. Extrapolation in Space Explained: The Area of Applicability area of applicability explained 🧭 Concept
  12. Feature Importance Says Coordinates Are the Best Predictor coordinates dominate feature importance 🔧 Fix
  13. How to Handle Class Imbalance in a Spatial Classifier class imbalance spatial classifier ⚙️ How-To

Topics this path covers

A path is a route; a topic is everything the site has on a subject. Open a topic to see the guides this path skips.

Other ways in