Skip to content
svgexpected-loss

Expected loss by decision

If we ship (or keep the control) now, how much do we expect to lose if that choice turns out wrong?

Demo data · seed 20261101 · 3 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read blue as the expected loss of shipping that arm, orange as that of keeping control.
  2. Compare with your tolerable loss.
  3. Ship only when the loss from shipping is below that threshold.
  1. Callout 1: Keeping control here risks a large loss.
  2. Callout 2: Shipping B risks almost nothing.
  3. Callout 3: Shipping D has a larger expected loss than keeping control.

Watch out

  • Expected loss depends on the prior and on a loss scale that must suit the business.

Defaults

Tolerable loss ε
0
The loss you can accept if your decision turns out wrong.
Range 0 to 1,000,000,000, step 0.0001

Pinned in the code

  • Draws the run's numbers as given (computed by the Python/R engine); the chart computes nothing statistical.
  • Expected loss of shipping = E[max(control − treatment, 0)] under the posterior (in the metric's units, for a higher-is-better metric); of keeping the control = E[max(treatment − control, 0)].
  • The decision rule ships the treatment when its expected loss is below ε and keeps the control when that loss is below ε; otherwise keep collecting data.
# Expected loss by decision — Codesplash Chart Lab (recipe "expected-loss")
# controls: threshold=0
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("expected-loss-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["arm"] = pd.Categorical(df["arm"].astype("string"), categories=["B", "C", "D"])

A = "arm"
SHIP = "loss if shipped"
KEEP = "loss if not shipped"
EPS = 0
d = df.dropna(subset=[A, SHIP, KEEP])
x = np.arange(len(d))
fig, ax = plt.subplots(figsize=(8, 4.5))
ax.bar(x - 0.2, d[SHIP], width=0.4, color=PALETTE[0], label="expected loss if shipped")
ax.bar(x + 0.2, d[KEEP], width=0.4, color=PALETTE[1], label="expected loss if not shipped")
if EPS:
    ax.axhline(EPS, color="black", linestyle="--", linewidth=1.2, label=f"tolerable loss ε = {EPS:g}")
ax.set_xticks(x, d[A].astype(str))
ax.set_ylabel("expected loss")
ax.legend(fontsize=8)
plt.show()

Needs pandas, numpy, matplotlib · reads expected-loss-demo.csv · app theme from the optional codesplash helper