0

Is it possible to run a classification repeatedly and generate the mode of all classified outputs in Google Earth Engine?

I have successfully performed a single-run of the Random Forest classification with a set of training data but have two more independently collected training data points to use.

Is it possible to have a loop introduced in GEE for this task?

The aim of the classification is to delineate waterbodies from surrounding vegetated land cover classes.

Please see link for the codes:
https://code.earthengine.google.com/?accept_repo=users/lexisgis/WaterMapping

Thanks.

user109472
  • 13
  • 1
  • 4

1 Answers1

1

Does classified1.addBands(classified2).addBands(...).mode() do it? It's not clear what you mean by looping over classifiers, but you could do something like this:

var numTrees = ee.List.sequence(5, 50, 5);

var forests = numTrees.map(function(t) {
  return ee.Classifier.randomForest(t)
      .train({
        features: training, 
        classProperty: 'class', 
        inputProperties: image.bandNames()
      });
});

Of course, you might want to substitute different training sets, or even different classifiers for t. Whatever you use, train the classifier, classify the thing, and take the mode of the ensemble.

EDIT: In answer to your answer (and comment), here it is returning classified images:

// Here, image is a previously defined image to classify.
// It has bands match the properties in training.
var images = numTrees.map(function(t) {
      var classifier ee.Classifier.randomForest(t)
          .train({
            features: training, 
            classProperty: 'class', 
            inputProperties: image.bandNames()
          });
      return image.classify(classifier);
});
  • Thanks, generated 3 trained RF classifiers with 3 different training data (see codes below). Cannot seem to figure out how to generate 3 classified images. Could you assist with this please? Still trying to get around GEE. Thanks again. var features = ee.List([train1, train2, train3]); var bands = ['B2', 'B3', 'B4', 'B8', 'nd']; var classifier = features.map(function(t) { return ee.Classifier.randomForest({numberOfTrees: 500}) .train({ features: t, classProperty: 'class', inputProperties: bands }) }); – user109472 Sep 11 '18 at 15:29
  • I have edited the answer accordingly. Please upvote if this helps you. Also, no need to follow up with another answer that asks a follow-up question. – Nicholas Clinton Sep 11 '18 at 16:02