How To Validated A Supervised Image Accuracy Using Regression In GEE
Validation is often defined as the process of determining the degree to which a model is an accurate representation of the real world from the perspective of its intended uses. Validation is crucial as industries and governments depend increasingly on predictions by computer models to justify their decisions.
When it comes to supervised or unsupervised image classification with GEE, you have to make sure the algorithm you have selected achieves maximum accuracy. One can do this is by applying regression, this process will inform you how accurate your algorithm is. Lets have a look.
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);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");// you can create a validation set in a similar vay and cross check your resultsvar validationData = ValWater.merge(ValVegetation).merge(ValUrban).merge(ValSand).merge(ValRocks);var validation = image.sampleRegions({collection: validationData, properties: ['land_class'], scale:20,tileScale: 16});var validated = validation.classify(classifier);// Get confusion matrix and user / producer's accuracies, overall accuracires and Kappa
var testAccuracy = validated.errorMatrix('land_class', 'classification');
print('Validation error matrix: ', testAccuracy);
print('Validation overall accuracy: ', testAccuracy.accuracy(), testAccuracy.consumersAccuracy(), testAccuracy.kappa(),
testAccuracy.producersAccuracy());
Once you run the code, the validatio accuracy will be displayed on the console,Top right of your screen.
The accuracy should be hovering below one percent. In this case, it stands at 0.700 which is good enough.