How much training data is enough?

Agreement map around Chokwe: dark green where all 25 random forest models saw irrigated agriculture
At a glance
Where Gaza province (Chokwe, Xai-Xai) and Manica province (Manica, Catandica), Mozambique
Data Six-month Sentinel-1 and Sentinel-2 composites from Digital Earth Africa, field polygons from my fieldwork
Method Random forest, SVM and a neural network in R (caret), each setting repeated with 25 random draws, tested on separate field polygons
Published Weitkamp & Karimi (2023), Remote Sensing, and chapter 4 of my PhD

Collecting field data for a satellite map is the expensive part. You walk or drive to fields, check what is growing and whether it is irrigated, and draw a polygon. So I wanted to know how much of that you really need, and what happens if the mix is off or some labels are wrong.

Map of Mozambique with the four study areas: Catandica and Manica in Manica province, Chokwe and Xai-Xai in Gaza province

The two provinces are very different places to map. Gaza is flat and dry, with larger and more regular fields along the Limpopo. Manica is hilly and wetter, with small fields of all shapes.

I took my training data for both provinces and changed it in four ways. For every setting I drew 25 random training sets, trained the three algorithms on each and tested them on the same independent field polygons. Every dot below is one of those models.

What I changed
Province
Measure
Algorithms

Show the numbers
  • Size: the same mix of classes, but only part of the training pixels, from 1% to all of them.
  • Balance: every class gets the same number of pixels.
  • Imbalance: the total stays the same, but irrigated fields go from 1% to 99% of the training pixels.
  • Wrong labels: a share of the training pixels gets relabelled at random as irrigated, rainfed or light vegetation, classes that are easy to confuse in the field.

What came out

A small training set gets you a high overall accuracy, but not a stable map. In both provinces the overall accuracy was above 0.9 with only 5% of the training data, for all three algorithms. In Gaza the median for random forest went from 0.90 with 1% of the data to 0.98 with all of it. Overall accuracy is driven by the big classes, though. For the irrigated fields themselves the results kept improving with more data, and with little data they depend a lot on which samples you happen to draw. With 1% of the data in Manica, SVM found anywhere between 43% and 85% of the irrigated validation pixels, with the same settings.

The mix of the training data should look like the landscape. Accuracy was highest with 10 to 20% irrigated pixels, close to their real share in my field data. Once most of the training pixels were irrigated, the models called almost everything irrigated: in Gaza they found all irrigated fields, but only about a third of what they mapped as irrigated really was (random forest, 99% irrigated pixels). The median overall accuracy fell to 0.57 for random forest and 0.33 for the neural network.

Random forest and SVM are more robust than the neural network. They had less spread between runs and coped better with wrong labels. With 40% wrong labels, SVM in Manica still had a median overall accuracy of 0.98. The neural network sometimes did very well, but whether it did depended more on the luck of the draw.

So, how much is enough? You can test that with your own data. Train on several random subsets and see whether the results stay the same. If they still jump around, go back to the field.

In the paper, the names user’s and producer’s accuracy for the irrigated class are swapped by a mistake in my script. The chart uses the correct ones; overall accuracy is not affected.

Same score, different map

The numbers hide a lot. Here are two SVM models, both trained on all the Gaza training data, only with a different random draw. Their scores are practically identical: an overall accuracy of 0.97 for both, both found 98% of the irrigated validation pixels, and 98% of what they mapped as irrigated was right. Both map about 82 km² of irrigation in this 14 by 14 km area around Chokwe.

But they don’t map the same fields. 23 km² is irrigated in only one of the two, about a quarter of each map. Run 8 puts more irrigation on the north bank, where most of the farmer-led fields are. Run 3 puts more inside the Chokwe Irrigation Scheme.

Two SVM runs around Chokwe with the same accuracy. Green: irrigated. In the last view: grey-green is irrigated in both runs, orange only in run 3, blue only in run 8 (Run 3)
Two SVM runs around Chokwe with the same accuracy. Green: irrigated. In the last view: grey-green is irrigated in both runs, orange only in run 3, blue only in run 8

I picked the pair that differs most, but it is not an exception. Across all 25 SVM runs with all the data, each map had 75 to 91 km² of irrigation. 111 km² was irrigated in at least one run, but only 51 km² in all 25. A validation score tells you how well a map matches your validation fields, not what it does with all the pixels in between.

The maps behind the numbers

These agreement maps show the 25 random forest models for one area around Chokwe, with the two extremes of each scenario side by side. Dark green is where all 25 models saw irrigated agriculture, red is where only one or a few did. Too little or unbalanced training data made the models miss irrigation, mostly the farmer-led fields north of the river. Wrong labels made them see it in the wrong places.

1% of the training data

Size: 1% of the training data

All training data

Size: All training data
Agreement of 25 random forest models around Chokwe. Green: irrigated agriculture, darker when more models agree. Red: irrigated in only a few models

Related: Uncharted territory: my PhD · Mapping smallholder irrigation in Mozambique · Do models transfer?

Timon Weitkamp
Authors
Geospatial analyst: satellite monitoring, change detection and machine learning