Tree Species Classification – Aberfoyle Forest

Random Forest Modelling Report

Author

Forest Research

Published

8 July 2026

Forest Research


Generating Predictor Variables from PlanetScope Imagery

Understanding the PlanetScope imagery

To train our model, we used Planet surface reflectance (SR) imagery.

Surface reflectance data measures the proportion of sunlight reflected by the Earth’s surface, after correcting for atmospheric effects such as haze or moisture. This correction is essential: it ensures that images taken on different dates can be compared reliably.

Because we analysed imagery from four different seasons — winter, spring, summer, and autumn — the model can learn how vegetation changes throughout the year. These seasonal differences help improve its ability to correctly identify tree species under varying conditions.

The Planet sensor captures information in 1 spectral bands:

  • Coastal Blue
  • Blue
  • Green I
  • Green
  • Yellow
  • Red
  • Red Edge
  • Near-Infrared (NIR)

Each band captures a different portion of the light spectrum, revealing characteristics that are invisible to the human eye.

For visual interpretation, we created RGB composites combining the Red, Near-Infrared, and Blue bands. This combination enhances vegetation contrast and makes structural differences across the Aberfoyle easier to interpret.

RGB composites (Red, NIR, Blue) showing seasonal variation across Aberfoyle.

The seasonal composites reveal clear differences in vegetation appearance throughout the year.

In winter, deciduous trees appear darker due to leaf loss, while evergreen conifers maintain consistent reflectance. During spring and summer, increased chlorophyll activity enhances contrast between species. By autumn, colour changes associated with senescence introduce additional spectral variability.

These seasonal patterns provide valuable signals for machine learning models tasked with distinguishing tree species.


Creating Vegetation Indices (Summer)

Summer imagery plays a particularly important role in this analysis. During this season, vegetation is at its peak: tree canopies are fully developed, leaves are dense, and chlorophyll activity is high. These conditions provide the strongest and most stable signals for distinguishing between species.

To enhance the predictive power of the Random Forest model, we derived 4 vegetation indices from the summer scene. Vegetation indices combine different spectral bands to highlight specific plant characteristics, such as chlorophyll content, canopy density, and overall health.

Unlike raw spectral bands, vegetation indices reduce background noise and emphasise biologically meaningful differences. This leads to more robust and reliable predictions.

Because this assessment focuses on closed forest canopies, soil exposure is minimal. Therefore, we prioritised indices that capture subtle differences in plant physiology and canopy structure rather than those primarily designed to correct for soil effects.

The following indices were selected:

Index Full Name Key Use
MCARI Modified Chlorophyll Absorption Ratio Index Sensitive to chlorophyll concentration and canopy structure
GNDVI Green Normalised Difference Vegetation Index Responsive to chlorophyll variation; differentiates species with similar biomass
NDVI Normalised Difference Vegetation Index Widely used baseline vegetation indicator
MSAVI2 Modified Soil-Adjusted Vegetation Index Enhances structural contrast; highlights crown density differences

Together, these indices provide complementary ecological information, improving the model’s ability to discriminate between tree species.

Vegetation indices derived from the summer PlanetScope imagery.

A total of 4 vegetation indices were derived from the summer imagery.


Combining Spectral Bands and Vegetation Indices

At this stage, all spectral bands and vegetation indices were combined into a single multi-layer raster.

Each individual raster layer represents a specific environmental characteristic — either a spectral band captured by the PlanetScope sensor or a derived vegetation index. Because all layers share the same spatial extent and resolution, they can be stacked together into one coherent dataset.

This multi-layer image forms the foundation of the Random Forest model. Each pixel now contains a vector of predictor variables describing seasonal reflectance patterns and vegetation properties.

In total, the model uses 36 predictor variables.

Distribution of predictor variables by category
Category No. Variables
Winter bands 8
Spring bands 8
Summer bands 8
Autumn bands 8
Vegetation indices 4

Field Data: Defining the Response Variable

The response variable in this study corresponds to tree species recorded in the Forester Sub-Compartment database. These field-based records provide the ground truth needed to train and evaluate the Random Forest model.

To ensure clear and consistent spectral signatures, pure stands were selected. This avoids mixed pixels and reduces ambiguity in the training data.

Note

A total of 539 training polygons representing 9 species were used in this analysis. Each polygon serves as a reference area from which spectral information is extracted and linked to its corresponding species label.

Spectral Signatures by Season

The interactive plots below show the median spectral reflectance profile per species for each season. Use the legend to toggle species on and off.


Random Forest Classification

Forward Feature Selection (FFS)

When building machine learning models, including too many highly correlated variables can reduce model stability and increase the risk of overfitting. In other words, the model may start learning redundant information rather than meaningful ecological patterns.

To address this, a Forward Feature Selection (FFS) procedure was applied using the ffs() function from the CAST package.

This method iteratively adds predictor variables to the model, selecting those that improve performance under cross-validation. Instead of relying on intuition alone, FFS evaluates combinations of variables and retains only those that contribute meaningful predictive power.

In this analysis, model performance improved steadily as variables were added. The Cohen’s Kappa statistic — which measures classification agreement beyond chance — increased and eventually stabilised above 0.7, indicating substantial agreement.

Tip

The optimal subset consisted of 12 predictor variables.

The first plot shows how model performance changes as additional variables are included. The second plot highlights the subset of predictors retained in the final model.

Although performance continues to improve slightly with additional variables, gains become marginal after a certain point. Selecting a reduced set of predictors helps maintain interpretability while preserving strong classification accuracy.


Tuning Spatial Cross-Validation

To evaluate model performance realistically, spatial cross-validation was applied using the blockCV package in R.

Traditional cross-validation randomly splits the data into training and validation sets. However, when working with spatial data, nearby observations often share similar environmental characteristics. This spatial autocorrelation can artificially inflate model performance if neighbouring pixels appear in both training and validation datasets.

Spatial cross-validation addresses this issue by dividing the study area into spatial blocks. In each fold, all observations from one block are withheld for validation. This ensures that the model is tested on spatially independent data.

Before defining the block size, spatial autocorrelation was estimated for each predictor raster. The block size was then determined based on the median autocorrelation range across predictors.

The analysis indicated that spatial dependency extends up to approximately 1117 metres. Therefore, the study area was divided into blocks of roughly that size, ensuring spatial independence between folds.


Running the Random Forest Model

The Random Forest classifier was trained using spatial cross-validation to ensure robust performance assessment. A 10-fold spatial cross-validation strategy was implemented through trainControl(). In each fold, entire spatial blocks were withheld from training, preventing spatial leakage between training and validation data.

Parameter Value
Predictor variables 12
Response classes 9
Number of trees 400
Optimisation metric Cohen’s Kappa
Best mtry 2
Final Kappa 0.771
Random Forest 

52921 samples
   12 predictor
    9 classes: 'Birch', 'Larch', 'Lodgepole pine', 'Norway spruce', 'Oak', 'Other broadleaves', 'Other conifers', 'Scots pine', 'Sitka spruce' 

No pre-processing
Resampling: Cross-Validated (10 fold) 
Summary of sample sizes: 47543, 48019, 47301, 47281, 47962, 47573, ... 
Resampling results across tuning parameters:

  mtry  Accuracy   Kappa    
   2    0.8408560  0.7707962
   7    0.8337115  0.7621023
  12    0.8204186  0.7442976

Kappa was used to select the optimal model using the largest value.
The final value used for the model was mtry = 2.


Predicted Map

Supervised tree species classification map – Aberfoyle Forest.

The final classification map illustrates the spatial distribution of tree species across the Aberfoyle.


Accuracy Assessment

Confusion matrix with User’s Accuracy (UA) and Producer’s Accuracy (PA) (%)
Birch Larch Lodgepole pine Norway spruce Oak Other broadleaves Other conifers Scots pine Sitka spruce Sum UA
Birch 5064.0 0.0 0.0 3 4 2.0 0.0 51.0 131.0 5255 96.4
Larch 3.0 5021.0 0.0 0 27 0.0 0.0 8.0 8.0 5067 99.1
Lodgepole pine 0.0 2.0 857.0 10 0 0.0 0.0 19.0 28.0 916 93.6
Norway spruce 0.0 0.0 7.0 2187 0 0.0 0.0 43.0 1226.0 3463 63.2
Oak 13.0 2.0 0.0 0 4139 3.0 0.0 0.0 0.0 4157 99.6
Other broadleaves 78.0 2.0 1.0 0 11 705.0 0.0 11.0 52.0 860 82.0
Other conifers 3.0 2.0 1.0 44 0 0.0 222.0 24.0 403.0 699 31.8
Scots pine 37.0 7.0 5.0 34 1 0.0 1.0 7165.0 454.0 7704 93.0
Sitka spruce 0.0 61.0 5.0 100 0 0.0 1.0 197.0 24436.0 24800 98.5
Sum 5198.0 5097.0 876.0 2378 4182 710.0 224.0 7518.0 26738.0 52921 NA
PA 97.4 98.5 97.8 92 99 99.3 99.1 95.3 91.4 NA 94.1

The confusion matrix provides a detailed breakdown of classification performance for each species.

Tip

The overall accuracy reached 94.1%, indicating substantial agreement beyond chance.

Producer’s accuracy reflects how well reference species were correctly classified, while User’s accuracy indicates the reliability of each predicted class.

Some confusion remains between spectrally similar conifer species, which is expected given overlapping canopy characteristics.