svgensemble-spread
Ensemble spread
Where do the members of an ensemble disagree, and does the band hold the actual values?
How to read it
- Read the x axis as rows ordered by the ensemble's prediction, lowest on the left.
- Read the grey dots at one position as the members' predictions for that row; a tall column means they disagree.
- Compare the ticks (actual values) with the shaded band: the legend says what share of them it holds.
- Callout 1: Members agree: the dots sit on the line.
- Callout 2: Members spread out: the model is unsure here.
- Callout 3: Shaded band around the consensus line.
Watch out
- These are training rows, so the band looks better here than on new data; judge coverage from the held-out 90% coverage metric.
- TabM's members share most weights, so their spread understates uncertainty; read it as disagreement, not as an interval.
Defaults
- Member dots
- On
- Show each member's prediction as a dot.
Pinned in the code
- Draws the numbers the learner published (training history, member predictions, predicted densities); the chart computes nothing statistical.
- The band is whatever the learner published: a deep ensemble's mixture interval (mean ± 1.645 SD, 90% if Normal) or the members' lowest-to-highest range for TabM.
- Rows are training rows, evenly spaced in the order of the ensemble's prediction; read held-out coverage from the run's metrics, not from this picture.
# Ensemble spread — Codesplash Chart Lab (recipe "ensemble-spread")
# controls: members=true
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("ensemble-spread-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["member"] = pd.Categorical(df["member"].astype("string"), categories=["member 1", "member 2", "member 3", "member 4", "member 5"])
_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")
X = "row (ordered by prediction)"
Y = "member prediction"
C = "ensemble"
LO = "90% low"
HI = "90% high"
A = "actual"
SHOW_MEMBERS = True
rows = df.drop_duplicates(subset=[X]).sort_values(X) # one row per position: consensus, band, actual
fig, ax = plt.subplots(figsize=(7, 4.2))
if LO and HI:
ax.fill_between(rows[X], rows[LO], rows[HI], color=PALETTE[0], alpha=0.18, linewidth=0, label="band")
if SHOW_MEMBERS:
ax.scatter(df[X], df[Y], s=6, color=GREY, alpha=0.9, label="members")
ax.plot(rows[X], rows[C], color=PALETTE[0], linewidth=1.6, label=C)
if A:
ax.scatter(rows[X], rows[A], marker="_", s=70, color=REF, linewidths=1.5, label=A)
ax.set_xlabel(X)
ax.set_ylabel(Y)
ax.legend(frameon=False, fontsize=8)
plt.show()Needs pandas, numpy, matplotlib · reads ensemble-spread-demo.csv · app theme from the optional codesplash helper
# Ensemble spread — Codesplash Chart Lab (recipe "ensemble-spread")
# controls: members=true
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("ensemble-spread-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["member"] = pd.Categorical(df["member"].astype("string"), categories=["member 1", "member 2", "member 3", "member 4", "member 5"])
_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")
X = "row (ordered by prediction)"
Y = "member prediction"
C = "ensemble"
LO = "90% low"
HI = "90% high"
A = "actual"
SHOW_MEMBERS = True
rows = df.drop_duplicates(subset=[X]).sort_values(X)
fig = go.Figure()
if LO and HI:
fig.add_trace(go.Scatter(x=list(rows[X]) + list(rows[X])[::-1], y=list(rows[HI]) + list(rows[LO])[::-1], fill="toself", fillcolor="rgba(70,110,200,0.18)", line=dict(width=0), name="band", hoverinfo="skip"))
if SHOW_MEMBERS:
fig.add_trace(go.Scatter(x=df[X], y=df[Y], mode="markers", marker=dict(color=GREY, size=4), name="members"))
fig.add_trace(go.Scatter(x=rows[X], y=rows[C], mode="lines", line=dict(color=PALETTE[0], width=2), name=C))
if A:
fig.add_trace(go.Scatter(x=rows[X], y=rows[A], mode="markers", marker=dict(symbol="line-ew", color=REF, size=10, line=dict(width=2, color=REF)), name=A))
fig.update_layout(xaxis_title=X, yaxis_title=Y)
fig.show()Needs pandas, numpy, plotly · reads ensemble-spread-demo.csv · app theme from the optional codesplash helper
# Ensemble spread — Codesplash Chart Lab (recipe "ensemble-spread")
# controls: members=true
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("ensemble-spread-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["member"]] <- factor(df[["member"]], levels = c("member 1", "member 2", "member 3", "member 4", "member 5"))
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
X <- "row (ordered by prediction)"
Y <- "member prediction"
C <- "ensemble"
LO <- "90% low"
HI <- "90% high"
A <- "actual"
show_members <- TRUE
rows <- df[!duplicated(df[[X]]), , drop = FALSE]
rows <- rows[order(rows[[X]]), , drop = FALSE]
r <- data.frame(x = rows[[X]], centre = rows[[C]])
p <- ggplot()
if (!is.null(LO) && !is.null(HI)) {
r$lo <- rows[[LO]]; r$hi <- rows[[HI]]
p <- p + geom_ribbon(data = r, aes(x, ymin = lo, ymax = hi), fill = cs_cat[1], alpha = 0.18)
}
if (show_members) p <- p + geom_point(data = data.frame(x = df[[X]], y = df[[Y]]), aes(x, y), colour = grey_col, size = 0.8)
p <- p + geom_line(data = r, aes(x, centre), colour = cs_cat[1], linewidth = 0.7)
if (!is.null(A)) p <- p + geom_point(data = data.frame(x = rows[[X]], a = rows[[A]]), aes(x, a), shape = 95, size = 5, colour = ref_col)
p <- p + labs(x = X, y = Y)
print(p)Needs ggplot2 · reads ensemble-spread-demo.csv · app theme from the optional codesplashr helper