Workshop: A Small Network for Pay on the Nine Wells
Learning objectives
- Train a small network on eight of the nine wells at a time and score it on the ninth, in Python and on the book's table
- Compare the network with logistic regression, kNN and the random forest on wells they have not seen, and say plainly which wins
- Read a network's training and held-out scores against its size and its epochs, and say what a growing gap means
- Explain why a bigger network fails on Ogbon-8, the well in the water leg, from the rocks the training wells hold
A Network on Wells It Has Not Seen
Grown on eight of the Ogbon field's nine wells and called on the ninth, nine times over, a network with two tanh hidden units on the porosity logs and log10 RT calls 0.989 of the held-out samples right; logistic regression calls 0.986, kNN (k = 15) 0.976 and the random forest 0.976. The small network leads logistic regression by 33 samples of 10809, 16.5 ft. With four or eight hidden units it fits the training wells better, 0.990, and calls a new well worse, 0.975 and 0.976: Ogbon-8, the well in the water leg, falls from 1.000 to 0.873. The bigger networks learn a pattern the eight training wells hold and Ogbon-8 does not share, and only holding wells out shows it. This workshop trains the networks in Python; the figure reads them from the book's precomputed network table.
The Nine Wells
The data are the book's own learning set: Ogbon-1, the Petrophysics book's well, and eight hypothetical appraisal wells of the book's field, each 1201 samples every 0.5 ft, logged by Ogbon-1's own build and the book's own tool model, all synthetic. The class is pay, the Petrophysics book's net-pay rule on the generator's truth. The networks are Section 13.1's kind, tanh hidden units and a softmax over not pay and pay, with every log scaled on the training wells of each fold only. Each is trained by Adam, a learning rate of 0.01, in mini-batches of 128 samples, for 40 epochs, on eight wells, 9608 samples, and called on the ninth, 1201, nine times.
Step 1: Load the Learning Set
The set is one CSV, the book's own, with a comment header naming every column's unit. Add log10 RT.
import numpy as np
import pandas as pd
URL = "https://ogbonlab.com/mlgeo-core/data/ogbon-learning-set.csv"
df = pd.read_csv(URL, comment="#")
df["LRT"] = np.log10(df["RT_ohmm"])
A = ["GR_API", "RHOB_gcc", "NPHI_vv", "DT_usft"]
B = A + ["LRT"]
y = df["pay"].to_numpy()
wells = df["well"].to_numpy()
lith = df["lith"].to_numpy()
Step 2: A Small Network
scikit-learn's network with one hidden layer of tanh units, behind a scaler, so the scaler is fitted on the rows the network is trained on and no others.
from sklearn.neural_network import MLPClassifier
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
def network(h):
return make_pipeline(
StandardScaler(),
MLPClassifier(hidden_layer_sizes=(h,), activation="tanh",
solver="adam", learning_rate_init=0.01,
batch_size=128, max_iter=40, random_state=0))
Step 3: Leave One Well Out
def held_out(cols, h):
X = df[cols].to_numpy()
calls = np.zeros(len(y), dtype=int)
train_ok, train_n = 0, 0
for w in np.unique(wells):
te = wells == w
net = network(h).fit(X[~te], y[~te])
calls[te] = net.predict(X[te])
train_ok += (net.predict(X[~te]) == y[~te]).sum()
train_n += (~te).sum()
return (calls == y).mean(), train_ok / train_n, calls
acc_B2, train_B2, calls_B2 = held_out(B, 2)
The book's kernel gives 0.989 held out with two hidden units, against 0.989 on the training wells. scikit-learn draws its own first weights and its own batches and may stop early by its own rule, so its third decimal may differ from the kernel's. On the same wells the book's tables give logistic regression 0.986, kNN with k = 15 0.976 and the random forest of Chapter 8 0.976 (Chapters 4, 5 and 8). Pooled over the nine held-out wells the small network misses 11.0 ft of pay and calls 47.5 ft of false pay.
Step 4: The Network's Size
sizes = [1, 2, 4, 8]
run = {h: held_out(B, h) for h in sizes}
The book's kernel gives, held out, 0.989 with one hidden unit, 0.989 with two, 0.975 with four and 0.976 with eight; on the training wells 0.989, 0.989, 0.990 and 0.990. More units fit the wells the network learned from a little better and a new well worse. With four the false pay grows to 123.5 ft.
Step 5: Ogbon-8 and Its Limestone
dry = wells == "Ogbon-8"
dry_acc = {h: (run[h][2][dry] == y[dry]).mean() for h in sizes}
dry_wrong = {h: pd.Series(lith[dry & (run[h][2] != y)]).value_counts()
for h in sizes}
Ogbon-8 lies wholly in the water leg, and its tight limestone is the only wet limestone in the field: in every other well the limestone holds oil. When Ogbon-8 is the well held out, no training well shows the network what wet limestone reads. The book's kernel gives Ogbon-8 called right at 1.000 by the networks with one and two hidden units and at 0.873 and 0.872 by those with four and eight, whose mistakes there are all limestone: 153 and 154 samples called pay. A small network is close to a straight boundary in the five logs and carries the trend of the other rocks into the wet limestone, which is right here; a bigger one bends its boundary to fit the eight wells' limestone, all of it oil-bearing, and the bend is wrong where the training wells never went. A flexible model is only as good as the rocks its training wells hold.
Step 6: When to Stop
With four hidden units the held-out share peaks at 0.986 after epoch 6 and ends at 0.975 after epoch 40, while the training share keeps climbing. It is tempting to stop at the peak. But that peak was found on the held-out wells: choosing the epoch by them scores the network on wells it was tuned on, the leak Chapter 10 warns of. An early stop needs a validation well of its own, inside the eight training wells of each fold.
Without Resistivity
acc_A2, train_A2, calls_A2 = held_out(A, 2)
On the porosity logs alone the book's kernel gives the network with two hidden units 0.878 held out, logistic regression 0.874, kNN 0.873 and the forest 0.864, and Ogbon-8 0.357: the porosity logs see clean rock, not the oil in it, and no hidden unit can find what its inputs do not carry.
What a Network Buys
On these wells a small network matches logistic regression and passes it by 0.003, and a bigger one does worse on a new well than either: the call of pay from these logs is close to a straight boundary in five dimensions, and the extra bend a network can draw is as likely to fit the training wells' accidents as the rock. Networks earn their weights where the pattern is in the shape of the data, along depth or across a section, which is what the next chapters build: convolution across depth, and memory down the well.