5

I'm using Google Earth Engine for Land Cover change detection, I would like to know whether we can generate Error Matrix (Accuracy Assessment) for a classified image in Earth Engine or not?

1 Answer 1

5

Yes, you can. This page describes how to do it.

// Make a Random Forest classifier and train it.
var classifier = ee.Classifier.randomForest(10)
    .train({
      features: training, 
      classProperty: 'Land_Cover_Type_1',
      inputProperties: ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7']
    });

// Classify the input imagery.
var classified = input.classify(classifier);

// Get a confusion matrix representing resubstitution accuracy.
var trainAccuracy = classifier.confusionMatrix();
print('Resubstitution error matrix: ', trainAccuracy);
print('Training overall accuracy: ', trainAccuracy.accuracy());

// Sample the input with a different random seed to get validation data.
var validation = input.addBands(modis).sample({
  numPixels: 5000,
  seed: 1
  // Filter the result to get rid of any null pixels.
}).filter(ee.Filter.neq('B1', null));

// Classify the validation data.
var validated = validation.classify(classifier);

// Get a confusion matrix representing expected accuracy.
var testAccuracy = validated.errorMatrix('Land_Cover_Type_1', 'classification');
print('Validation error matrix: ', testAccuracy);
print('Validation overall accuracy: ', testAccuracy.accuracy());

It's worth noting that you can also take a single sample and partition it:

// The randomColumn() method will add a column of uniform random
// numbers in a column named 'random' by default.
var sample = input.addBands(modis).sample({...}).randomColumn()
var split = 0.7;  // Roughly 70% training, 30% testing.
var training = sample.filter(ee.Filter.lt('random', split));
var testing = sample.filter(ee.Filter.gte('random', split));
2
  • Accuracy level came almost 90 %, which I think it shouldn't be. Anyway, I appreciate your help, Thank you :) Commented Jul 27, 2017 at 16:49
  • 1
    It is important to distinguish between re-substitution accuracy (which should be viewed with extreme caution as a good classifier can reproduce the training set exactly), and test accuracy (the instances of which should be independent of the instances in the training set) which is more likely to reflect the external validity of the classifier. Commented Jul 27, 2017 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.