svglearning-curve
Learning curve
Would more data help, or is the model limited by bias or variance?
How to read it
- Compare the training and validation lines as rows grow.
- A persistent gap suggests overfitting; more data may help.
- Both low and close together suggests a model too simple; more data won't help much.
- Callout 1: Training score.
- Callout 2: Validation score: rises with more rows.
- Callout 3: The gap at the end: what more data could still close.
Watch out
- Splits vary: read the bands before concluding the curves have flattened.
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.
- Bands are the engine's (mean ± 1 SD across folds unless the run says otherwise); every size uses the same folds.
# Learning curve — Codesplash Chart Lab (recipe "learning-curve")
# controls: defaults
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("learning-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=["train", "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 = "training rows"
Y = "accuracy"
LO = "lower"
HI = "upper"
G = "set"
groups = levels_of(df[G]) if G else [None]
series = []
for name in groups:
d = df if name is None else df[df[G].astype(str) == str(name)]
series.append((name if name is not None else "", d.dropna(subset=[X]).sort_values(X)))
fig, ax = plt.subplots(figsize=(8, 4.5))
for i, (name, d) in enumerate(series):
col = PALETTE[i % len(PALETTE)]
if LO and HI:
ax.fill_between(d[X], d[LO], d[HI], color=col, alpha=0.15, lw=0)
ax.plot(d[X], d[Y], color=col, linewidth=2, label=name or Y)
ax.set_xlabel(X)
ax.set_ylabel(Y)
if G: ax.legend(fontsize=8)
plt.show()Needs pandas, numpy, matplotlib · reads learning-curve-demo.csv · app theme from the optional codesplash helper
# Learning curve — Codesplash Chart Lab (recipe "learning-curve")
# controls: defaults
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("learning-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=["train", "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)))
def rgba(hex_colour, alpha):
h = hex_colour.lstrip("#")
return f"rgba({int(h[0:2], 16)}, {int(h[2:4], 16)}, {int(h[4:6], 16)}, {alpha})"
X = "training rows"
Y = "accuracy"
LO = "lower"
HI = "upper"
G = "set"
groups = levels_of(df[G]) if G else [None]
series = []
for name in groups:
d = df if name is None else df[df[G].astype(str) == str(name)]
series.append((name if name is not None else "", d.dropna(subset=[X]).sort_values(X)))
fig = go.Figure()
for i, (name, d) in enumerate(series):
col = PALETTE[i % len(PALETTE)]
shape = "linear"
if LO and HI:
fig.add_scatter(x=d[X], y=d[LO], mode="lines", line=dict(width=0, shape=shape), showlegend=False, hoverinfo="skip")
fig.add_scatter(x=d[X], y=d[HI], mode="lines", line=dict(width=0, shape=shape), fill="tonexty", fillcolor=rgba(col, 0.15), showlegend=False, hoverinfo="skip")
fig.add_scatter(x=d[X], y=d[Y], mode="lines", name=name or Y, line=dict(color=col, width=2, shape=shape))
fig.update_layout(xaxis_title=X, yaxis_title=Y)
fig.show()Needs pandas, numpy, plotly · reads learning-curve-demo.csv · app theme from the optional codesplash helper
# Learning curve — Codesplash Chart Lab (recipe "learning-curve")
# controls: defaults
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("learning-curve-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["set"]] <- factor(df[["set"]], levels = c("train", "validation"))
levels_of <- function(v) if (is.factor(v)) levels(droplevels(v)) else unique(as.character(v[!is.na(v)]))
x_col <- "training rows"
y_col <- "accuracy"
lo_col <- "lower"
hi_col <- "upper"
g_col <- "set"
d <- data.frame(x = df[[x_col]], y = df[[y_col]], g = if (is.null(g_col)) "" else factor(as.character(df[[g_col]]), levels = levels_of(df[[g_col]])))
d$lo <- if (is.null(lo_col)) NA_real_ else df[[lo_col]]
d$hi <- if (is.null(hi_col)) NA_real_ else df[[hi_col]]
d <- d[!is.na(d$x) & !is.na(d$y), ]
d <- d[order(d$g, d$x), ]
p <- ggplot(d, aes(x, y, colour = g, fill = g)) +
{ if (!all(is.na(d$lo))) geom_ribbon(aes(ymin = lo, ymax = hi), colour = NA, alpha = 0.15) } + geom_line(linewidth = 0.9) +
scale_colour_manual(values = cs_cat, guide = if (is.null(g_col)) "none" else "legend") + scale_fill_manual(values = cs_cat, guide = "none") +
labs(x = x_col, y = y_col, colour = NULL) + theme_cs
print(p)Needs ggplot2 · reads learning-curve-demo.csv · app theme from the optional codesplashr helper