Springe direkt zu Inhalt

Self Assessment

Here, you can check the knowledge you gained during the third chapter.

Please, work through the following exercises.

You can verify your results by expanding the corresponding 'Spoiler'-boxes at the bottom of this page which will contain a correct solution.


3.1: Training and Validation data

In the context of LULC-Classifications, what is the difference between training and validation data?


3.2: Classes

Will a higher number of classification classes always lead to a better classification result?


3.3: Find the Mistakes

Find the mistakes in the following piece of code and correct them.

//Example RandomForest Classifier:
var rfclassifier = ee.classifier.smilerandomforest(50).train({
  Features: training,
  ClassProperty: 'landcover'
//Run the classification
rfclassified = s2a_median.classify(rfclassifier);
//Display classification
{min: 0, max: 3, palette: ['blue', 'green', 'orange','yellow']},
'RF classification');


3.4: Code Analysis

Comment every line of the following piece of code! What does it do?


var rfvalidation = rfclassified.sampleRegions({ 
collection: valMerge,
properties: ['landcover'],
scale: 30,
print(rfvalidation, 'Random Forest Validation');

var rfTestAccuracy = rfvalidation.errorMatrix('landcover', 'classification');
print(rfTestAccuracy, 'Validation of the Random Forest Error Matrix');
print(rfTestAccuracy.accuracy(), 'Random Forest Overall Accuracy');

Now it is your turn!

Create a Land Use / Land Cover Classification using a Random Forest Classifier for a research area and time period of your choice.

This includes:

- Preparing the data

- Creating Training Samples

- Classification and Validation

- Interpretation of the results


Be sure to set your framework conditions before you start coding, as a nice and precise LULC-Classification needs a bit of planning ahead. This includes for example the kind and amount of classes you want to assess, the number of training samples per class and the sampling strategy. Further information on this topic can be found in Chapter 3.2 'Interpretation and Thoughts of Improvement'.


Print the relevant results to the Console Panel and display meaningful maps in the Map Panel.

In case you get stuck, you can always use the code of Chapter 3.2 'Improved Classification' as reference.

Training data: This data set 'teaches' the algorithm which combinations of pixel values will produce a good predictive model for our distinct classes.
Validation data: This data set, on the other hand, is used to validate the outcome of the classified product by offering an unbiased evaluation of the fitted model.

No! The number of classes should always be adapted to the research question. In general, it is better to stick to a relatively small number of classes that can still adequately portray the research question. Instead, focus on a high quality of training samples per class. This way, the finished product will not be chaotic or confusing at first sight and probably more accurate as well.

The corrected mistakes are marked in bold.


//Example RandomForest Classifier:
var rfclassifier = ee.Classifier.smileRandomForest(50).train({
  features: training,
  classProperty: 'landcover'

//Run the classification
var rfclassified = s2a_median.classify(rfclassifier);

//Display classification
{min: 0, max: 3, palette: ['blue', 'green', 'orange','yellow']},
'RF classification');

Comment every line of the following piece of code! What does it do?


This code is used to validate an already processed classification called 'rfclassified' using a validation sample set called 'valMerge'.

Then, an Error Matrix is calculated to evaluate the classifications accuracy.


var rfvalidation = rfclassified.sampleRegions({ //Initiates the validation
collection: valMerge, //Choose the merged validation samples
properties: ['landcover'], //Choose geometry field 'landcover' as property
scale: 30, //Set spatial resolution
print(rfvalidation, 'Random Forest Validation');//Print the results to the console

var rfTestAccuracy = rfvalidation.errorMatrix('landcover', 'classification'); //Create an Error Matrix for evaluation purposes
print(rfTestAccuracy, 'Validation of the Random Forest Error Matrix'); //Print Error Matrix to the Console
print(rfTestAccuracy.accuracy(), 'Random Forest Overall Accuracy'); //Print Overall Accuracy to the Console