svgdrift-timeline
Drift over time
Which features of the scoring data are drifting away from the training data, and since when?
How to read it
- Read each line as one feature's drift statistic over scoring runs.
- Compare with the alert threshold.
- A sudden rise suggests a data change; a slow rise, gradual drift.
- Callout 1: This feature crossed the alert threshold.
- Callout 2: The threshold.
- Callout 3: The stable features.
Watch out
- Input drift doesn't always hurt the model. Check performance too.
Defaults
- Alert threshold (null = none)
- 0.25
- Draw a line at the level that should raise an alert.
- Range 0 to 1,000,000, step 0.01
Pinned in the code
- Draws the run's numbers as given (computed by the Python/R engine); the chart computes nothing statistical.
- The six features with the largest value keep a colour; others are grey. PSI rule of thumb: < 0.1 stable, 0.1–0.25 moderate, > 0.25 major shift (the default alert).
# Drift over time — Codesplash Chart Lab (recipe "drift-timeline")
# controls: threshold=0.25
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"]
# non-colour encodings per series (same table as the app: series are never told apart by colour alone)
SERIES_DASHES = ["-", (0, (6, 3)), (0, (1.5, 2.5)), (0, (8, 3, 2, 3)), (0, (12, 4)), (0, (3, 3)), (0, (8, 2, 2, 2, 2, 2)), (0, (1.5, 5))]
df = pd.read_csv("drift-timeline-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["scoring week"] = pd.to_datetime(df["scoring week"])
T = "scoring week"
V = "PSI"
F = "feature"
THRESHOLD = 0.25
d = df.dropna(subset=[T, V]).sort_values(T)
top = d.groupby(F, observed=True)[V].max().sort_values(ascending=False).index[:6]
fig, ax = plt.subplots(figsize=(8, 4.5))
for name, g in d.groupby(F, observed=True):
k = list(top).index(name) if name in top else None
ax.plot(g[T], g[V], color=PALETTE[k] if k is not None else "grey", alpha=1 if k is not None else 0.45, linewidth=1.8 if k is not None else 1,
linestyle=SERIES_DASHES[k] if k is not None else "-", label=str(name) if k is not None else None) # highlighted features also differ by dash, as in the app
if THRESHOLD is not None:
ax.axhline(THRESHOLD, color="#ce5342", linestyle="--", linewidth=1)
hot = d[d[V] > THRESHOLD]
ax.scatter(hot[T], hot[V], color="#ce5342", s=16, zorder=3)
ax.set_xlabel(T)
ax.set_ylabel(V)
ax.legend(fontsize=8)
plt.show()Needs pandas, numpy, matplotlib · reads drift-timeline-demo.csv · app theme from the optional codesplash helper
# Drift over time — Codesplash Chart Lab (recipe "drift-timeline")
# controls: threshold=0.25
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
# non-colour encodings per series (same table as the app: series are never told apart by colour alone)
SERIES_DASHES = ["solid", "6px,3px", "1.5px,2.5px", "8px,3px,2px,3px", "12px,4px", "3px,3px", "8px,2px,2px,2px,2px,2px", "1.5px,5px"]
df = pd.read_csv("drift-timeline-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["scoring week"] = pd.to_datetime(df["scoring week"])
T = "scoring week"
V = "PSI"
F = "feature"
THRESHOLD = 0.25
d = df.dropna(subset=[T, V]).sort_values(T)
top = list(d.groupby(F, observed=True)[V].max().sort_values(ascending=False).index[:6])
dash = {f: SERIES_DASHES[top.index(f)] if f in top else "solid" for f in d[F].unique()} # the highlighted features also differ by dash, as in the app
fig = px.line(d, x=T, y=V, color=F, line_dash=F, line_dash_map=dash, color_discrete_sequence=PALETTE)
if THRESHOLD is not None:
fig.add_hline(y=THRESHOLD, line=dict(color="#ce5342", dash="dash"), annotation_text="alert")
fig.update_layout(legend_title=None)
fig.show()Needs pandas, numpy, plotly · reads drift-timeline-demo.csv · app theme from the optional codesplash helper
# Drift over time — Codesplash Chart Lab (recipe "drift-timeline")
# controls: threshold=0.25
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))
# non-colour encodings per series (same table as the app: series are never told apart by colour alone)
cs_linetypes <- c("solid", "63", "23", "8323", "C4", "33", "822222", "25")
df <- read.csv("drift-timeline-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["scoring week"]] <- as.POSIXct(df[["scoring week"]], tz = "UTC")
df[["feature"]] <- factor(df[["feature"]])
t_col <- "scoring week"
v_col <- "PSI"
f_col <- "feature"
threshold <- 0.25
d <- data.frame(t = df[[t_col]], v = df[[v_col]], f = as.character(df[[f_col]]))
top <- utils::head(names(sort(tapply(d$v, d$f, max), decreasing = TRUE)), 6)
d$shown <- factor(ifelse(d$f %in% top, d$f, "other"), levels = c(top, "other"))
p <- ggplot(d, aes(t, v, group = f, colour = shown, linetype = shown)) + geom_line(aes(alpha = shown != "other")) + # highlighted features also differ by dash, as in the app
{ if (!is.null(threshold)) list(geom_hline(yintercept = threshold, colour = "#ce5342", linetype = "dashed"), geom_point(data = d[d$v > threshold, ], colour = "#ce5342", size = 1.6)) } +
# values named by level (a partly named vector matched only "other", leaving the top features grey)
scale_alpha_manual(values = c("FALSE" = 0.4, "TRUE" = 1), guide = "none") + scale_colour_manual(values = setNames(c(cs_cat[seq_along(top)], "grey55"), c(top, "other"))) +
scale_linetype_manual(values = setNames(c(cs_linetypes[seq_along(top)], "solid"), c(top, "other"))) +
labs(x = t_col, y = v_col, colour = NULL, linetype = NULL) + theme_cs
print(p)Needs ggplot2 · reads drift-timeline-demo.csv · app theme from the optional codesplashr helper