Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Demo 2: Land Cover Classification

This demonstration utilizes scripts originally developed for the 4-Day Advanced Online Training on AI/ML for Earth Observation for Philippine EO Professionals, part of the CoPhil Programme (EU-Philippines Copernicus Capacity Support Programme), a flagship initiative under the European Union’s Global Gateway strategy (2025).

Learning Objectives

  1. Set up and authenticate Google Earth Engine in Google Colab

  2. Acquire and preprocess Sentinel-2 satellite imagery

  3. Calculate spectral indices (NDVI, NDWI, NDBI, EVI)

  4. Create training datasets using verified open data sources

  5. Train a Random Forest classifier

  6. Perform land cover classification

  7. Assess accuracy and generate statistics

Supervised Classification Workflow

Key Steps

  1. Preprocessing: Cloud masking, atmospheric correction

  2. Feature Extraction: Spectral bands, indices (NDVI, NDWI)

  3. Training Data: Collect representative samples for each class

  4. Model Training: Train classifier on training data

  5. Classification: Apply model to entire scene

  6. Validation: Assess accuracy with independent test data

Why Random Forest for Earth Observation?

Random Forest is one of the most popular algorithms for land cover classification because:

  • Handles high-dimensional data: Works well with many spectral bands (Sentinel-2 has 13 bands)

  • Robust to overfitting: Ensemble approach reduces variance

  • Feature importance: Reveals which bands are most informative

  • No feature scaling required: Unlike neural networks

  • Fast training: Efficient even with large datasets

  • Interpretable: Can visualize decision rules\

Random Forest: The “Forest” Analogy

One tree (Decision Tree): One expert’s opinion

  • Can be very confident but sometimes wrong

  • Might overfit to specific training examples

Forest (Random Forest): Committee of experts

  • Each expert sees slightly different data

  • Each expert considers different features

  • Final decision: Majority vote

  • Wisdom of crowds: Group decision more reliable than individual

💡 If you ask 100 independent experts and 75 say “Forest”, you can be more confident than if only 1 expert says “Forest”.

A. Setup and Authentication

This code block initializes the environment by linking Google Earth Engine for processing and visualizing satellite imagery.

This code prompt you through an authentication process and will open a browser window for account selection and authorization. Make sure that you select the email you provided when you registered to this training. If not, inform your instructor/s if you use another e-mail account.

You may encounter an error: <EEException: ee.Initialize: no project found>, in case you cannot authenticate and initialize Earth Engine.

In this case, you may need to provide a project that you own or have permissions to use. Go to your GEE account (you may also check in your Google Cloud) and choose any of the projects that you have and then copy the selected Project ID.

B. Define Study Area

This code block defines the geographic bounding box for Palawan, Philippines and initializes an interactive map centered on its coordinates, displaying the defined boundary as a red polygon layer for visual verification.

C. Sentinel-2 Data Acquisition

This code block filters the Sentinel-2 Harmonized collection for low-cloud imagery within the 2024 date range, applies cloud masking, and generates a median composite clipped to Palawan for a clear, seamless RGB visualization.

D. Calculate Spectral Indices

This code block calculates four key spectral indices—

  1. NDVI (vegetation),

  2. NDWI (water),

  3. NDBI (built-up areas), and

  4. EVI (enhanced vegetation)—

by performing mathematical transformations on specific Sentinel-2 bands to highlight different environmental features.

E. Feature Stack Preparation

This code block combines the original Sentinel-2 spectral bands with the four (4) newly calculated indices into a single multi-band image stack, creating a comprehensive feature set for spatial analysis and machine learning classification.

F. Training Data from Verified Open Sources

Using verified datasets:

  • ESA WorldCover 2021: 10m resolution, 76.7% accuracy

  • Global Mangrove Watch: 25m resolution, 87.4% accuracy for mangroves

  • OpenStreetMap: Urban features

G. Random Forest Training

This code block configures and trains a Random Forest classifier using 100 decision trees to learn the relationship between the input spectral features and the corresponding land cover training labels.

Parameters

  1. n_trees

  • Description: Number of trees in forest

  • Typical values: 50-500

  • Impact: More trees → better performance (diminishing returns)

  1. max_depth

  • Description: Maximum depth of each tree

  • Typical values: 10-50 or None

  • Impact: Deeper → more complex, risk overfitting

  1. min_samples_split

  • Description: Min samples to split node

  • Typical values: 2-10

  • Impact: Higher → simpler trees, less overfitting

  1. max_features

  • Description: Features per split

  • Typical values: 𝑛√ or log2(𝑛)

  • Impact: Balance between accuracy and diversity

  1. bootstrap

  • Description: Use bootstrap sampling

  • Typical values: True

  • Impact: Almost always True for RF

💡 GEE’s ee.Classifier.smileRandomForest() defaults:

  • numberOfTrees: 100

  • variablesPerSplit: 𝑛√ (automatic)

  • minLeafPopulation: 1

H. Image Classification

This code block applies the trained Random Forest model to the entire multi-band feature stack to generate a discrete land cover map, which is then displayed using a custom color palette for visual analysis.

I. Accuracy Assessment

This code block evaluates the model’s performance by generating an independent validation dataset and comparing the predicted land cover classes against known reference values. It calculates a confusion matrix to derive the Overall Accuracy and Kappa Coefficient, providing a statistical measure of how reliably the classifier identifies different land cover types.

Overall Accuracy

  • Definition: Percentage of correctly classified samples

  • Formula: Overall Accuracy = Correct Predictions / Total Samples

  • Interpretation: Simple, intuitive metric

  • Limitation: Can be misleading with imbalanced classes

  • Example: 95% accuracy sounds great, but if 95% of pixels are forest, a “classify everything as forest” model achieves 95%!

Kappa Coefficient

  • Definition: Measure of agreement beyond chance

  • Interpretation: κ < 0.4: Poor agreement κ = 0.4-0.6: Moderate agreement κ = 0.6-0.8: Good agreement κ > 0.8: Excellent agreement

  • Why use Kappa? Accounts for agreement by random chance, especially important for imbalanced datasets.


Summary and Key Takeaways

Random Forest Ensemble

  • Combines many trees to reduce variance and improve stability

  • Uses bootstrap sampling (bagging) for training diversity

  • Uses random feature selection to decorrelate trees

  • Final prediction by majority voting (classification) or averaging (regression)

  • More robust than single trees, less prone to overfitting

Accuracy Metrics

  • Overall accuracy can hide class-specific problems

  • Other accuracy metrics includes: (1) Precision (user’s accuracy): Reliability of positive predictions, (2) Recall (producer’s accuracy): Completeness of detection, and (3) F1-score: Harmonic mean balancing precision and recall

  • Choice of metric depends on application cost (false positives vs. false negatives)

For Earth Observation

  • Random Forest works well with multi-spectral data

  • Feature importance reveals spectral signature insights

  • Confusion patterns often reflect spectral similarity

  • Fast training enables rapid iteration


References

  1. CoPhil EO AI/ML Training Programme. (2025). CoPhil EO AI/ML Training: 4-Day Advanced Training on AI/ML for Earth Observation. https://skotsopoulos-del.github.io/cophil-training-v1.0/


End of Demo 2 Notebook