# Q-19: Interpolate a threshold from four points

Data-Driven Athletics tutorial · Week 7 · Chapter 7 · about 15 min · workflow steps: Gather, Visualize, Features

Web page: https://apopt.com/course/tutorials/q19-interpolate-threshold/ · Data: https://apopt.com/data/tutorials/q19-interpolate-threshold/

## The decision

A coach has a step test and wants one speed to call "threshold" for training. Which speed,
by which rule, and how much does the rule matter?

## The raw data

- `raw/lactate_step_illustrative.csv`: ILLUSTRATIVE step test, not a real athlete: lactate and heart rate at six stages from 10 to 15 km/h (speed_kmh, lactate_mmol, hr_bpm) The example of *Data-Driven Athletics* Section 7.4 (`book/ch07-emerging/data/lactate_step.csv`).

In a step test the athlete runs a few minutes at each of several rising speeds, and a drop of
blood at the end of each stage gives a lactate value. A threshold is a rule applied to those
points (Section 7.4). The table here is the book's **illustrative** step test, not a real
athlete: the four stages of the book's example, 12 to 15 km/h, and two easy stages before them,
with heart rate.

### The step test

*Predict first:* Look at the stages at 14 and 15 km/h (3.4 and 5.6 mmol/L). At what speed do you expect lactate to cross 4.0 mmol/L?

```python
import numpy as np
import pandas as pd

test = pd.read_csv("raw/lactate_step_illustrative.csv")   # speed_kmh, lactate_mmol, hr_bpm
v, lac = test["speed_kmh"].to_numpy(float), test["lactate_mmol"].to_numpy()
print(test.to_string(index=False))
```

Output:

```
 speed_kmh  lactate_mmol  hr_bpm
        10           1.3     138
        11           1.4     147
        12           1.6     155
        13           2.2     163
        14           3.4     171
        15           5.6     179
```

### A straight line between two stages

Find the first stage at or above the level, and draw a straight line from the stage before it:
speed = v₁ + (level − L₁) × (v₂ − v₁) / (L₂ − L₁).

```python
def cross(level):
    i = int(np.argmax(lac >= level))                      # first stage at or above the level
    return v[i - 1] + (level - lac[i - 1]) * (v[i] - v[i - 1]) / (lac[i] - lac[i - 1])

fixed = cross(4.0)
individual = cross(lac.min() + 1.0)
print(f"fixed 4.0 mmol/L:          {fixed:.2f} km/h")
print(f"lowest + 1.0 mmol/L ({lac.min() + 1.0:.1f}): {individual:.2f} km/h")
print(f"heart rate at the 4.0 crossing: {np.interp(fixed, v, test['hr_bpm']):.0f} beats/min")
```

Output:

```
fixed 4.0 mmol/L:          14.27 km/h
lowest + 1.0 mmol/L (2.3): 13.08 km/h
heart rate at the 4.0 crossing: 173 beats/min
```

The two rules are 1.2 km/h apart on the same six points. Neither is wrong; they are different
definitions. Whichever you use, name it and compare an athlete only with numbers made by the
same rule.

### A second opinion: a smooth curve

```python
from scipy.optimize import curve_fit, brentq
import matplotlib.pyplot as plt

model = lambda x, a, b, c: a + b * np.exp(c * (x - 10))
p, _ = curve_fit(model, v, lac, p0=(1, 0.1, 0.8))
smooth = brentq(lambda x: model(x, *p) - 4.0, v[0], v[-1])
print(f"fixed 4.0 mmol/L from the exponential fit: {smooth:.2f} km/h "
      f"({smooth - fixed:+.2f} against the straight line)")

xs = np.linspace(v[0], v[-1], 200)
fig, ax = plt.subplots(figsize=(6.4, 3.6))
ax.plot(v, lac, "o-", color="k", label="stages, straight segments")
ax.plot(xs, model(xs, *p), "--", label="exponential fit")
for level in (4.0, lac.min() + 1.0):
    ax.axhline(level, ls=":", color="gray")
ax.plot([fixed, individual], [4.0, lac.min() + 1.0], "s", ms=8, mfc="none", color="k")
ax.set(xlabel="speed (km/h)", ylabel="blood lactate (mmol/L)")
ax.legend(loc="upper left")
plt.tight_layout()
```

Output:

```
fixed 4.0 mmol/L from the exponential fit: 14.37 km/h (+0.09 against the straight line)
```

![Lactate in mmol/L against speed in km/h. The six stages joined by straight lines, a smooth dashed exponential curve through them, and dotted horizontal lines at 4.0 and 2.3 mmol/L, with squares where the straight lines cross them.](https://apopt.com/course/tutorials/q19-interpolate-threshold/c05-1.png)

A straight line between two points of an upward-bending curve lies above the curve, so the
straight-line crossing comes a little early; the smooth fit puts it 0.1 km/h later. The choice
of rule moved the answer more than ten times as far as the choice of arithmetic.

**For the athlete:** "On this test your lactate reached 4.0 at about 14.3 km/h, at a heart rate
near 173; that is one definition of threshold, and we will use the same one next time."

## With your own data

If your coach or lab gives you a step-test table, type it as three columns (speed, lactate,
heart rate) in place of this file. Nobody in this course is required to give blood; the
case study CS-8 simulates step tests instead.

## Action card

- **Finding:** Lactate crossed 4.0 mmol/L at 14.27 km/h; the lowest-plus-1.0 rule gives 13.08 km/h.
- **Evidence:** Straight-line interpolation between stages; an exponential fit moves the 4.0 crossing by 0.1 km/h.
- **Sure:** The arithmetic is sure to 0.1 km/h; the rule is a choice, worth 1.2 km/h here.
- **Action:** Name the rule with every threshold, and use the same rule on every retest.
- **Retest:** Repeat the step test with the same stages and rule after a training block.

## References

- *Data-Driven Athletics*, Chapter 7, The step test and the lactate curve (Section 7.4), and Chapter 2, Thresholds (Section 2.5).
- Faude, O., Kindermann, W., and Meyer, T. (2009). Lactate threshold concepts: how valid are they? *Sports Medicine*, 39(6), 469–490. [doi:10.2165/00007256-200939060-00003](https://doi.org/10.2165/00007256-200939060-00003)

---
Text CC BY 4.0, code MIT. IRSRI Sports Research Institute.
