accuracy assessment of classifier

Get the accuracy of you random forest classifier

step 1: add the image and training data

// add the image
var image = ee.Image("users/servirmekong/Vietnam/Sent2_2017_Forest001")
// add the reference data
var referenceData = ee.FeatureCollection("users/servirmekong/Vietnam/ReferenceDataForestTraining");

step 2:  select the different land cover categories

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: Display the data

Map.addLayer(image,{min:0,max:6000,bands:"swir1,nir1,red"},"sentinel 2 image");


step 4: select 80% of the reference data

var sample = referenceData.randomColumn("random");
sample = sample.filter("random",0.8))

step 5: Sample the image

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

step 6: apply the classifier.

var bandNames = image.bandNames()
var classifier = ee.Classifier.randomForest(10,0).train(trainingSample,"land_class",bandNames);

step 7: print all statistics of the classifier.

var confMatrix = classifier.confusionMatrix();


var OA = confMatrix.accuracy();
var CA = confMatrix.consumersAccuracy();
var Kappa = confMatrix.kappa();
var Order = confMatrix.order();
var PA = confMatrix.producersAccuracy();

print(confMatrix,'Confusion Matrix');
print(OA,'Overall Accuracy');
print(CA,'Consumers Accuracy');
print(PA,'Producers Accuracy');


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 )

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s