Skip to content
svgvalidation-curve

Validation curve

How does one hyperparameter trade underfitting for overfitting?

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

How to read it

  1. Compare training and validation scores across one hyperparameter.
  2. Where validation peaks: the best trade-off.
  3. Where the lines part: more complexity only fits noise.
  1. Callout 1: Validation peaks at this value.
  2. Callout 2: Training keeps climbing.
  3. Callout 3: Low values: both low, so the model is too simple.

Watch out

  • The peak was chosen on validation data, so its score is optimistic.

Defaults

Log scale
Off
Log x axis (automatic when the values span 100× or more).

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.
  • Every value is re-fit on the same folds; bands are mean ± 1 SD across folds. Training scores are each fold's model scored on its own training rows.
# Validation curve — Codesplash Chart Lab (recipe "validation-curve")
# controls: logX=false
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("validation-curve-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["set"] = pd.Categorical(df["set"].astype("string"), categories=["Training", "Validation"])

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)))
X = "max depth"
S = "ROC AUC"
K = "set"
LO = "lower"
HI = "upper"
numeric = pd.api.types.is_numeric_dtype(df[X])
settings = levels_of(df[X]) if not numeric else None
fig, ax = plt.subplots(figsize=(7, 4.5))
for i, k in enumerate(levels_of(df[K])):
    g = df[df[K].astype(str) == str(k)].dropna(subset=[S]).copy()
    g["_x"] = g[X].astype(float) if numeric else g[X].astype(str).map({s: j for j, s in enumerate(settings)})
    g, col = g.sort_values("_x"), PALETTE[i % len(PALETTE)]
    ax.plot(g["_x"], g[S], marker="o", color=col, label=str(k))
    if LO and HI:
        ax.fill_between(g["_x"], g[LO], g[HI], color=col, alpha=0.18)

if not numeric:
    ax.set_xticks(range(len(settings)), settings)
ax.set_xlabel(X)
ax.set_ylabel(S)
ax.legend(fontsize=8)
plt.show()

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