# Q-39: Turn a table into an action card

Data-Driven Athletics tutorial · Week 13 · Chapter 13 · about 20 min · workflow steps: Deploy

Web page: https://apopt.com/course/tutorials/q39-action-card/ · Data: https://apopt.com/data/tutorials/q39-action-card/

## The decision

A player asks what separates their made shots from their misses. Decide what the card can
honestly say from ten shots and five measures, and the one thing the player should try next.

## The raw data

- `raw/shot_trials_synthetic.csv`: SYNTHETIC: ten jump shots by one player, five measures each from the basketball app's results files (release angle and height, elbow angle, knee flexion, release timing), and made or missed Book example data, Chapter 10 (`book/ch10-skill/data/trials.csv`), made with a fixed seed in the layout of the apps' text results.

A results table answers "what was measured". An **action card** answers what the athlete
should do: five lines, written for them (the course's case-study template):

1. **Finding**: the one thing the data showed.
2. **Evidence**: the numbers behind it, in the athlete's units.
3. **How sure**: in words, with the reason.
4. **Action**: one thing to do, specific enough to do tomorrow.
5. **Retest**: when and how to look again.

The table is Chapter 10's **synthetic** set of ten jump shots by one player: five measures
from the basketball app's results files for each shot, and whether it went in. The player's
question: what separates my makes from my misses?

### The table, made against missed

*Predict first:* Which measure do you expect to differ most between makes and misses?

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

shots = pd.read_csv("raw/shot_trials_synthetic.csv")
METRICS = ["Ball Release Angle", "Ball Release Height", "Elbow Angle", "Knee Flexion", "Release Timing vs Apex"]
made, missed = shots[shots["made"] == 1], shots[shots["made"] == 0]
print(f"{len(shots)} shots, {len(made)} made")
print(pd.DataFrame({"made median": made[METRICS].median(), "missed median": missed[METRICS].median()}).to_string())
```

Output:

```
10 shots, 6 made
                        made median  missed median
Ball Release Angle            46.85         44.900
Ball Release Height            1.07          1.045
Elbow Angle                  159.50        160.000
Knee Flexion                  99.50        103.500
Release Timing vs Apex       -22.50         -7.500
```

A difference in medians is not yet a finding. With six makes and four misses, the
**probability of superiority** (Section 10.6) says how often a made shot beats a missed one
on a measure (0.5 means no difference), and a bootstrap gives it a range.

*Predict first:* Will any measure's 95% range leave out 0.5?

```python
rng = np.random.default_rng(493)

def superiority(a, b):
    diff = a[:, None] - b[None, :]                  # every made shot against every missed shot
    return (diff > 0).mean() + 0.5 * (diff == 0).mean()

rows = []
for m in METRICS:
    a, b = made[m].to_numpy(), missed[m].to_numpy()
    boot = [superiority(rng.choice(a, a.size), rng.choice(b, b.size)) for _ in range(2000)]
    lo, hi = np.percentile(boot, [2.5, 97.5])
    rows.append({"measure": m, "A": superiority(a, b), "low": lo, "high": hi,
                 "clear": not lo <= 0.5 <= hi})
table = pd.DataFrame(rows).sort_values("A", key=lambda s: (s - 0.5).abs(), ascending=False)
print(table.round(2).to_string(index=False))
```

Output:

```
               measure    A  low  high  clear
Release Timing vs Apex 0.04 0.00  0.25   True
   Ball Release Height 0.90 0.62  1.00   True
    Ball Release Angle 0.71 0.33  1.00  False
          Knee Flexion 0.31 0.04  0.67  False
           Elbow Angle 0.33 0.04  0.71  False
```

### From the table to the card

The card is filled from the table by rules, so the words cannot claim more than the numbers:
a measure goes in the finding only if its range leaves out 0.5; otherwise the finding says so,
and the action is to collect what would decide it.

```python
import matplotlib.pyplot as plt

UNITS = {"Release Timing vs Apex": "ms; minus is before the top of the jump"}
PLAIN = {("Release Timing vs Apex", "lower"): "let the ball go earlier, on the way up"}
SIDE = {"Release Timing vs Apex": {"lower": "earlier", "higher": "later"}}
top = table.iloc[0]
m = top["measure"]
share, side = (top["A"], "higher") if top["A"] >= 0.5 else (1 - top["A"], "lower")
said = PLAIN.get((m, side), f"had a {side} {m.lower()}")
card = {"Finding": f"On your makes you {said}." if top["clear"] else "No measure separates your makes from your misses yet.",
        "Evidence": f"{m}: median {made[m].median():.1f} on makes, {missed[m].median():.1f} on misses "
                    f"({UNITS.get(m, 'app units')}); the make was {SIDE.get(m, {}).get(side, side)} in {share:.0%} of make-miss pairs.",
        "How sure": (f"Moderate: ten shots in one session, and {len(table)} measures checked, so one clear result could be luck."
                     if top["clear"] else "Unclear: every range includes no difference."),
        "Action": "Next session, aim to let the ball go on the way up, before the top of your jump.",
        "Retest": "Film 20 more shots from the same spot over two sessions and rerun this card."}
for k, v in card.items():
    print(f"{k:9s} {v}")

fig, ax = plt.subplots(figsize=(6.0, 2.2))
for y, d, fill in [(1, made, "black"), (0, missed, "white")]:
    ax.plot(d[m], [y] * len(d), "o", mfc=fill, mec="black", ms=8)
    ax.plot([d[m].median()] * 2, [y - 0.3, y + 0.3], "-" if y else "--", color="black")
ax.set(yticks=[0, 1], yticklabels=["missed", "made"], ylim=(-0.6, 1.6), xlabel=f"{m.lower()} ({UNITS.get(m, 'app units')})",
       title="Makes left the hand earlier before the top")
plt.tight_layout()
```

Output:

```
Finding   On your makes you let the ball go earlier, on the way up.
Evidence  Release Timing vs Apex: median -22.5 on makes, -7.5 on misses (ms; minus is before the top of the jump); the make was earlier in 96% of make-miss pairs.
How sure  Moderate: ten shots in one session, and 5 measures checked, so one clear result could be luck.
Action    Next session, aim to let the ball go on the way up, before the top of your jump.
Retest    Film 20 more shots from the same spot over two sessions and rerun this card.
```

![Release timing relative to the top of the jump for ten shots, as dots on one line for made shots (filled) and one for missed shots (open), with each group's median marked; made shots sit further before the top.](https://apopt.com/course/tutorials/q39-action-card/c05-1.png)

The release angle, the measure the chapter looked at first, does not separate the shots: its
range runs from 0.33 to 1.00. Release timing does: in 96% of make-miss pairs the make left the
hand earlier before the top of the jump, and release height points the same way. Two cautions
go on the card in words, not numbers: ten shots from one session, and five measures checked,
so one clear result could still be luck. That is why the action is one small change and the
retest is already booked. Had no range left out 0.5, the rule would have written "not yet",
which is a finding too.

**For the athlete:** "On your makes you let the ball go a little earlier, on the way up; try
that on purpose next session, and we will film 20 more to see if it holds."

## Action card

- **Finding:** On your makes you let the ball go earlier, on the way up.
- **Evidence:** Release timing: median 22.5 ms before the top of the jump on makes, 7.5 ms on misses; the make was earlier in 96% of make-miss pairs.
- **Sure:** Moderate: ten shots in one session, and five measures checked, so one clear result could be luck.
- **Action:** Next session, aim to let the ball go on the way up, before the top of your jump.
- **Retest:** Film 20 more shots from the same spot over two sessions and rerun the card.

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