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.
- 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.
- 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.
- 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.
- 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.
| Well | Baseline only | With path matching |
|---|---|---|
| Well 1 | 19.5 ft | 10.1 ft |
| Well 2 | 21.4 ft | 16.1 ft |
| Well 3 | 17.1 ft | 7.2 ft |
| All 14,151 points | 19.6 ft | 12.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
- Learn the smoothness penalty from the training wells rather than hand-tuning it, ideally varying it by region.
- Use more than one log. Gamma-ray alone can be ambiguous where two layers look alike. Adding a second measurement would sharpen the matching.
- Report uncertainty. Viterbi gives one best path. Keeping the next-best paths would show a driller how confident the prediction is at each point.