This document describes a supervised classification of tree species of forestry interest using Random Forest in Aberfoyle Forest with multi-station PlanetScope surface reflectance imagery. It details the generation of spectral and vegetation index predictors, the selection of training samples, and the use of spatial cross-validation to ensure robust model evaluation. The results show strong classification performance at the species level.
Generate predictor variables from the PlanetScope imagery
The PlanetScope imagery
Planet surface reflectance (SR) imagery was used to create predictor variables. SR data is important because it shows how much light the Earth’s surface reflects and corrects for atmospheric effects. This allows for accurate comparisons between different dates. Including changes over time helps the model generalise by capturing seasonal differences in vegetation.
The Planet sensor captures images in eight spectral bands: Red, Near-Infrared (NIR), Blue, Green, Green I, Coastal Blue, Yellow, and Red Edge. The Red, NIR, and Blue bands were combined to make RGB composites. This approach allows for a detailed visual assessment of Aberfoyle Forest and makes it easier to see different vegetation patterns.
“Seasonal false-colour RGB composites of the study area (Winter, Spring, Summer, and Autumn 2025) are presented using a Red–NIR–Blue band combination. This configuration enhances the greenness of vegetation, which is displayed in vivid green shades, while bare soil is distinctly highlighted in purplish tones.”
Create vegetation indices (Summer)
Vegetation indices derived from the summer scene enhance the Random Forest model by providing features that represent the peak of vegetative growth, when foliage is densest and most uniform. This facilitates clearer differentiation between species or vegetation types. Additionally, vegetation indices reduce noise present in raw spectral data, resulting in more reliable and accurate predictions. These improvements can substantially increase the model’s performance.
Selection of Vegetation Indices
Because the assessment targets closed canopies, soil effects are minimal. Therefore, it is appropriate to use indices that emphasize subtle differences in plant health, chlorophyll content, and canopy structure. MCARI, GNDVI, NDVI, and MSAVI2 each highlight these characteristics, and collectively they provide a more comprehensive perspective that improves species discrimination compared to indices designed solely to correct for soil or water.
MCARI is highly sensitive to variations in chlorophyll and canopy structure, making it particularly useful for distinguishing species with subtle differences in greenness.
GNDVI, which uses the green band, is more responsive to chlorophyll levels than NDVI and can better differentiate species with similar biomass but differing health.
NDVI remains a reliable general-purpose index and serves as a solid baseline. It complements MCARI and GNDVI effectively.
MSAVI2 can be valuable when species vary in crown density or have incomplete canopy cover, as it adds structural contrast.
“vegetation indices on the study area, including NDVI, GNDVI, MCARI, and MSAVI2.”
Combining Spectral Bands and Vegetation Indices into a Multi-Layered Image
The imagery dataset consists of multiple raster images, with each image representing a spectral band from the PlanetScope sensor or a vegetation index. As these images cover the same geographic area and possess identical spatial resolution, they can be stacked to form a single multi-layer image. This composite integrates a total of 36 predictor variables listed below.
| Covariates |
|---|
| coastal.blue_winter |
| blue_winter |
| green.I_winter |
| green_winter |
| yellow_winter |
| red_winter |
| rededge_winter |
| nir_winter |
| coastal.blue_spring |
| blue_spring |
| green.I_spring |
| green_spring |
| yellow_spring |
| red_spring |
| rededge_spring |
| nir_spring |
| coastal.blue_summer |
| blue_summer |
| green.I_summer |
| green_summer |
| yellow_summer |
| red_summer |
| rededge_summer |
| nir_summer |
| coastal.blue_autumn |
| blue_autumn |
| green.I_autumn |
| green_autumn |
| yellow_autumn |
| red_autumn |
| rededge_autumn |
| nir_autumn |
| NDVI |
| GNDVI |
| MCARI |
| MSAVI2 |
Field data (The response variable)
The response variable corresponds to forest species identified within the study area, based on data from the Forester Sub-compartment database. To maintain the integrity of spectral signatures, only pure forest stands were selected for training the Random Forest model.
Zoom in on the map below to view the model training areas.
Spectral signatures of tree species
The figures below show how tree species reflect light across four seasons. When looking at the average reflectance values in the PlanetScope spectral bands for nine tree species, each species has its own unique spectral signature These trees reflect the most light in the near-infrared band, especially during summer when the differences are most noticeable.
Random Forest Classification
Forward Feature Selection (FFS)
This model with 36 predictor variables is likely to have some variables autocorrelated, which can lead to overfitting. Removing some variables can help address this issue. The ffs (forward feature selection) function in CAST lets users select predictor variables using cross-validation that they define.
“Scatter plot showing Kappa statistics for multiple model runs with varying numbers of predictor variables. Colors represent the number of variables used, selected via forward feature selection (ffs) in CAST. While performance improves with more variables, Kappa stabilizes at 0.6 or higher from 12 variables onward, suggesting diminishing returns and potential overfitting risks with higher variable counts.”
“These are the selected variables that contributed most effectively to classification accuracy, supporting robust species discrimination in a multitemporal remote sensing framework.”
The selected predictors for the final model are shown in the figure below.
Tune Spatial cross-validation.
Addressing spatial autocorrelation
The classification will be evaluated using spatial cross-validation implemented with the blockCV R package. Spatial cross-validation with blockCV is particularly effective in mitigating spatial autocorrelation, which may cause traditional cross-validation methods to overestimate model performance. The blockCV package divides spatial data into blocks, thereby minimising spatial dependency between training and validation sets. This approach preserves spatial relationships and prevents autocorrelation in the validation data, resulting in a more accurate assessment of model performance.
“The plots display how much spatial autocorrelation each input raster covariate has and show the spatial block created using the median of these values. The study area is divided into blocks that are 1149 meters wide. For each round of x-fold cross-validation, all data from one spatial block are left out.”
Final model with selected predictors and Spatial Cross-Validation**
I split the data into a training set containing 80% of the samples and a validation set containing the remaining 20%. Additionally, I established the 19 predictors and 9 response variables. The R code configures a 10-fold spatial cross-validation using trainControl, with method = “cv” specifying cross-validation. The random forest model (method = “rf”) is trained using the train function with cross-validation (trControl = ctrl_sp_spatial), a specified tuning grid (tuneGrid), and 300 trees (ntree = 500), optimizing for the Kappa metric. We see that the classes could be distinguished with a high Kappa value (>0.67). The optimal mtry value for the model is 2.
The image below provides insight into how variables help distinguish between different species in the forest.
For instance, in the larch panel, the nir_summer show high importance for classifying this species. This suggests that reflectance in these bands during those seasons is especially useful for distinguishing larch individuals from other classes
Classification map
“Raster map made with predictions from a fitted model.”
Confusion Matrix and Accuracy Assessment
The confusion matrix shows that the model classifies most species accurately, with high User’s Accuracy (UA) and Producer’s Accuracy (PA) scores. Beech, Douglas fir, and Larch have UA values above 99%, which means their predictions are very reliable. Norway spruce and Other Conifers have lower UA scores (66.1% and 31.6%). The model performs well for broadleaf, but it may need improvement for species with similar spectral features. The average PA of 94.5% suggests the model is well-calibrated and generalises well.
| Birch | Larch | Lodgepole pine | Norway spruce | Oak | Open | Other broadleaves | Other conifers | Scots pine | Sitka spruce | Sum | UA | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Birch | 5114.0 | 0.0 | 0 | 0.0 | 0.0 | 0 | 1.0 | 0.0 | 59.0 | 142 | 5316 | 96.2 |
| Larch | 1.0 | 5128.0 | 0 | 0.0 | 19.0 | 0 | 0.0 | 0.0 | 5.0 | 6 | 5159 | 99.4 |
| Lodgepole pine | 0.0 | 3.0 | 856 | 14.0 | 0.0 | 0 | 0.0 | 0.0 | 19.0 | 26 | 918 | 93.2 |
| Norway spruce | 0.0 | 0.0 | 4 | 2390.0 | 0.0 | 0 | 0.0 | 0.0 | 134.0 | 1088 | 3616 | 66.1 |
| Oak | 18.0 | 4.0 | 0 | 0.0 | 4147.0 | 0 | 3.0 | 0.0 | 0.0 | 0 | 4172 | 99.4 |
| Open | 0.0 | 0.0 | 0 | 0.0 | 0.0 | 2000 | 0.0 | 0.0 | 0.0 | 0 | 2000 | 100.0 |
| Other broadleaves | 66.0 | 1.0 | 0 | 0.0 | 10.0 | 0 | 692.0 | 0.0 | 1.0 | 20 | 790 | 87.6 |
| Other conifers | 4.0 | 0.0 | 0 | 31.0 | 0.0 | 0 | 0.0 | 221.0 | 21.0 | 422 | 699 | 31.6 |
| Scots pine | 36.0 | 7.0 | 3 | 32.0 | 1.0 | 0 | 0.0 | 1.0 | 7095.0 | 529 | 7704 | 92.1 |
| Sitka spruce | 3.0 | 56.0 | 2 | 85.0 | 0.0 | 0 | 0.0 | 3.0 | 234.0 | 25514 | 25897 | 98.5 |
| Sum | 5242.0 | 5199.0 | 865 | 2552.0 | 4177.0 | 2000 | 696.0 | 225.0 | 7568.0 | 27747 | 56271 | NA |
| PA | 97.6 | 98.6 | 99 | 93.7 | 99.3 | 100 | 99.4 | 98.2 | 93.8 | 92 | NA | 94.5 |