Back to projects

Wellbore geology prediction

A horizontal oil well has to stay inside a thin layer of rock for thousands of feet. This Kaggle competition asked how deep that layer sits along the rest of the well, given only the drill path and a gamma-ray reading. I solved it with geology-aware path matching rather than a black-box model.

Held-out RMSE
12.4 ft
vs. baseline
−37%
Search window
±30 ft
Resolution
0.5 ft

The problem

For each well I had its 3D trajectory and a gamma-ray log, a measurement that changes as the drill bit passes through different rock. The target was True Vertical Thickness (TVT): where the bit sits relative to the formation, for every point past where the known data stops.

The obvious move is to throw coordinates into a gradient-boosted model. The catch is extrapolation: those models fit the training wells well but drift as they predict further along a new well, because nothing stops them from predicting rock layers that jump around in physically impossible ways.

Approach

Instead, I built the prediction in layers, each one a constraint a geologist would recognize.

  1. Regional structure. For each well, find its 5 nearest neighbors and fit a tilted plane through their formation depths. Rock layers dip gently across a region, and this captures that trend.
  2. Anchor the starting depth. Some reference logs were missing the formation tops. I back-calculated them from the part of the well where the answer is known, which gave a stable starting point.
  3. Correct local bias, then let it fade. Fit a small linear correction on the known section, then smoothly damp it back toward the regional average over about 1,000 ft, so a local quirk doesn't get extrapolated forever.
  4. Match the rock signature. Treat the remaining uncertainty as a path-finding problem. At each point along the well, consider every depth offset from −30 to +30 ft in 0.5 ft steps. Score each by how well the gamma-ray reading matches the reference profile at that depth, and penalize sudden jumps between neighboring points. The Viterbi algorithm finds the single smoothest, best-matching path through all of them.

The smoothness penalty is what makes it work: real rock layers bend gradually, so the model is simply not allowed to predict anything else.

Results

Evaluated on the three public sample wells. For each one, the depth after the known section is hidden and predicted, and the regional plane is fitted only from the other wells, so nothing about the answer leaks in.

WellBaseline onlyWith path matching
Well 119.5 ft10.1 ft
Well 221.4 ft16.1 ft
Well 317.1 ft7.2 ft
All 14,151 points19.6 ft12.4 ft

Path matching cuts the error by about 37%. It helps most where the gamma-ray signature is distinctive (Well 3) and least where the layer drifts further than the search window allows (Well 2). You can see both effects for yourself in the live demo.

What I'd do next