How To Use Supervised Land Classification With Random Forest In Supervised Land Classification With Random Forest.

Stephen Chege
2 min readJun 1, 2021

--

Random Forest (RF) algorithm is one of the best algorithms for classification. RF is able for classifying large data with accuracy. It is a learning method in which number of decision trees are constructed at the time of training and outputs of the modal predicted by the individual trees.

Working of Random Forest Algorithm

We can understand the working of Random Forest algorithm with the help of following steps −

Step 1 − First, start with the selection of random samples from a given dataset.

Step 2 − Next, this algorithm will construct a decision tree for every sample. Then it will get the prediction result from every decision tree.

Step 3 − In this step, voting will be performed for every predicted result.

Step 4 − At last, select the most voted prediction result as the final prediction result.

Load up your GEE

var Dubai =
/* color: #d63000 / / shown: false / / displayProperties: [
{
"type": "rectangle"
}
] */
ee.Geometry.Polygon(
[[[55.25107984413207, 25.218326927334207],
[55.25107984413207, 25.160541442818463],
[55.38291578163207, 25.160541442818463],
[55.38291578163207, 25.218326927334207]]], null, false);
// import the satellite data from the European Space Agency
var S2 = ee.ImageCollection("COPERNICUS/S2");
//filter for Dubai
S2 = S2.filterBounds(Dubai);
print(S2);
//filter for date
S2 = S2.filterDate("2020-01-01", "2020-05-11");
print(S2);
var image = ee.Image(S2.first());
print(image)
Map.addLayer(image,{min:0,max:3000,bands:"B4,B3,B2"}, "Dubai");//Map.addLayer(image,{min:0,max:3000,bands:"B8,B4,B3"}, "Dubai");// set the selection bands
var predictionBands = image.bandNames();
//print (predictionBands);
var trainingData = Water.merge(Vegetation).merge(Urban).merge(Sand).merge(Rocks);// sample the regions
var classifierTraining = image.select(predictionBands).sampleRegions(
{collection: trainingData,
properties: ['land_class'], scale: 20 });
//train the classifier
var classifier = ee.Classifier.smileRandomForest(300).train({features:classifierTraining,
classProperty:'land_class',
inputProperties: predictionBands});
// get the classified image
var classified = image.select(predictionBands).classify(classifier);
var Palette = [
'aec3d4', // Water
'369b47', // Vegetation
'cc0013', // Urban
'cdb33b', // Sand
'f7e084' // barren
];
//add the classified image to the map
Map.addLayer(classified, {min: 1, max: 5, palette: Palette}, "LULC Dubai");

This should be your end result

--

--

Stephen Chege
Stephen Chege

Written by Stephen Chege

Providing Geospatial data science related content. schege47@gmail.com

No responses yet