Workshop: Feature Engineering for Well Logs

Chapter 9, Engineering Features from Geoscience Data

Learning objectives

  • Load the book's learning set in Python and fit a rule on Ogbon-1 alone
  • Show that a rule on depth calls the well it learned from perfectly and fails across the field, and say why
  • Engineer depth below each well's top and explain what it fixes and what it cannot
  • Show that the logs, which read the rock and its fluid, carry from Ogbon-1 to the other wells

A Feature That Leaks

A feature can carry the answer without carrying the rock. Within Ogbon-1, depth names the bed, so a decision tree on depth fitted on Ogbon-1 calls 1.000 of its samples right; across the field the beds dip, the same depth is another bed, and the same rule calls only 0.678 of the other eight wells right. Depth below each well's top moves the rule with the beds, 0.800, but not with the level oil-water contact; the five logs, which read the rock and its fluid in every well, call 0.971. This workshop builds each rule in Python and the figure shows where each one is wrong.

The Depth RuleInteractive figure, enable JavaScript to interact.

The Data

The workshop reads the book's own learning set as a CSV file, mlgeo-core/data/ogbon-learning-set.csv on this site: Ogbon-1, the Petrophysics book's well, and Ogbon-2 to Ogbon-9, the book's own hypothetical appraisal wells, 1201 samples each, every one logged over Ogbon-1's beds moved by the structure, by the book's own tool model. Pay is the Petrophysics book's net-pay rule on the generator's truth. The whole set is synthetic, and that is why every number below can be checked. Each rule here learns on Ogbon-1 alone and is scored on the eight wells it never saw.

Each step below gives its code and then what the book's kernel gives for the same computation on the same set.

Step 1: Load the Set

One Row per Half Foot

The file is the book's learning set, with its comment lines naming the source and each column's unit. The rule learns on Ogbon-1 alone and is asked about the other eight wells.

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"])
home = df["well"] == "Ogbon-1"
print(home.sum(), (~home).sum())

The book's kernel gives 1201 samples of Ogbon-1 and 9608 of the other eight wells.

Step 2: A Rule on Depth

Learned at Home

A decision tree on depth alone, fitted on Ogbon-1 with the settings of the book's cross-validation table (Gini, depth at most 12). A tree needs no scaling: it reads the order of a feature, not its unit (Section 9.1).

from sklearn.tree import DecisionTreeClassifier

def rule(cols):
    tree = DecisionTreeClassifier(max_depth=12,
                                  random_state=0)
    tree.fit(df.loc[home, cols], df.loc[home, "pay"])
    right = tree.predict(df[cols]) == df["pay"]
    return tree, right

tree, right = rule(["depth_ft"])
print(right[home].mean(), right[~home].mean())

The book's kernel gives 1.000 on Ogbon-1 and 0.678 on the other eight wells.

Step 3: What the Rule Learned

Four Intervals

A tree on one feature calls pay inside intervals bounded by its thresholds, each midway between two neighbouring depths.

t = tree.tree_
print(np.sort(t.threshold[t.feature >= 0]))

The book's kernel gives four intervals of pay, 5855.75 ft to 5927.75 ft, 5945.75 ft to 6017.75 ft, 6039.75 ft to 6117.75 ft and 6135.75 ft to 6190.75 ft: Ogbon-1's four runs of pay, each widened by half a sample. The rule is a map of one well.

Step 4: Each Well

Where the Map Is Wrong

Score each well on its own, and the two rules that learn nothing: calling nothing pay, and calling every sample the larger class.

by_well = right.groupby(df["well"], sort=False)
print(by_well.mean().round(3))
away = df.loc[~home, "pay"]
print((away == 0).mean(), max(away.mean(), 1 - away.mean()))

The book's kernel gives Ogbon-3, 231.9 ft up the structure, 0.445, the hardest of the eight, and Ogbon-8, 484.5 ft down the dip, 1.000, by luck: it holds no pay and lies below the deepest interval. On the other eight wells calling nothing pay would score 0.468, and calling every sample pay, their larger class, 0.532.

Step 5: Hang the Wells on Their Top

Depth That Moves with the Beds

Every well of the set is logged over the same beds from the same top, so depth below a well's first sample is depth below the same bed, as a geologist's picked top would give.

first = df.groupby("well", sort=False)["depth_ft"]
df["below_top_ft"] = df["depth_ft"] - first.transform("min")
tree, right = rule(["below_top_ft"])
print(right[~home].mean())
print(right[df["well"] == "Ogbon-8"].mean())

The book's kernel gives 0.800 on the other eight wells, and Ogbon-8 0.539: its wet sands are the beds that hold pay in Ogbon-1. Depth below the top names the bed, but the oil-water contact is level and the beds dip, so it cannot name the fluid.

Step 6: Let the Logs Decide

Rock and Fluid in Every Well

The same tree on the porosity logs and log10 RT, fitted on the same 1201 samples.

LOGS = ["GR_API", "RHOB_gcc", "NPHI_vv", "DT_usft", "LRT"]
tree, right = rule(LOGS)
print(right[home].mean(), right[~home].mean())

The book's kernel gives 1.000 on Ogbon-1 and 0.971 on the other eight wells; its hardest well is Ogbon-8, at 0.868. scikit-learn reads the file's rounded logs and breaks ties between equally good splits its own way, so its share can differ from the kernel's in the third decimal place.

Why Depth Leaks

Leakage is information in a feature that will not be there when the model is used. Within one well, depth is a perfect label: it says where the beds are, and so where the pay is, without saying anything about rock or fluid. A score taken on Ogbon-1, or on samples drawn from it, cannot see the trouble, because every sample shares the map. Only a well the rule never saw shows it. Depth is not worthless: in Section 9.1 depth beside the logs, standardized and every well held out, scores 0.976 with kNN, as the logs alone do, because there the logs say which rock a sample is. A feature should be judged by what it would mean in the next well.

What These Scores Are

Every rule in Chapter 9 learned on one well or, in Section 9.1, on eight wells with the ninth held out. Chapter 10 compares the ways of splitting samples into training and test sets, and measures how much a split that keeps a well on both sides flatters.

This page is prerendered for SEO and accessibility. The interactive widgets above hydrate on JavaScript load.