Create probability maps

using the random forest classifier

step 1: add the image and training data

var image = ee.Image("users/servirmekong/Vietnam/Sent2_2017_Forest001")
var referenceData = ee.FeatureCollection("users/servirmekong/Vietnam/ReferenceDataForestTraining");
var chl = ee.FeatureCollection("users/servirmekong/Vietnam/CHL_Boundary").geometry();

step 2: select the training data

var water = referenceData.filter(ee.Filter.eq("land_type","water"));
var crop = referenceData.filter(ee.Filter.eq("land_type","crop"));
var urban = referenceData.filter(ee.Filter.eq("land_type","urban"));
var plantations = referenceData.filter(ee.Filter.eq("land_type","plantations"));
var forest = referenceData.filter(ee.Filter.eq("land_type","forest"));

step 3: Set the class to 1 and all others to 0

var setClass = function(feat){
  return feat.set("land_class",1)

var setOther = function(feat){
  return feat.set("land_class",0)

var primi =
var other =

step 4: Filter the other class to have about an equal number of data points in both categories.

other = other.randomColumn("random")
other = other.filter("random",0.25))

step 5: Display the data points


step 6: Merge the data

var referenceData = other.merge(primi)

step 7: Create the training sample and train the classifier

var trainingSample = image.sampleRegions(referenceData,["land_class"],10);

var bandNames = image.bandNames();
var classifier = ee.Classifier.randomForest(100,0).setOutputMode('PROBABILITY').train(trainingSample,"land_class",bandNames);

step 8: classify the image and add it to the map.

var classification = image.classify(classifier).multiply(100)



One comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s