A crop map is used where nobody collected labels. It is usually tested on a random sample of labelled fields, most of which have labelled neighbours a few dozen metres away. I measured how much that flatters the result.
Temporal CNN, seven crop classes. Macro-F1 averages the F1 score over classes, so rare crops count as much as maize. Scores are low in absolute terms: this is a hard task, and the subject here is the gap between the columns.
The answer
The better of two models scores a macro-F1 of 0.29 on a random sample of fields, 0.25 when whole 2 km blocks are held out, and 0.21 when a whole image tile is held out. The random split overstates performance in a new area by 0.08 (95% interval 0.065 to 0.100), more than a quarter of the headline score.
Dots are the mean of five seeds. Bars are 95% intervals from resampling 2 km blocks, which keeps neighbouring errors together. The grey tick is a model that always answers maize.
Overall accuracy hides this. It moves by less than two points across the three designs and sits close to the 44.5% from always answering maize. The loss is in the minority crops: recall on common bean falls from 15% on random fields to under 1% on a held-out tile. Away from its training area, the model falls back on maize and cassava.
Where the errors are
Every labelled field, placed with coordinates I recovered for this study. Switch the test design to see which fields the model gets wrong.
Grey squares are the 2 km blocks that contain labels. Field positions are accurate to a few metres.
What I expected and did not find
I wrote down four hypotheses before the full run. One of them was wrong. I expected scores to keep falling as the gap between training and test fields widened. They barely move.
Solid lines enforce a gap. Dotted lines are the control: the same number of training fields, chosen at random, with no gap. Where the two run together, the smaller training set explains the change and distance does not.
Once training-set size is controlled, a gap of up to 1 km costs nothing measurable for either model. The leak in a random split is very local, and two independent measurements agree. In PostGIS, the median distance from a labelled field to its nearest labelled neighbour is 60 m, and 38.5% of fields grow the same crop as that neighbour against 29.0% expected by chance. And in the imagery itself, likeness between fields fades within a few hundred metres:
Empirical semivariogram of field-mean NDVI on the greenest date, from 400,000 random field pairs. Fields 250 m apart show 79% of the overall variance; by 750 m it is 90%.
Holding out a 2 km block already removes those neighbours, so a further gap adds little. The larger drop from block to tile is a change of place, not of distance.
The four hypotheses
- Random splits overstate accuracy: supported. Both models score highest on random fields, lower on held-out blocks and lowest on a held-out tile. All 1,000 resamples agree.
- The gap grows with distance, then levels off: not supported. The loss happens at very short range.
- The neural model loses more than the forest: supported. Its random-to-tile gap is larger by 0.041 (0.021 to 0.059), though it remains the better model everywhere.
- Confidence is less trustworthy off-site: mixed. Calibration error rises for the neural model and falls for the forest.
The dataset had no coordinates
The CV4A Kenya Crop Type rasters are published without a coordinate system, which rules out any spatial analysis as shipped. I restored them from two measurements.
- The four tiles are one mosaic. Edge rows and columns of neighbouring tiles correlate at 0.97 to 0.99, against 0.90 for adjacent columns inside a tile.
- One tile overlaps a georeferenced sibling dataset. For the same date and band, a chip from each of its three tiles matches with a normalized cross-correlation of 1.000 at a single offset.
The three matches agree to within 2.6 m, under a third of a pixel, and the recovered fields land in Busia County as the documentation says. One command reproduces the check.
How it was done
- Data. Four Sentinel-2 tiles, 13 dates from June to November 2019, 12 bands and a cloud mask. 4,688 field polygons, 3,286 with public labels, seven classes including four intercrops.
- Features. Cloud-masked band means per field and date, with three vegetation and water indices. Gaps are interpolated inside each field; anything else is imputed from training rows inside each fold.
- Models. A random forest and a small temporal convolutional network in PyTorch. 135 runs in all, five seeds each.
- PostGIS. Field polygons live in PostGIS. The block assignment and buffer exclusion that define the splits are written in SQL as well as NumPy, with tests that the two agree.
- Uncertainty. One set of 1,000 resamples of 2 km blocks shared by every statistic, so differences are paired.
- Plan and review. The plan was written before the full run but not lodged with an outside registry. A code review before the results were produced changed how the intervals are computed and added the size-matched control; every change is logged. The plan named random minus block (0.04) as its headline, and the larger tile gap is shown beside it.
- Code. The pipeline, the plan, the tests and every result file are in a public repository on GitHub.
The numbers
Limits
- One region and one season. Nothing here says how large the gap is elsewhere.
- Neither model is tuned, and both are far from useful accuracy on the minority crops. A stronger model could show a different gap.
- Only four tiles, and one of them holds two thirds of the labels.
- Part of the tile drop is a change in which crops are grown, not only in how they look.
- Fields are small: the median is 10 pixels.
Data: CV4A Kenya Crop Type Competition, PlantVillage and Radiant Earth Foundation (doi:10.34911/rdnt.dw605x). Charts drawn with D3.