Skip to content
svgsplit-strip

Validation fold strip

Which rows train, validate and test in each fold — and is anything leaking across time or groups?

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

How to read it

  1. Read each row as one fold of the plan, rows binned in order.
  2. Colours mark training, validation and test.
  3. Check for leaks: no validation or test bin should come before training in a time-ordered plan.
  1. Callout 1: The final fit.
  2. Callout 2: One fold's training rows.
  3. Callout 3: Test rows are held out of every fold.

Watch out

  • A plan that looks tidy can still leak through duplicates, groups or features computed on all rows.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Draws the run's numbers as given (computed by the host's cs-ml evaluation or the Python/R engine); the chart computes nothing statistical.
  • Bins come from the host's split plan summary (cs-ml SplitSummary: about 120 bins over row order, or time order when the plan is time-based); each bin is stacked by the share of its rows in each set.
  • Time-series plans show validation always to the right of training; a gap appears as an empty band between them.
  • The right margin repeats each fold's row counts.
# Validation fold strip — Codesplash Chart Lab (recipe "split-strip")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.colors import to_rgba

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"]
# non-colour encodings per series (same table as the app: series are never told apart by colour alone)
SERIES_HATCHES = ["", "////", "..", "\\\\\\\\", "---", "xx", "|||", "++"]
HATCH_INK = to_rgba(plt.rcParams["axes.facecolor"], 0.5)  # stripes let the chart surface show through

df = pd.read_csv("split-strip-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["fold"] = pd.Categorical(df["fold"].astype("string"), categories=["Final", "Fold 1", "Fold 2", "Fold 3", "Fold 4"])

_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"])  # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"])  # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
def levels_of(s):
    """Declared level order (categoricals), else order of first appearance."""
    if isinstance(s.dtype, pd.CategoricalDtype):
        return [v for v in s.cat.categories if (s == v).any()]
    return list(dict.fromkeys(s.dropna().astype(str)))
ROW = "fold"
BIN = "rows in time order (binned)"
TR = "train"
VA = "validation"
TE = "test"
EX = "excluded"
d = df.dropna(subset=[ROW, BIN])
rows = levels_of(d[ROW])
parts = [(TR, PALETTE[0], "train"), (VA, PALETTE[1], "validation"), (TE, PALETTE[2], "test")] + ([(EX, GREY, "excluded")] if EX else [])
fig, ax = plt.subplots(figsize=(9, 0.5 * len(rows) + 1.4))
for r, name in enumerate(rows):
    s = d[d[ROW].astype(str) == str(name)].sort_values(BIN)
    total = sum(s[c].fillna(0) for c, _, _ in parts).replace(0, np.nan)
    bottom = np.full(len(s), len(rows) - 1 - r - 0.4)
    for col, colour, label in parts:  # each bin's height is split by share
        h = (s[col].fillna(0) / total).fillna(0).to_numpy() * 0.8
        hatch = SERIES_HATCHES[1] if label == "test" else ""  # the held-out test set is hatched, as in the app
        ax.bar(s[BIN], h, bottom=bottom, width=1.0, color=colour, hatch=hatch, hatchcolor=HATCH_INK, linewidth=0, label=label if r == 0 else None)
        bottom = bottom + h
ax.set_yticks(range(len(rows))[::-1], rows)
ax.set_xlabel(BIN)
ax.legend(fontsize=8, ncol=len(parts), loc="upper center", bbox_to_anchor=(0.5, -0.18))
plt.show()

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