Skip to main content

Merging Classes

This page continues the Minnesota land cover example from Getting a Dataset Ready for Modeling.

The Minnesota 2023 Cropland Data Layer contains 53 classes. Many of them cover only a tiny part of the state, and a model cannot learn a class from a handful of examples. Before sampling labels, I merged the 53 classes into 11.

Merging always raises the question of what information is lost. I merged classes only when at least one of the following was true:

  1. The original labels are unreliable. NASS publishes an accuracy report for every state and year. If a class is mapped incorrectly much of the time, keeping it separate trains the model on noisy labels rather than preserving real information.
  2. The class is too rare to learn. Classes that cover less than about 0.1% of the state provide too few examples for the model to learn on their own.
  3. The classes look alike in satellite imagery and the distinction does not matter for my use. If the model cannot separate two classes from Sentinel-2 imagery, keeping them separate adds false precision.

From 53 classes to 11​

Merged classCDL classes (code)Share of MinnesotaReason
CornCorn (1), Sweet Corn (12)16.4%Sweet corn is rare (0.2%) and looks like field corn until its earlier harvest
SoybeansSoybeans (5)14.2%Not merged
Small grainsSpring Wheat (23), Winter Wheat (24), Durum Wheat (22), Barley (21), Oats (28), Rye (27), Triticale (205), Speltz (30), Millet (29), Buckwheat (39)2.7%Similar growing season; most are rare and unreliable
Other cropsSugarbeets (41), Dry Beans (42), Potatoes (43), Sunflower (6), Canola (31), Peas (53), Flaxseed (32), Mustard (35), Sorghum (4), Carrots (206), Other Crops (44), Double Crop Corn/Soybeans (241)1.5%Each is rare; together they are large enough to learn
Alfalfa and hayAlfalfa (36), Other Hay/Non Alfalfa (37), Clover/Wildflowers (58), Sod/Grass Seed (59), Switchgrass (60)2.3%Perennial forage crops cut several times a season
Grassland and shrublandGrassland/Pasture (176), Shrubland (152)7.7%Shrubland is rare and unreliable
ForestDeciduous Forest (141), Evergreen Forest (142), Mixed Forest (143)19.0%Evergreen and mixed forest are unreliable
WetlandsWoody Wetlands (190), Herbaceous Wetlands (195)24.8%The distinction does not matter for this model
Open waterOpen Water (111)5.8%Not merged
DevelopedDeveloped/Open Space (121), Low Intensity (122), Medium Intensity (123), High Intensity (124)5.5%Development intensity does not matter for this model
BarrenBarren (131)0.2%Not merged

I removed ten classes entirely. Fallow/Idle Cropland (61) can look like bare soil, weeds, or grass depending on the field. The other nine are too rare to sample: Christmas Trees (70), Apples (68), Grapes (69), Strawberries (221), Pumpkins (229), Peppers (216), Watermelons (48), Misc Vegs & Fruits (47), and Vetch (224). Together they cover less than 0.02% of the state. Shares of Minnesota are computed from every pixel in the map.

Evidence that the merges lose little​

NASS's 2023 Minnesota accuracy report lists a user's accuracy for each class: of the pixels the map labels as a class, the percentage that are actually that class. Most of the classes I merged away have low user's accuracy, and each merges into a more reliable class.

Merged classLess reliable classes merged in (user's accuracy)Most reliable class in the group (user's accuracy)
Small grainsOats (49%), Rye (70%), Winter Wheat (75%)Spring Wheat (93%)
Alfalfa and hayClover/Wildflowers (9%), Other Hay/Non Alfalfa (49%)Alfalfa (75%)
Grassland and shrublandShrubland (39%)Grassland/Pasture (59%)
ForestMixed Forest (58%), Evergreen Forest (61%)Deciduous Forest (74%)
CornSweet Corn (89%)Corn (96%)

What I gave up​

Not every merge is free. The four developed classes are mapped reliably (79% to 97% user's accuracy), so merging them discards a real distinction. I accepted that because this model is meant to map land cover, not urban density. If your use depends on a distinction like this one, keep those classes separate.

Woody wetlands and forest also look nearly identical in satellite imagery. I kept woody wetlands in Wetlands rather than merging them into Forest, because wetlands matter for land cover mapping, but I expect the model to confuse them. The confusion matrix after training will show how often it does.

Keeping the original class​

Each label I upload keeps its original CDL code as an extra field alongside the merged class. Studio imports that field as metadata, so I, or anyone reviewing the model, can regroup the labels later without rebuilding the dataset.

Checking the merges after training​

The strongest evidence comes from training itself. To test a merge, train one model with the finer classes and look at its confusion matrix. If the model regularly confuses two classes, merging them loses nothing the model could have delivered.