svgtrial-history
Tuning history
Is the hyperparameter search still improving, and which trials were pruned?
How to read it
- Read each dot as a trial's score, in order.
- Read the step line as the best so far.
- If the best line is flat for many trials, the search has probably run its course.
- Callout 1: The running best.
- Callout 2: A completed trial.
- Callout 3: A pruned or failed trial.
Watch out
- The best trial's score is optimistic: it was chosen for being highest. Test it on untouched data.
Defaults
- Lower is better
- Off
- Say whether a lower score is better, for the running best line.
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.
- The running best is the engine's when sent; otherwise the chart takes the best completed trial so far (pruned and failed trials never count).
- Pruned trials stopped after their first folds (racing / median pruner), so their score covers fewer folds.
# Tuning history — Codesplash Chart Lab (recipe "trial-history")
# controls: minimize=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("trial-history-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["status"] = pd.Categorical(df["status"].astype("string"), categories=["complete", "pruned", "failed"])
_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")
TRIAL = "trial"
SCORE = "ROC AUC"
BEST = None
STATUS = "status"
MINIMIZE = False # lower scores are better
d = df.dropna(subset=[TRIAL]).sort_values(TRIAL)
status = d[STATUS].astype(str).str.lower() if STATUS else pd.Series("complete", index=d.index)
done = d[status == "complete"]
best = d[BEST] if BEST else (done[SCORE].cummin() if MINIMIZE else done[SCORE].cummax()).reindex(d.index).ffill() # running best
fig, ax = plt.subplots(figsize=(8, 4.5))
ax.scatter(done[TRIAL], done[SCORE], s=22, color=PALETTE[0], label="complete")
pruned = d[status == "pruned"]
ax.scatter(pruned[TRIAL], pruned[SCORE], s=22, facecolors="none", edgecolors="grey", label="pruned")
failed = d[status == "failed"]
if len(failed):
ax.scatter(failed[TRIAL], np.full(len(failed), np.nanmin(d[SCORE]) if len(done) else 0), marker="x", color="#ce5342", label="failed")
ax.step(d[TRIAL], best, where="post", color=REF, linewidth=1.6, label="best so far")
ax.set_xlabel(TRIAL)
ax.set_ylabel(SCORE)
ax.legend(fontsize=8)
plt.show()Needs pandas, numpy, matplotlib · reads trial-history-demo.csv · app theme from the optional codesplash helper
# Tuning history — Codesplash Chart Lab (recipe "trial-history")
# controls: minimize=false
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
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 px.colors.qualitative.Plotly
df = pd.read_csv("trial-history-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["status"] = pd.Categorical(df["status"].astype("string"), categories=["complete", "pruned", "failed"])
_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")
TRIAL = "trial"
SCORE = "ROC AUC"
BEST = None
STATUS = "status"
MINIMIZE = False
d = df.dropna(subset=[TRIAL]).sort_values(TRIAL)
status = d[STATUS].astype(str).str.lower() if STATUS else pd.Series("complete", index=d.index)
done = d[status == "complete"]
best = d[BEST] if BEST else (done[SCORE].cummin() if MINIMIZE else done[SCORE].cummax()).reindex(d.index).ffill()
fig = go.Figure()
fig.add_scatter(x=done[TRIAL], y=done[SCORE], mode="markers", name="complete", marker=dict(color=PALETTE[0], size=7))
pruned = d[status == "pruned"]
fig.add_scatter(x=pruned[TRIAL], y=pruned[SCORE], mode="markers", name="pruned", marker=dict(color="white", size=7, line=dict(color="grey", width=1.2)))
failed = d[status == "failed"]
if len(failed):
fig.add_scatter(x=failed[TRIAL], y=[float(np.nanmin(d[SCORE]))] * len(failed), mode="markers", name="failed", marker=dict(symbol="x", color="#ce5342", size=8))
fig.add_scatter(x=d[TRIAL], y=best, mode="lines", name="best so far", line=dict(color=REF, width=2, shape="hv"))
fig.update_layout(xaxis_title=TRIAL, yaxis_title=SCORE)
fig.show()Needs pandas, numpy, plotly · reads trial-history-demo.csv · app theme from the optional codesplash helper
# Tuning history — Codesplash Chart Lab (recipe "trial-history")
# controls: minimize=false
library(ggplot2)
has_cs <- isTRUE(requireNamespace("codesplashr", quietly = TRUE)) # optional: the app's chart theme
theme_cs <- if (has_cs) codesplashr::theme_codesplash(dark = FALSE) else theme_minimal()
cs_cat <- if (has_cs) codesplashr::cs_palette(dark = FALSE)$categorical else grDevices::palette.colors(8, "Okabe-Ito")
if (has_cs) update_geom_defaults("text", list(colour = codesplashr::cs_palette(dark = FALSE)$foreground))
df <- read.csv("trial-history-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["status"]] <- factor(df[["status"]], levels = c("complete", "pruned", "failed"))
tok <- if (has_cs) codesplashr::cs_palette(dark = FALSE) else list()
seq_ramp <- if (is.null(tok$sequential)) c("#eff6fd", "#1a469d") else tok$sequential # low → high
div_ramp <- if (is.null(tok$diverging)) c("#c13e2e", "#f3f5f8", "#0859ac") else tok$diverging # −, 0, +
ref_col <- if (is.null(tok$reference)) "#4e5661" else tok$reference
grey_col <- if (is.null(tok$dim)) "#ced1d6" else tok$dim
trial_col <- "trial"
score_col <- "ROC AUC"
best_col <- NULL
status_col <- "status"
minimize <- FALSE # lower scores are better
d <- df[!is.na(df[[trial_col]]), ]
d <- data.frame(t = d[[trial_col]], s = d[[score_col]], status = if (is.null(status_col)) "complete" else tolower(as.character(d[[status_col]])),
best = if (is.null(best_col)) NA_real_ else d[[best_col]])
d <- d[order(d$t), ]
if (is.null(best_col)) { # running best over completed trials
s <- ifelse(d$status == "complete", d$s, if (minimize) Inf else -Inf)
d$best <- if (minimize) cummin(s) else cummax(s)
d$best[!is.finite(d$best)] <- NA
}
floor_s <- min(d$s, na.rm = TRUE)
p <- ggplot(d, aes(t)) + geom_step(aes(y = best), colour = ref_col, linewidth = 0.8, na.rm = TRUE) +
geom_point(data = d[d$status == "complete", ], aes(y = s), colour = cs_cat[1], size = 1.8) +
geom_point(data = d[d$status == "pruned", ], aes(y = s), shape = 21, colour = "grey50", fill = NA, size = 1.8) +
geom_point(data = d[d$status == "failed", ], aes(y = floor_s), shape = 4, colour = "#ce5342", size = 2) +
labs(x = trial_col, y = score_col) + theme_cs
print(p)Needs ggplot2 · reads trial-history-demo.csv · app theme from the optional codesplashr helper