Session 17 · Fri Nov 6 · Book sections 3.7, 3.11
🌲
What does a forest add to Wednesday’s logistic regression, for classes and for numbers?
| Part | What we do | Data |
|---|---|---|
| Start | draw a ROC curve by hand, then read it for two models | ten real seismic events |
| 1. Classes | one tree, many trees, thresholds, tree agreement | four Pacific Northwest source types; snow layers in the Swiss Alps |
| 2. Numbers | the same tree for a number, baselines, importance, range limits | soil moisture at Turnbull, WA; SoilGrids |
| 3. Maps | how much spatial correlation is a problem | soil moisture, western US; biomass, central Africa |
| 4. Practice | best practices for classifiers and regressors | everything above |
| Rank | Probability of explosion | Analyst label |
|---|---|---|
| 1 | 0.97 | explosion |
| 2 | 0.90 | explosion |
| 3 | 0.72 | earthquake |
| 4 | 0.62 | explosion |
| 5 | 0.40 | earthquake |
| 6 | 0.37 | explosion |
| 7 | 0.15 | earthquake |
| 8 | 0.12 | explosion |
| 9 | 0.06 | earthquake |
| 10 | 0.02 | earthquake |

Start at (0, 0) and go down the list. Explosion: move up 0.2. Earthquake: move right 0.2. Circle where you stand at thresholds 0.8, 0.5 and 0.2.
| Threshold | Caught, of 5 | False alarms, of 5 | Recall | False-positive rate |
|---|---|---|---|---|
| 0.8 | 2 | 0 | 0.4 | 0.0 |
| 0.5 | 3 | 1 | 0.6 | 0.2 |
| 0.2 | 4 | 2 | 0.8 | 0.4 |
AUC is also a count. Of the 25 explosion and earthquake pairs, the explosion has the higher probability in 19: 19 / 25 = .76.
Ten events chosen to include every kind of error. Logistic regression, 61 waveform features, Zenodo record 14025693.

A threshold gives one confusion matrix, which gives one point. The curve collects all of them, and its area is .96 on all 500 test events.

🖥️ Model & simulation 🧊 Cryosphere 🧊 Glaciology
Is this simulated snow layer unstable? 742 observed snow profiles were compared by hand with simulated ones.
| Threshold | Missed | False alarms | Accuracy | Recall | Precision |
|---|---|---|---|---|---|
| 0.50 | 7 | 7 | 88% | 91% | 91% |
| 0.71 | 11 | 3 | 88% | 85% | 96% |
The authors question whether 0.71 is an improvement for operations, because it misses more unstable layers.
Mayer, van Herwijnen, Techel and Schweizer (2022), The Cryosphere 16, 4593–4615, Fig. 7. doi:10.5194/tc-16-4593-2022. CC BY 4.0.


Each question draws one straight line, so the tree cuts the events into boxes. A new event lands in one box and takes its most common label; to predict a number, its mean.
The tree tests every feature and every cut, and keeps the question that leaves each side purest. Then it repeats inside each box, never looking back.


Curve: all 61 features.
Left to itself, a tree draws a box around almost every training event, outliers included. It becomes perfect on those events and worse on new ones, and a small change in the data can change the whole tree.

Each tree differs from the others in two ways:
The forest takes a majority vote, or the mean for numbers.
Out-of-bag score: each event is predicted only by trees that never saw it, so no test set is spent.
One tree scores .774 and 300 trees score .884; the out-of-bag estimate is .882. Beyond about 50 trees the score only wobbles by ±.003.
| Model | Macro-F1 | Recall: explosion |
|---|---|---|
| One full tree | .800 | .720 |
| Forest, 300 trees | .884 | .796 |
| Logistic regression, standardized | .884 | .804 |
| Logistic regression, raw features | .783 | |
| Boosted trees | .898 | .836 |
Boosting: trees grown in sequence, each one fit to the errors left by the trees before it.
Forests need no standardizing. Logistic regression does: on raw features it stopped before converging.

Explosion against earthquake, mean of 10 random subsets, bars 1 standard deviation.
With all training events the forest ties logistic regression. With 40 events it leads, AUC .908 against .875, which fits a study that trained on 146 layers.

A forest also outputs a probability: the mean over its trees.
| Threshold | Logistic: missed / false alarms | Forest: missed / false alarms |
|---|---|---|
| 0.2 | 15 / 53 | 6 / 82 |
| 0.5 | 33 / 16 | 32 / 20 |
| 0.8 | 62 / 6 | 89 / 3 |
250 explosions, 250 earthquakes.
| ROC AUC | Average precision | Brier | |
|---|---|---|---|
| Logistic | .963 | .963 | .075 |
| Forest | .964 | .965 | .078 |
AUC .963 and .964, yet threshold 0.8 misses 62 or 89 explosions. A threshold does not transfer between models: choose it for each one on validation data.

For each of the 1,000 test events, count the trees voting for the winning class.
The labels are not needed to compute the agreement, so low-agreement events can go to an analyst first.
The 254 events with agreement below 70% are 1 in 4 test events and hold 85 of the 115 errors. Agreement ranks events; it is not yet a calibrated probability.


Same questions, same boxes. The target is the daily change in soil moisture at Turnbull, and each box predicts the mean change of its training days (m³/m³).
The tree keeps the question that most reduces the spread inside each group, the same idea as purity. More levels make more stairs; without a limit they follow single days; averaging many trees smooths them.

📍 In-situ sensor 💧 Land water 💧 Hydrology & land-surface modeling
Now today’s soil moisture at 5 cm, with six features including yesterday’s value.
| Soil moisture at 5 cm | Error (m³/m³) | R² | Error, rainy days |
|---|---|---|---|
| Climatology | .0284 | .848 | .0353 |
| Yesterday’s value | .0042 | .995 | .0138 |
| Linear regression | .0036 | .997 | .0103 |
| Forest, 300 trees | .0033 | .997 | .0109 |
USCRN station WA Spokane 17 SSW. Train 2015 to 2020 (1,630 days), test 2021 to 2024 (1,172 days, 78 with 5 mm of rain or more). Features: yesterday’s moisture at 5 and 10 cm, rain today and yesterday, air temperature, solar radiation. Error: mean absolute error. R²: share of variance explained.
Repeating yesterday already gives R² .995, so that is the baseline to beat. The forest lowers the error by .0009 m³/m³; on rainy days the linear model does slightly better.

📍 In-situ sensor 💧 Land water 💧 Hydrology & land-surface modeling
Soil properties for the globe, from about 240,000 profiles and more than 400 environmental layers. Top: predicted soil organic carbon, 5 to 15 cm (dg/kg). Bottom: range of the prediction, 5% to 95% quantile.
A quantile forest keeps the training values in each leaf, so each location gets a distribution, not a single number.
Cross-validation stratified in space: model efficiency from 0.31 (coarse fragments) to 0.74 (bulk density).
“The least sampled areas present the highest prediction uncertainties.”
Poggio et al. (2021), SOIL 7, 217–240, Fig. 7. doi:10.5194/soil-7-217-2021. CC BY 4.0.
🖥️ Model & simulation 💧 Land water 💧 Hydrology & land-surface modeling
Annual mean soil moisture, 992 land cells at 0.5°, 1991 to 2020.
The red box was held out of training.
Features: longitude and latitude, or precipitation and air temperature.
CPC leaky-bucket model: Fan and van den Dool (2004), J. Geophys. Res. 109, D10102.

Inside the box, the forest on longitude and latitude can only extend the boxes it drew around it (R² .18). The forest on precipitation and temperature recovers the pattern (R² .81).

Soil moisture, western US. Each cell is predicted from training cells beyond a distance.

Forest biomass, central Africa. XY: coordinates. RSE: satellite and environment. Shorter distance axis.
Ploton et al. (2020), Nat. Commun. 11, 4540, Fig. 5a. doi:10.1038/s41467-020-18321-y. CC BY 4.0.
There is no fixed limit: compare your prediction distance with the field’s correlation distance. A random split gives both soil moisture forests R² .91; at 500 km they reach .01 and .85. In central Africa both fall together, so nearness was doing the work.
| Situation | A problem? | What to do |
|---|---|---|
| Filling gaps: prediction sites as close to training as your test sites | Not for the score. A random split asks the right question if samples represent the map | Random folds (Wadoux et al., 2021) |
| Predicting a new region, beyond the correlation distance | Yes. Random folds report near-neighbor skill | Hold out blocks with a buffer as wide as your real distance (Roberts et al., 2017) |
| Longitude and latitude as features | Depends on the task. They score .91 in gaps, .01 at 500 km | Prefer features with a mechanism; test with a buffer |
| Out-of-bag score | Yes on maps. It leaves neighbors in: .91 for coordinates alone | Do not use it as a spatial test |
| Correlated features, not samples | Not for predictions. Importance splits among them | Read correlated features as a group |
| New conditions in feature space | Yes, at any distance. A forest cannot leave its training range | Report where the map applies (Meyer and Pebesma, 2022) |
Wadoux, Heuvelink and de Bruin (2021), Ecol. Model. 457, 109692. Roberts et al. (2017), Ecography 40, 913–929. Meyer and Pebesma (2022), Nat. Commun. 13, 2208.

Ground surface temperature from air temperature, trained only on days below 28 °C.
| Mean absolute error (°C) | Cool days, held out | Hot days |
|---|---|---|
| Forest | 4.1 | 7.9 |
| Linear | 4.0 | 4.0 |
| On hot days (°C) | Largest value |
|---|---|
| Observed | 67.6 |
| Forest | 45.5 |
| Linear | 70.8 |
USCRN WA Spokane 17 SSW, 2015 to 2024. Infrared ground sensor, daily maximum. 2,301 training days, 570 hot days.
On cool days the two tie. On hot days the forest’s error doubles because every prediction is an average of training values, so its curve goes flat above 28 °C.

Snow instability. Impurity importance of the final six features. Features correlated above r = 0.8 were removed first.
Mayer et al. (2022), Fig. 6. CC BY 4.0. ε̇ᵥ: viscous deformation rate; r_c: critical cut length; P_k: skier penetration depth.

Soil moisture. Add yesterday’s moisture again, in percent. Its credit splits .99 into .53 and .46, while the error stays at .0033 to .0034 m³/m³.
Impurity importance divides credit among correlated features. Removing correlated features first, as Mayer et al. did, or shuffling groups of features on held-out data gives a fairer reading; neither shows cause.
| Practice | Seen in this course |
|---|---|
| 1. Choose the decision and the metric before fitting | Always answering “earthquake” at 5% explosions: accuracy .949, no use |
| 2. Split first, by what samples share: event, station, time, region | Oversampling before the split: F1 .995. After: .590 |
| 3. Fit a baseline and a simple model first | Logistic regression ties the forest at .884 |
| 4. Keep preprocessing in a pipeline fit on training folds | Logistic regression on raw features: .783 |
| 5. Start from defaults; tune by cross-validation on training data | Forest defaults .881 ± .015; no setting tested beat them by more than .001 |
| 6. Treat rare classes and choose the threshold on validation data | Same AUC, yet 62 or 89 explosions missed at 0.8 |
| 7. Report per-class errors and spread; open the test set once | Explosions are the weakest class in every model |
| Practice | Seen in this course |
|---|---|
| 1. Beat the physical baselines: climatology and persistence | Error .0284 and .0042; forest .0033 m³/m³ |
| 2. Split by time or place, matching how you will predict | At 500 km, R² .85 with climate and .01 with coordinates |
| 3. Report error in units and by regime, not only R² | R² .997, yet rainy-day error is 3 times the mean error |
| 4. Noisy target: grow larger leaves | Daily moisture change, R²: leaf size 1 .09; leaf size 20 .28 |
| 5. Check how many features each split sees | One third instead of all (scikit-learn’s default): error .0060 against .0047 |
| 6. Test beyond the training range | Hot days: error 4.1 to 7.9 °C |
| 7. Give a range with each prediction | Quantile forests, as in SoilGrids |
| Question | Tool | Geoscience example | Number |
|---|---|---|---|
| Where is the ROC curve from? | one point per threshold | ten seismic events | AUC .76 by hand; .963 on 500 |
| Why not one tree? | train against test score | four source types | 1.000 against .800 |
| What do many trees add? | bootstrap, random features | four source types | .774 to .884; out-of-bag .882 |
| Do thresholds transfer? | same threshold, two models | explosion or earthquake | 62 or 89 missed at 0.8 |
| Which predictions need a person? | tree agreement | seismic catalog | 47% against 2% wrong |
| Did it learn anything? | climatology, persistence | Turnbull soil moisture | .0284, .0042, forest .0033 m³/m³ |
| What happens outside training? | test beyond the range | ground surface temperature | error 4.1 to 7.9 °C |
| Which features matter? | importance, with copies removed | Swiss snow; soil moisture | .99 splits into .53 and .46 |
| How far can a map model go? | training cells beyond a distance | western US soil moisture | .91 in gaps; at 500 km, .85 or .01 |
git pull, then pixi run jupyter lab → 3.11_forests_practice.ipynbrates and check your drawing. Part 2: tree depth against test scoreoob_score=True, compare with logistic regression at .884Reference: 3.7. Monday: robust training, ensembles and AutoML (3.8, 3.9, 3.10). Ch 3 quiz Tue to Thu. Due Mon Nov 9: homework on scoring clusters. HW-CML due Fri Nov 20.
ESS 469/569 · Machine Learning in the Geosciences · Autumn 2026