Skip to content
svgpred-actual

Predicted vs actual

How close are a regression model's predictions to the true values, and where does it miss?

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

How to read it

  1. Read each point as one row's prediction and true value.
  2. Points on the diagonal: right on target.
  3. Look for bends and funnels: bias at high values or errors that grow.
  1. Callout 1: Diagonal: perfect prediction.
  2. Callout 2: Low values above the line: under-predicted.
  3. Callout 3: Colour: validation or test rows.

Watch out

  • Only held-out rows tell you how the model will do on new data.

Defaults

Identity line (equal axes)
On
Draw y = x with equal axes, so distance from the line is the error.

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.
  • Prediction on x and actual on y (scikit-learn's PredictionErrorDisplay); points above the line are under-predicted.
  • With the identity line on, both axes share one range so the 45° line means equality.
  • Validation points are out-of-fold predictions; test points come from the final model, scored once.
# Predicted vs actual — Codesplash Chart Lab (recipe "pred-actual")
# controls: identity=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("pred-actual-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["split"] = pd.Categorical(df["split"].astype("string"), categories=["validation", "test"])

_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")
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)))
ACT = "sale price (k€)"
PRED = "predicted price (k€)"
SET = "split"
IDENTITY = True
d = df.dropna(subset=[ACT, PRED])
sets = levels_of(d[SET]) if SET else [None]
fig, ax = plt.subplots(figsize=(6, 6))
for i, s in enumerate(sets):
    g = d if s is None else d[d[SET].astype(str) == str(s)]
    ax.scatter(g[PRED], g[ACT], s=12, alpha=0.6, color=PALETTE[i % len(PALETTE)], label=str(s) if s is not None else None)
lo, hi = float(min(d[ACT].min(), d[PRED].min())), float(max(d[ACT].max(), d[PRED].max()))
if IDENTITY:
    ax.plot([lo, hi], [lo, hi], color=REF, linestyle="--", linewidth=1, label="perfect prediction (y = x)")
ax.set_xlabel(PRED)
ax.set_ylabel(ACT)
ax.legend(fontsize=8)
plt.show()

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