Prediction errors
Visualize predicted vs. true values for regression models. An identity line (y = x) is always shown — points on the line are perfect predictions, points above overestimate, and points below underestimate.
Both axes share the same scale domain (with 2% padding), so the visual distance from the identity line is geometrically accurate.
Basic usage
import polars as pl
from plotutils.uncertainty import plot_predictions_errors
df = pl.DataFrame({
"true": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0],
"pred": [1.1, 2.2, 2.8, 4.1, 5.3, 5.9, 7.2, 7.8, 9.1, 10.3],
})
chart = plot_predictions_errors(df)
Color and shape encoding
Use color_col and shape_col to distinguish groups — for example, different models
or train/test splits:
df = pl.DataFrame({
"true": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0],
"pred": [1.1, 2.2, 2.8, 4.1, 5.3, 5.9, 7.2, 7.8],
"model": ["A", "A", "B", "B", "A", "A", "B", "B"],
"split": ["train", "test", "train", "test", "train", "test", "train", "test"],
})
chart = plot_predictions_errors(df, color_col="model", shape_col="split")
Multi-panel comparison
Combine with hchart / vchart to compare across conditions with
independent axes per panel. This is useful when different splits or datasets
have very different value ranges:
from plotutils.concat import hchart
chart = hchart(
column="split",
row="group",
df=df,
func=plot_predictions_errors,
color_col="model",
shape_col="model",
)
See the Concatenation page for full examples.
Reference
plotutils.uncertainty.plot_predictions_errors(df, true_col='true', pred_col='pred', title='', width=600, height=600, x_title=None, y_title=None, point_color='steelblue', color_col=None, shape_col=None, identity_line_color='gray', point_size=60, point_opacity=0.7)
Create a prediction-vs-truth scatter plot with a y = x identity line.
Each point represents one observation. The x-axis shows the true (ground-truth) value and the y-axis shows the predicted value. Both axes share the same scale domain so the identity line is a true diagonal. Points on the identity line represent perfect predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Polars DataFrame with at least true_col and pred_col columns. |
required |
true_col
|
str
|
Column for true (ground-truth) values (x-axis). |
'true'
|
pred_col
|
str
|
Column for predicted values (y-axis). |
'pred'
|
title
|
str
|
Plot title. |
''
|
width
|
int
|
Chart dimensions. Default 600x600 (square) to reinforce equal axis scaling. |
600
|
height
|
int
|
Chart dimensions. Default 600x600 (square) to reinforce equal axis scaling. |
600
|
x_title
|
str or None
|
Axis titles (defaults to column names). |
None
|
y_title
|
str or None
|
Axis titles (defaults to column names). |
None
|
point_color
|
str
|
Fixed color for all points. Ignored when color_col is set. |
'steelblue'
|
color_col
|
str or None
|
Column mapped to point color (nominal). When set, point_color is ignored and Altair picks a categorical palette automatically. |
None
|
shape_col
|
str or None
|
Column mapped to point shape (nominal). When set, each unique value gets a distinct marker shape. |
None
|
identity_line_color
|
str
|
Color of the y = x dashed identity line. |
'gray'
|
point_size
|
int
|
Size (area) of the scatter points. |
60
|
point_opacity
|
float
|
Opacity of the scatter points (0.0 -- 1.0). |
0.7
|
Returns:
| Type | Description |
|---|---|
LayerChart
|
Altair layered chart with scatter points and identity line. |
Source code in src/plotutils/uncertainty.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |