Session 21 · Wed Nov 18 · Book sections 4.1–4.2
🎯
A table of features has no order between its columns.
What does a fully connected network add to logistic regression and a forest, for a class and for a number?
Reading: 4.1 Neural networks (classification) · 4.2 Regression with a neural network · training and evaluating any network: lecture 24a
The structure of the data chooses the network. A table of features has no order: every input connects to every neuron, and the network assumes nothing.
From one neuron to deep networks, then back to one neuron, and to trees.
Rosenblatt (1958) Psychol. Rev. 65, 386–408 · Rumelhart, Hinton & Williams (1986) Nature 323, 533–536 · Cybenko (1989) Math. Control Signals Syst. 2, 303–314; Hornik, Stinchcombe & White (1989) Neural Netw. 2, 359–366 · DeVries et al. (2018) Nature 560, 632–634 · Mignan & Broccardo (2019) Nature 574, E1–E3 · Grinsztajn, Oyallon & Varoquaux (2022) NeurIPS 35. AUC values: our rerun of the open release (figs/lit_aftershock_2018/numbers.json).
61 features in, 32 hidden neurons with ReLU, 4 scores out: 2,116 weights (notebook 4.1). The softmax turns the scores into probabilities.
Each neuron: a weighted sum of all inputs plus its bias, then ReLU. Here z1 = 1.60 passes; z2 = −1.55 becomes 0. In matrix form, z = W x + b.
One ReLU neuron draws one straight line: 66% of the training samples right on a ring. Three lines enclose the core: 98%. Sixteen smooth the edge: 98%.
weights = outputs × (inputs + 1): 2,116 in 4.1, 1,313 in 4.2. Start small, one hidden layer of 16 to 64 neurons, and grow only if the training loss stays high.
At about 17,000 weights each: 256 neurons in one layer, or 64 in each of four. Depth composes cuts of cuts; for a table of features, one or two hidden layers are usually enough.
Shuffle the samples of every window in the same way and the MLP scores the same, 57.6% and 57.8%: it never used the shape of the waveform. Right for a table, wasteful for a waveform.
In km and magnitude units the loss is a narrow valley: after 60 steps the magnitude weight is −0.03 of −0.76. Scaled to unit variance, the same 60 steps reach the lowest loss.
In each training batch, each hidden neuron is off with probability 0.3, so no neuron can rely on one particular other; at evaluation every neuron works.
Classification: one score per class, softmax, cross-entropy (4.1). Regression: one number, no activation, squared, absolute or Huber error (4.2). The hidden layers can be identical.
| Classification (4.1) | Regression (4.2) | |
|---|---|---|
| Sample, input X | seismic event: 61 features | GNSS window: 6 numbers |
| Y, to predict | source type, 4 classes | position in 30 days (mm) |
| Last layer, loss | 4 scores; cross-entropy | 1 number; MSE, MAE, Huber |
| Score, baseline | accuracy; logistic | error in mm; linear |
📍 In-situ sensor 🪨 Solid Earth 📐 Geodesy
1,482 samples, one every 5 days, 2006–2026. Train on the first 70%, validate on the next 15%, test on the last 15%, in time order, with a gap so that no 30-day window overlaps.
Squared error makes large errors dominate the mean; absolute error weights every millimeter the same; Huber is squared near zero and absolute beyond.
Cross-entropy only looks at the probability the network gives to the observed class: 0.9 costs 0.11, a uniform guess over 4 classes costs 1.39, confident and wrong costs without bound.
📍 In-situ sensor 🪨 Solid Earth 📈 Seismology
One hidden layer: 87.1%. Three hidden layers with dropout: 89.2%. Without dropout the validation loss climbs after epoch 11. Earthquakes and explosions are confused most.
| Model | Weights | Test accuracy, 800 events |
|---|---|---|
| three hidden layers, dropout | 18,852 | 89.2% |
| random forest, 300 trees | — | 88.5% |
| three hidden layers, no dropout | 18,852 | 87.6% |
| one hidden layer of 32 | 2,116 | 87.1% |
| logistic regression | 248 | 86.8% |
| majority class | 0 | 25% |
One split, one seed; one standard error is 1.2 points. The best network ties the forest, and the one-layer network ties logistic regression.
Every test observation, −132 to −111 mm, is below the training range, −94 to 0 mm. A network that predicts the position itself must extrapolate.
| Model | Weights | Test error (mm), 3 seeds |
|---|---|---|
| linear regression | 7 | 0.63 |
| network on the change, absolute error | 1,313 | 0.70 ± 0.01 |
| network on the change, Huber | 1,313 | 0.72 ± 0.01 |
| network on the change, squared error | 1,313 | 0.73 ± 0.02 |
| persistence | 0 | 1.02 |
| network on the position | 1,313 | 2.45 ± 1.88 |
The linear model wins; the three losses tie; predicting the position loses to persistence. On six hand-built numbers the network adds weights and no skill.
| Step | Practice | Rubric |
|---|---|---|
| Frame | split along the deployment axis | A1–A4 |
| Check | inside the training range? | A7 |
| Baseline | no learning; linear or logistic | A6 |
| Design | small; last layer fits Y | C1 |
| Train | seed; loss; curves; checkpoint | D1–D6 |
| Evaluate | test once; units; three seeds | D7–E3 |
pixi run jupyter lab · PyTorch names: nn.MSELoss, nn.L1Loss, nn.HuberLoss, nn.CrossEntropyLoss, optim.Adam, state_dict
Fully connected: for features already computed. It tied a forest on 61 features (4.1) and lost to a linear model on 6 numbers (4.2).
ESS 469/569 · Machine Learning in the Geosciences · Autumn 2026