ferrum¶
Top-level public surface of the ferrum package.
Ferrum — a statistical visualization library with a Rust core.
Theme ¶
Immutable theme value class for chart styling.
Pass to Chart.theme(t) per-chart or activate process-wide via
set_default_theme(t). Per-chart .theme() always wins at render
time.
All keys listed in ferrum-spec.md §3.13 are plumbed end-to-end to
the Rust renderer. Unknown keys raise ValueError at construction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
background
|
str
|
Chart background color as a CSS hex string (e.g. |
required |
mark_color
|
str
|
Default mark fill/stroke color for marks that have no explicit color encoding. |
required |
font_family
|
optional
|
Default text styling for body text (axis titles, etc.). |
required |
font_weight
|
optional
|
Default text styling for body text (axis titles, etc.). |
required |
font_color
|
optional
|
Default text styling for body text (axis titles, etc.). |
required |
font_size
|
optional
|
Default text styling for body text (axis titles, etc.). |
required |
title_font_family
|
optional
|
Chart title styling. |
required |
title_font_size
|
optional
|
Chart title styling. |
required |
title_font_weight
|
optional
|
Chart title styling. |
required |
title_color
|
optional
|
Chart title styling. |
required |
title_anchor
|
optional
|
Chart title styling. |
required |
title_offset
|
optional
|
Chart title styling. |
required |
label_font_family
|
optional
|
Tick label styling. Fall back to |
required |
label_color
|
optional
|
Tick label styling. Fall back to |
required |
grid
|
bool
|
Whether to draw grid lines (default True). |
required |
grid_color
|
optional
|
Grid line styling. |
required |
grid_width
|
optional
|
Grid line styling. |
required |
grid_dash
|
optional
|
Grid line styling. |
required |
grid_opacity
|
optional
|
Grid line styling. |
required |
axis_line
|
bool
|
Whether to draw axis strokes (default True). |
required |
axis_line_color
|
optional
|
Axis and tick styling. |
required |
axis_line_width
|
optional
|
Axis and tick styling. |
required |
tick_color
|
optional
|
Axis and tick styling. |
required |
tick_size
|
optional
|
Axis and tick styling. |
required |
tick_width
|
optional
|
Axis and tick styling. |
required |
point_size
|
optional
|
Mark styling. |
required |
point_opacity
|
optional
|
Mark styling. |
required |
line_stroke_width
|
optional
|
Mark styling. |
required |
bar_corner_radius
|
optional
|
Mark styling. |
required |
area_opacity
|
optional
|
Mark styling. |
required |
opacity
|
optional
|
Mark styling. |
required |
color_scheme
|
str
|
Named categorical palette: one of |
required |
sequential_scheme
|
str
|
Default sequential color ramp used by heatmaps, density plots, and
other continuous-color charts when no explicit |
required |
diverging_scheme
|
str
|
Default diverging color ramp used by correlation matrices and other
diverging-color charts when no explicit |
required |
legend_orient
|
optional
|
Legend layout. |
required |
legend_direction
|
optional
|
Legend layout. |
required |
legend_title_font_size
|
optional
|
Legend layout. |
required |
padding
|
optional
|
Spacing in pixels. |
required |
axis_title_padding
|
optional
|
Spacing in pixels. |
required |
column_padding
|
optional
|
Spacing in pixels. |
required |
row_padding
|
optional
|
Spacing in pixels. |
required |
strip_background_color
|
optional
|
Facet strip-title background color. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any keyword argument is not in the supported key list (see
|
Examples:
>>> import ferrum as fm
>>> t = fm.Theme(background="#f9f9f9", grid=False, padding=16)
>>> t2 = t.update(mark_color="#e74c3c")
>>> t2
Theme(background='#f9f9f9', grid=False, mark_color='#e74c3c', padding=16)
update ¶
Return a new Theme with the given properties overridden.
Passing None for a key removes that property from the derived
theme. The source theme is unchanged (immutable).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
any
|
Property overrides. Pass |
{}
|
Returns:
| Type | Description |
|---|---|
Theme
|
A new |
Examples:
to_spec_dict ¶
Return a dict suitable for ferrum._core.render_svg(theme=...).
Resolves spec-defined fallbacks (e.g. title_color falls back to
font_color if unset) and normalises the public Python alias
background to the Rust binding's canonical background_color
key. Rust sees a fully-resolved dict; no Option fallback chains in
the binding.
Chart ¶
Bases: _RenderMixin
Top-level chart value class.
Every method returns a new Chart — the object is effectively immutable and
safe to reuse across branches of a pipeline. The fluent API follows the pattern::
fm.Chart(df).mark_point().encode(x="sepal_length", y="sepal_width")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame - like or None
|
Input data. Accepts Polars |
None
|
width
|
int or 'container'
|
Chart width in pixels, or |
None
|
height
|
int or 'container'
|
Chart height in pixels. Default is |
None
|
title
|
str
|
Title rendered above the plot area. |
None
|
description
|
str
|
Accessible description attached to the SVG root ( |
None
|
Examples:
>>> import ferrum as fm
>>> import polars as pl
>>> df = pl.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})
>>> chart = fm.Chart(df).mark_point().encode(x="x", y="y")
>>> svg = chart.show_svg()
layer_names
property
¶
Named sub-layers after composite-mark desugar resolution.
Returns [] for single-mark charts with no layers. Accessing
this property forces resolution of any pending _PendingMark.
show_svg ¶
Render the chart to an SVG string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster
|
bool or None
|
Override the auto-raster policy for this render only.
|
None
|
Returns:
| Type | Description |
|---|---|
str
|
SVG markup for the chart. |
Examples:
show_png ¶
Render the chart to PNG bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster
|
bool or None
|
Override the auto-raster policy for this render only.
|
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
PNG-encoded image data. |
Examples:
save ¶
Save the chart to a file on disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Destination file path. Extension determines the default format:
|
required |
format
|
('svg', 'png', 'html', 'json')
|
Explicit format override. |
"svg"
|
embed_wasm
|
bool
|
For |
True
|
raster
|
bool or None
|
Override the auto-raster policy for this save only.
|
None
|
Examples:
show ¶
Display the chart inline or in a browser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster
|
bool or None
|
Override the auto-raster policy for this render only.
|
None
|
Examples:
mark_point ¶
Render data as points (scatter plot).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
float
|
Point area in square pixels. Default is |
required |
fill
|
str
|
Fill colour override (CSS colour string or hex). Normally driven
by the |
required |
stroke
|
str
|
Stroke colour for the point outline. |
required |
opacity
|
float
|
Overall opacity in |
required |
filled
|
bool
|
Whether points are filled. Default is |
required |
shape
|
str
|
Point shape: |
required |
stroke_width
|
float
|
Stroke width in pixels. |
required |
position
|
Position
|
Position adjustment — |
required |
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_line ¶
Render data as a connected line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stroke
|
str
|
Stroke colour override. |
required |
stroke_width
|
float
|
Line width in pixels. Default is |
required |
opacity
|
float
|
Overall opacity in |
required |
interpolate
|
str
|
Line interpolation: |
required |
stroke_cap
|
str
|
Line cap: |
required |
stroke_join
|
str
|
Line join: |
required |
position
|
Position
|
Position adjustment. |
required |
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_bar ¶
Render data as bars.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fill
|
str
|
Bar fill colour override. |
required |
stroke
|
str
|
Bar stroke colour. |
required |
stroke_width
|
float
|
Bar stroke width in pixels. |
required |
opacity
|
float
|
Overall opacity in |
required |
corner_radius
|
float
|
Rounded corner radius in pixels. |
required |
orient
|
str
|
|
required |
position
|
Position
|
Position adjustment — |
required |
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_area ¶
Render data as a filled area between the line and a baseline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fill
|
str
|
Fill colour override. |
required |
stroke
|
str
|
Border stroke colour. |
required |
stroke_width
|
float
|
Border stroke width in pixels. |
required |
opacity
|
float
|
Overall opacity in |
required |
interpolate
|
str
|
Area boundary interpolation: |
required |
line
|
bool
|
Whether to draw the top boundary as a line. Default is |
required |
position
|
Position
|
Position adjustment — e.g. |
required |
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_rule ¶
Render a horizontal or vertical reference rule spanning the plot area.
A rule spans the full width (when y is encoded) or full height
(when x is encoded). Encoding both x/x2 or y/y2
draws finite line segments instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stroke
|
str
|
Rule colour override. |
required |
stroke_width
|
float
|
Rule width in pixels. Default is |
required |
stroke_dash
|
str or list
|
Dash pattern, e.g. |
required |
opacity
|
float
|
Overall opacity in |
required |
position
|
Position
|
Position adjustment. |
required |
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_text ¶
Render data values as text labels.
Requires a text encoding channel pointing at the column to display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fill
|
str
|
Text colour override. |
required |
font_size
|
float
|
Font size in points. Default is |
required |
font_weight
|
str or int
|
CSS font-weight, e.g. |
required |
align
|
str
|
Horizontal alignment: |
required |
baseline
|
str
|
Vertical alignment: |
required |
dx
|
float
|
Horizontal pixel offset from the anchor point. |
required |
dy
|
float
|
Vertical pixel offset from the anchor point. |
required |
angle
|
float
|
Rotation in degrees. |
required |
limit
|
float
|
Maximum rendered width in pixels; clips overflow. |
required |
position
|
Position
|
Position adjustment. |
required |
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_tick ¶
Render data as short tick marks (rug / strip plot).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stroke
|
str
|
Tick colour override. |
required |
stroke_width
|
float
|
Tick stroke width in pixels. |
required |
opacity
|
float
|
Overall opacity in |
required |
band_size
|
float
|
Tick length in pixels. |
required |
orient
|
str
|
|
required |
position
|
Position
|
Position adjustment. |
required |
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_rect ¶
Render data as rectangles (heatmap cells, Gantt bars).
Requires x/x2 or y/y2 encoding pairs (or ordinal
x/y for a heatmap cell grid).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fill
|
str
|
Rectangle fill colour override. |
required |
stroke
|
str
|
Rectangle border stroke colour. |
required |
stroke_width
|
float
|
Border stroke width in pixels. |
required |
opacity
|
float
|
Overall opacity in |
required |
corner_radius
|
float
|
Rounded corner radius in pixels. |
required |
position
|
Position
|
Position adjustment. |
required |
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_segment ¶
Render data as line segments from (x, y) to (x2, y2).
Distinct from mark_rule (axis-aligned only); segments may take any
direction. Requires x, y, x2, y2 on the encoding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stroke
|
str
|
Segment stroke colour override. |
required |
stroke_width
|
float
|
Segment stroke width in pixels. |
required |
stroke_dash
|
list of float
|
Dash pattern (alternating on/off pixel lengths). |
required |
opacity
|
float
|
Stroke opacity in |
required |
position
|
Position
|
Position adjustment. |
None
|
**kwargs
|
Additional mark-style overrides forwarded to the segment layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_density ¶
Render a kernel-density estimate (KDE) curve or filled contour.
When only x is encoded, draws a 1-D KDE area curve. When both
x and y are encoded, renders a bivariate filled-contour density
(routes through desugar_contour(fill=True)). Can be called before
or after .encode().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bandwidth
|
float or 'scott' or 'silverman'
|
KDE bandwidth. |
required |
kernel
|
str
|
Kernel type: |
required |
extent
|
list of float or None
|
|
required |
cumulative
|
bool
|
Produce a CDF instead of a PDF. Default is |
required |
n
|
int
|
Number of evaluation points. Default is |
required |
multiple
|
str
|
How to handle multiple densities when a |
required |
position
|
Position
|
Position adjustment. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_histogram ¶
Render data as a histogram.
Bins the x-encoded column and encodes bin extents as x/x2
with counts (or densities) on y. Can be called before or after
.encode(x=...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin_count
|
int
|
Target number of bins. Ignored when |
required |
bin_width
|
float
|
Exact bin width in data units. Overrides |
required |
density
|
bool
|
Normalise counts to a probability density. Default is |
required |
right
|
bool
|
Whether bins are closed on the right. Default is |
required |
cumulative
|
bool
|
Render a cumulative histogram. Default is |
required |
multiple
|
str
|
How to handle grouped histograms when a |
required |
position
|
Position
|
Position adjustment. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_smooth ¶
Render a smoothed regression line with optional confidence interval band.
Fits a smooth curve through (x, y) data using the method specified by
method. When ci is set, emits a layered ribbon (CI band) + line
chart. Can be called before or after .encode(x=..., y=...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
Smoothing method: |
required |
degree
|
int
|
Polynomial degree for |
required |
bandwidth
|
float
|
LOESS bandwidth fraction in |
required |
n
|
int
|
Number of evaluation points along the x range. Default is |
required |
ci
|
float or None
|
Confidence level for the interval band, e.g. |
required |
groupby
|
str
|
Group-key column (Utf8). When set, the smooth is computed
independently per group and the group column is preserved in
the output so downstream |
required |
position
|
Position
|
Position adjustment. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_boxplot ¶
mark_boxplot(*, extent=1.5, size=None, width=None, outliers=True, color_field=None, horizontal=False, position=None, **mark_kwargs) -> 'Chart'
Render a Tukey boxplot via composite mark desugaring.
Desugars to a multi-layer chart: box (IQR rect), upper and lower
whisker rules, median rule, and (optionally) outlier points. Requires
a categorical x encoding and a continuous y (or the reverse
when horizontal=True).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extent
|
float
|
Whisker reach as a multiple of IQR. Default is |
1.5
|
size
|
float or None
|
Box band-width as a fraction of the category band (default |
None
|
width
|
float or None
|
Alias for |
None
|
outliers
|
bool
|
Whether to draw outlier points beyond the whiskers. Default is
|
True
|
color_field
|
str or None
|
Column name to drive per-group fill colour on the box layer. |
None
|
horizontal
|
bool
|
Swap x and y axes so boxes run horizontally. Default is |
False
|
position
|
Position
|
Position adjustment — e.g. |
None
|
**mark_kwargs
|
Additional mark-style overrides forwarded to each constituent layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_boxen ¶
mark_boxen(*, k_depth: str = 'tukey', k_proportion: float = 0.007, outlier_threshold: float = 1.5, palette=None, horizontal: bool = False, color_field=None, position=None, **mark_kwargs) -> 'Chart'
Render a letter-value (boxen) plot via composite mark desugaring.
Produces nested rectangular bands for each letter-value depth, a median
rule, and an outlier-point layer via the LetterValue transform.
Requires a categorical x encoding and a continuous y (or the
reverse when horizontal=True).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k_depth
|
('proportion', 'trustworthy', 'full')
|
Rule for choosing the number of letter-value levels. |
"proportion"
|
k_proportion
|
float
|
Proportion parameter used when |
0.007
|
outlier_threshold
|
float
|
IQR multiple beyond which points are considered outliers. Default
is |
1.5
|
palette
|
list of str or None
|
Colour palette applied to successive depth bands. |
None
|
horizontal
|
bool
|
Swap axes so bands run horizontally. Default is |
False
|
color_field
|
str or None
|
Column name to drive per-group colour. |
None
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Additional mark-style overrides forwarded to constituent layers. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_errorbar ¶
Render error bars via the ErrorExtent transform.
Computes extent values (CI, SD, SEM, or IQR) per group defined by the
x encoding, then draws a vertical rule spanning the extent with
optional tick caps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extent
|
('ci', 'stderr', 'stdev', 'iqr')
|
Extent measure: confidence interval ( |
"ci"
|
ticks
|
bool
|
Whether to draw horizontal tick caps at the extent endpoints.
Default is |
True
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides forwarded to constituent rule/tick layers. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_errorband ¶
Render an error band (ribbon) via the ErrorExtent transform.
Similar to mark_errorbar but renders the extent as a filled ribbon
rather than whisker rules. Optionally draws border lines at the upper
and lower extent edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extent
|
('ci', 'stderr', 'stdev', 'iqr')
|
Extent measure: confidence interval ( |
"ci"
|
borders
|
bool
|
Whether to draw line borders at the band edges. Default is |
False
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides (e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_ribbon ¶
Render a ribbon (filled area between y and y2 along x).
Requires both y and y2 encoding channels. Typically used to
visualise confidence intervals alongside a mark_line in the same
layered chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
opacity
|
float
|
Fill opacity of the ribbon. Default is |
0.3
|
interpolate
|
str
|
Boundary interpolation: |
'linear'
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Additional mark-style overrides (e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_contour ¶
mark_contour(*, bandwidth='scott', thresholds=6, smooth=True, fill=False, cmap=None, position=None, **mark_kwargs) -> 'Chart'
Render a bivariate contour plot via Kde2D + Contour transforms.
Estimates a 2-D kernel density and draws iso-contour lines (or filled
contour regions when fill=True). Requires both x and y
encodings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bandwidth
|
float or 'scott' or 'silverman'
|
Bandwidth for the 2-D KDE. Default is |
'scott'
|
thresholds
|
int or list of float
|
Number of evenly-spaced contour levels, or an explicit list of
density thresholds. Default is |
6
|
smooth
|
bool
|
Whether to smooth contour paths via Gaussian filtering before
contouring. Default is |
True
|
fill
|
bool
|
Render filled contour regions instead of contour lines. Default is
|
False
|
cmap
|
str or None
|
Colour map name applied to contour levels. |
None
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides forwarded to the polygon/path layers. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_violin ¶
Render violin plots via the Violin transform.
Estimates a mirrored KDE per group and overlays an optional inner
summary (box, quartile lines, or individual points). Requires a
categorical x and continuous y encoding (or swapped when
horizontal is set).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bandwidth
|
float or 'scott' or 'silverman'
|
KDE bandwidth. Default is |
'scott'
|
inner
|
('box', 'quartile', 'point', 'none')
|
Inner mark drawn on top of each violin:
|
"box"
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides forwarded to the violin polygon layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_qq ¶
mark_qq(*, distribution='normal', dequantize=False, line=True, position=None, **mark_kwargs) -> 'Chart'
Render a quantile-quantile plot.
Computes theoretical vs. sample quantiles via the QQ transform.
Reads the sample column from the x encoding; y is ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distribution
|
('normal', 'uniform', 'exponential', 'lognormal')
|
Theoretical distribution to compare the sample against. |
"normal"
|
dequantize
|
bool
|
Whether to apply rank-based dequantization before comparison.
Default is |
False
|
line
|
bool
|
Whether to overlay a 45-degree reference line. Default is |
True
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the scatter layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_raster ¶
mark_raster(*, aggregate='count', field=None, cmap=None, resolution='screen', blend='alpha', min_count=None, log_scale=False, position=None, **mark_kwargs) -> 'Chart'
Render a 2-D raster (pixel heatmap) via the Raster transform.
Bins data into a pixel grid and colours each pixel by an aggregate
statistic. Most useful for very large datasets where a scatter plot
would overplot. Requires x and y encodings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aggregate
|
str
|
Aggregate function applied to each pixel bin: |
'count'
|
field
|
str or None
|
Column name to aggregate. Required unless |
None
|
cmap
|
str or None
|
Colour map name. |
None
|
resolution
|
'screen' or int
|
Pixel grid resolution. |
'screen'
|
blend
|
str
|
Alpha-compositing blend mode. Default is |
'alpha'
|
min_count
|
int or None
|
Minimum count threshold; pixels below this are rendered transparent.
|
None
|
log_scale
|
bool
|
Apply a log transform to pixel values before colour mapping.
Default is |
False
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides forwarded to the image layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_hex ¶
mark_hex(*, bin_size=None, aggregate='count', field=None, cmap=None, stroke=None, stroke_width=0, position=None, **mark_kwargs) -> 'Chart'
Render a hexagonal bin plot via the Hex transform.
Bins data into a regular hexagonal grid and colours each cell by an
aggregate statistic. Requires x and y encodings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin_size
|
float or None
|
Hexagon radius in data units. |
None
|
aggregate
|
str
|
Aggregate function: |
'count'
|
field
|
str or None
|
Column to aggregate. Required unless |
None
|
cmap
|
str or None
|
Colour map name. |
None
|
stroke
|
str or None
|
Hex border colour. |
None
|
stroke_width
|
float
|
Hex border width in pixels. Default is |
0
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides forwarded to the polygon layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_swarm ¶
mark_swarm(*, size=4, orient='vertical', spacing=1.0, side='both', dodge=None, position=None, **mark_kwargs) -> 'Chart'
Render a beeswarm (strip swarm) plot via the Swarm transform.
Computes non-overlapping point positions along the categorical axis
using a deterministic placement algorithm seeded for reproducibility.
Requires a continuous y (or x) and an optional categorical
grouping axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
float
|
Point diameter in pixels. Default is |
4
|
orient
|
('vertical', 'horizontal')
|
Orientation of the swarm axis. |
"vertical"
|
spacing
|
float
|
Minimum spacing between point centres as a fraction of |
1.0
|
side
|
('both', 'left', 'right')
|
Side of the axis on which points can be placed. |
"both"
|
dodge
|
str or None
|
Column name to use as a secondary grouping variable for dodging.
|
None
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides forwarded to the point layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_function ¶
Render a mathematical function as a line.
Evaluates fn(xs) on n evenly-spaced x values in the
specified domain and renders the result as a line. The input data on
the chart is replaced with the synthetic dataset; use + composition
to overlay a function on a scatter chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
callable
|
A function accepting a 1-D NumPy array of x values and returning a 1-D array of y values. |
required |
domain
|
list of float or None
|
|
None
|
n
|
int
|
Number of evaluation points. Default is |
200
|
clip
|
bool
|
Whether to clip rendered line to the plot viewport. Default is
|
True
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides forwarded to the line layer (e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Examples:
mark_residuals ¶
mark_residuals(*, kind: str = 'studentized', reference_line: bool = True, cook_threshold: float | str | None = None, color_field: str | None = None, position=None, **mark_kwargs) -> 'Chart'
Render a residuals diagnostic plot.
Plots fitted values (y_pred) on x against residuals (raw or
studentized) on y. Data must carry the schema emitted by
ModelSource.predictions(): y_true, y_pred, residual,
studentized_residual, and cooks_distance.
When reference_line=True a sentinel _ref_zero column is
injected so the downstream mark_rule draws a single horizontal line
at y=0.
When cook_threshold is set, high-leverage points (Cook's D above
the threshold) are highlighted as a second mark_point layer drawn
in red with a black outline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
('studentized', 'raw')
|
Residual type to plot on the y axis. |
"studentized"
|
reference_line
|
bool
|
Whether to draw a horizontal reference line at y=0. Default is
|
True
|
cook_threshold
|
float, "auto", or None
|
Cook's Distance threshold for outlier highlighting. |
None
|
color_field
|
str or None
|
Column name to drive per-group colour on the scatter layer. |
None
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the scatter layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_prediction_error ¶
mark_prediction_error(*, reference_line: bool = True, ci: float | None = None, reference_band: bool = False, color_field: str | None = None, position=None, **mark_kwargs) -> 'Chart'
Render an actual-vs-predicted plot.
Plots y_true on x against y_pred on y as scatter points.
When reference_line=True the data is pre-sorted ascending by
y_true so the downstream mark_line renders a monotonic y=x
diagonal. Data must carry y_true and y_pred columns (schema
from ModelSource.predictions()).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference_line
|
bool
|
Whether to overlay a y=x identity reference line. Default is
|
True
|
ci
|
float or None
|
Confidence level for a prediction-interval band (e.g. |
None
|
reference_band
|
bool
|
Whether to draw a shaded reference band around the identity line.
Default is |
False
|
color_field
|
str or None
|
Column name to drive per-group colour. |
None
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the scatter layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_roc ¶
mark_roc(*, average: str | None = None, reference_line: bool = True, annotate_auc: bool = False, color_field: str | None = 'class', position=None, **mark_kwargs) -> 'Chart'
Render a Receiver Operating Characteristic (ROC) curve.
Plots false-positive rate (fpr) on x against true-positive rate
(tpr) on y as a line per class. Data must carry the schema emitted
by ModelSource.roc_curve(): fpr, tpr, threshold,
class, auc. When reference_line=True the data is
pre-sorted ascending by fpr before rendering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
average
|
str or None
|
When the data contains a macro/micro average row with
|
None
|
reference_line
|
bool
|
Whether to overlay a diagonal chance-level reference line
(TPR=FPR). Default is |
True
|
annotate_auc
|
bool
|
Whether to annotate each curve with its AUC value. Default is
|
False
|
color_field
|
str or None
|
Column name to drive per-class colour. Default is |
'class'
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the line layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_pr ¶
mark_pr(*, average: str | None = None, annotate_ap: bool = False, iso_lines: bool = False, color_field: str | None = 'class', position=None, **mark_kwargs) -> 'Chart'
Render a Precision-Recall (PR) curve.
Plots recall on x against precision on y as a line per class. Data
must carry the schema emitted by ModelSource.pr_curve():
precision, recall, threshold, class, ap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
average
|
str or None
|
Filter to a specific average type row (e.g. |
None
|
annotate_ap
|
bool
|
Whether to annotate each curve with its average-precision (AP)
value. Default is |
False
|
iso_lines
|
bool
|
Whether to draw iso-F1 reference lines in the background.
Default is |
False
|
color_field
|
str or None
|
Column name to drive per-class colour. Default is |
'class'
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the line layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_calibration ¶
mark_calibration(*, n_bins: int = 10, strategy: str = 'uniform', reference_line: bool = True, color_field: str | None = None, position=None, **mark_kwargs) -> 'Chart'
Render a calibration (reliability) curve.
Plots mean predicted probability on x against fraction of positive
outcomes (empirical probability) on y. A perfectly calibrated model
lies on the diagonal. Data must carry the schema emitted by
ModelSource.calibration_curve(): mean_predicted,
fraction_positive, count.
When reference_line=True the data is pre-sorted ascending by
mean_predicted before rendering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_bins
|
int
|
Number of calibration bins. Default is |
10
|
strategy
|
('uniform', 'quantile')
|
Binning strategy. |
"uniform"
|
reference_line
|
bool
|
Whether to overlay a perfect-calibration diagonal reference line.
Default is |
True
|
color_field
|
str or None
|
Column name to drive per-group colour. |
None
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the line layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_gain ¶
mark_gain(*, reference_line: bool = True, color_field: str | None = 'class', position=None, **mark_kwargs) -> 'Chart'
Render a cumulative gain chart.
Plots percent of population contacted on x against the cumulative gain
(fraction of positive cases captured) on y. Data must carry the schema
emitted by ModelSource.cumulative_gain(): percent_population,
gain, class. The no-skill diagonal baseline is encoded as rows
with class='baseline'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference_line
|
bool
|
Whether to draw the no-skill baseline diagonal. Default is
|
True
|
color_field
|
str or None
|
Column name to drive per-class colour. Default is |
'class'
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the line layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_lift ¶
mark_lift(*, reference_line: bool = True, color_field: str | None = 'class', position=None, **mark_kwargs) -> 'Chart'
Render a lift curve chart.
Plots percent of population targeted on x against lift (ratio of
positive-case density to baseline) on y. Data must carry the schema
emitted by ModelSource.lift_curve(): percent_population,
lift, class. The no-skill lift=1 baseline is encoded as rows
with class='baseline'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference_line
|
bool
|
Whether to draw the lift=1 baseline rule. Default is |
True
|
color_field
|
str or None
|
Column name to drive per-class colour. Default is |
'class'
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the line layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_discrimination_threshold ¶
mark_discrimination_threshold(*, metrics: tuple[str, ...] = ('precision', 'recall', 'f1', 'queue_rate'), n_thresholds: int = 50, threshold_line: bool = False, optimum_label: bool = True, position=None, **mark_kwargs) -> 'Chart'
Render a discrimination-threshold sweep plot.
Sweeps the decision threshold from 0 to 1 and plots multiple metrics
(precision, recall, F1, queue rate) as lines against the threshold
value. Data must be in long form with columns threshold, metric,
value — the figure builder handles unpivoting from
ModelSource.discrimination_threshold() output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
tuple of str
|
Metric names to include. Default is
|
('precision', 'recall', 'f1', 'queue_rate')
|
n_thresholds
|
int
|
Number of evenly-spaced threshold steps to evaluate. Default is
|
50
|
threshold_line
|
bool
|
Whether to draw a vertical rule at the optimal threshold. Default
is |
False
|
optimum_label
|
bool
|
Whether to overlay a text annotation at the F1-optimum point
showing |
True
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the line layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_confusion ¶
mark_confusion(*, normalize: str | None = None, annotate: bool = True, color_field: str = 'value', cmap: str | None = None, position=None, **mark_kwargs) -> 'Chart'
Render a confusion matrix as an annotated heatmap.
Renders an ordinal heatmap with actual class on one axis and predicted
class on the other. Data must carry the long-form schema emitted by
ModelSource.confusion_matrix(): actual, predicted,
value, value_fmt. When annotate=True, a second
mark_text layer reads value_fmt for per-cell text labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normalize
|
('true', 'pred', 'all')
|
Normalise cell counts. |
"true"
|
annotate
|
bool
|
Whether to overlay per-cell count / percentage text. Default is
|
True
|
color_field
|
str
|
Column name driving the heatmap colour scale. Default is
|
'value'
|
cmap
|
str or None
|
Sequential colormap name for the heat cells. |
None
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the rect layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_class_prediction_error ¶
mark_class_prediction_error(*, normalize: bool = False, color_field: str = 'predicted', show_counts: bool = True, position=None, **mark_kwargs) -> 'Chart'
Render a class prediction error bar chart.
Renders one stacked bar per actual class (x-axis), with segments
coloured by predicted class. This orientation surfaces which classes
are confused with which — for each actual class you can see how the
model's predictions distribute across the predicted classes. Data must
carry long-form columns (actual, predicted, value) — same shape as
ModelSource.confusion_matrix(normalize=None).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normalize
|
bool
|
Whether to normalise each bar to 100%. Default is |
False
|
color_field
|
str
|
Column driving the segment colour. Default is |
'predicted'
|
show_counts
|
bool
|
Whether to overlay per-segment count text at the segment
centre. Default is |
True
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the bar layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_importance ¶
mark_importance(*, orient: str = 'horizontal', error_bars: bool = True, top_k: int | None = None, color_field: str | None = None, position=None, **mark_kwargs) -> 'Chart'
Render a feature-importance bar chart.
Renders one bar per feature, sorted descending by importance. When
error_bars=True and the data carries imp_lower/imp_upper
columns a second errorbar layer is added. Data must carry the schema
emitted by ModelSource.importances(): feature, importance,
std. The chart builder computes the bound columns and truncates to
top_k rows before calling this method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orient
|
('horizontal', 'vertical')
|
Bar orientation. |
"horizontal"
|
error_bars
|
bool
|
Whether to draw error bars from |
True
|
top_k
|
int or None
|
Limit results to the top-k features by importance. Truncation
is applied by the figure-level chart builder
( |
None
|
color_field
|
str or None
|
Column name to drive per-feature colour. |
None
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the bar layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_shap_beeswarm ¶
mark_shap_beeswarm(*, max_display: int = 20, color_bar: bool = True, order: str = 'abs_mean', zero_line: bool = True, position=None, **mark_kwargs) -> 'Chart'
Render a SHAP beeswarm summary plot.
Visualises the distribution of SHAP values across samples for each
feature as a swarm of points, coloured by the feature's original value.
Data must carry the long-form schema from ModelSource.shap_values()
pre-filtered to the top max_display features by the chart builder.
When zero_line=True (default) a sentinel _ref_zero column is
injected and the downstream desugar appends a dashed mark_rule
layer at x=0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_display
|
int
|
Maximum number of top features to show. Default is |
20
|
color_bar
|
bool
|
Whether to render a colour bar for the feature-value scale.
Default is |
True
|
order
|
('abs_mean', 'mean', 'none')
|
Feature ordering: by mean absolute SHAP ( |
"abs_mean"
|
zero_line
|
bool
|
Whether to overlay a dashed vertical reference rule at
|
True
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the point layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_shap_bar ¶
Render a SHAP aggregated-bar feature importance chart.
Shows mean absolute SHAP values per feature as a horizontal bar chart.
Data must carry the long-form schema from ModelSource.shap_values()
pre-filtered to the top max_display features by the chart builder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_display
|
int
|
Maximum number of top features to show. Default is |
20
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the bar layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_pdp ¶
mark_pdp(*, kind: str = 'average', ice_alpha: float = 0.2, center: bool = False, color_field: str | None = 'feature', position=None, **mark_kwargs) -> 'Chart'
Render partial-dependence plots (PDP / ICE).
Visualises how the model's output varies as a function of one feature
while marginalising over all others. Data must carry the long-form
schema from ModelSource.partial_dependence(): feature,
feature_value, pd_value. The chart builder pre-sorts ascending
by feature_value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
('average', 'individual', 'both')
|
What to render. |
"average"
|
ice_alpha
|
float
|
Opacity of individual ICE lines when |
0.2
|
center
|
bool
|
Whether to centre ICE lines at their first value (centred ICE).
Default is |
False
|
color_field
|
str or None
|
Column name driving per-feature colour. Default is |
'feature'
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the line layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_shap_waterfall ¶
mark_shap_waterfall(*, sample_idx: int = -1, max_display: int = 20, position=None, **mark_kwargs) -> 'Chart'
Render a SHAP waterfall chart for one sample.
Shows how each feature pushes the model output from the base value
toward the final prediction for a single observation. Data must carry
the long-form schema from ModelSource.shap_values() for the chosen
sample_idx.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_idx
|
int
|
Row index of the sample to explain. Must be provided explicitly;
the default |
-1
|
max_display
|
int
|
Maximum number of features to show (smallest-magnitude features
are collapsed into an |
20
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the bar layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
mark_learning_curve ¶
mark_learning_curve(*, ci_style: str = 'band', color_field: str | None = 'split', position=None, **mark_kwargs) -> 'Chart'
Render a learning curve (train size vs. CV score).
Plots training set size on x against CV score on y, with separate
lines for training and validation splits. Data must carry the schema
emitted by ModelSource.learning_curve(), pre-deduped per
(train_size, split) by the chart builder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ci_style
|
('band', 'bars', 'none')
|
How to display cross-validation variance. |
"band"
|
color_field
|
str or None
|
Column name to drive per-split line colour. Default is
|
'split'
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the line layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_validation_curve ¶
mark_validation_curve(*, log_scale: bool = False, ci_style: str = 'band', color_field: str | None = 'split', param_label: str | None = None, position=None, **mark_kwargs) -> 'Chart'
Render a validation curve (hyperparameter vs. CV score).
Plots a swept hyperparameter value on x against CV score on y, with
separate lines for training and validation splits. Data must carry the
schema emitted by ModelSource.validation_curve(), pre-deduped per
(param_value, split) by the chart builder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_scale
|
bool
|
Whether to use a log scale on the x axis. Useful for parameters
like regularisation strength that span orders of magnitude.
Default is |
False
|
ci_style
|
('band', 'bars', 'none')
|
How to display cross-validation variance. |
"band"
|
color_field
|
str or None
|
Column name to drive per-split line colour. Default is
|
'split'
|
param_label
|
str or None
|
Human-readable x-axis title for the hyperparameter being swept.
The chart builder forwards the user's |
None
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the line layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_cv_scores ¶
Render a per-fold cross-validation score summary.
Shows the distribution of CV scores across folds as a box plot, strip
plot, or bar chart. Data must carry the schema emitted by
ModelSource.cv_scores(). The chart builder pre-aggregates per
split when kind="bar" and passes raw per-fold rows for "box"
or "strip".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
('box', 'strip', 'bar')
|
Summary plot type. |
"box"
|
split
|
('train', 'test', 'both')
|
Which CV split(s) to display. |
"train"
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides forwarded to constituent layers. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_alpha_selection ¶
mark_alpha_selection(*, log_scale: bool = True, highlight_best: bool = True, ci_style: str = 'band', position=None, **mark_kwargs) -> 'Chart'
Render a regularisation-strength (alpha) selection curve.
Sweeps the regularisation parameter alpha and plots CV score as a
function of alpha, with variance bands. When highlight_best=True
a vertical rule is drawn at the alpha that maximises mean_score.
Data must carry the schema emitted by ModelSource.alpha_selection():
alpha, mean_score, score_lo, score_hi, split.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_scale
|
bool
|
Whether to use a log scale on the x axis. Default is |
True
|
highlight_best
|
bool
|
Whether to draw a vertical reference rule at the optimal alpha.
Default is |
True
|
ci_style
|
('band', 'bars', 'none')
|
How to display CV variance. |
"band"
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides forwarded to constituent layers. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_silhouette ¶
mark_silhouette(*, zero_line: bool = True, color_field: str | None = 'cluster', position=None, **mark_kwargs) -> 'Chart'
Render a Rousseeuw silhouette plot.
Displays one horizontal bar per sample whose width encodes its
silhouette coefficient, coloured by cluster assignment. Samples within
each cluster are stacked vertically in descending coefficient order.
Data must carry the schema emitted by ModelSource.silhouette():
sample_id, y_position, cluster, silhouette_value.
When zero_line=True a sentinel _ref_zero column is injected
so the downstream mark_rule renders a single vertical rule at x=0.
The method pre-computes _silhouette_x_lo, _silhouette_x_hi,
_silhouette_y_lo, and _silhouette_y_hi columns from the raw
data so the renderer can draw rect marks directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zero_line
|
bool
|
Whether to draw a vertical reference rule at silhouette = 0.
Default is |
True
|
color_field
|
str or None
|
Column name driving per-cluster colour. Default is |
'cluster'
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the rect layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_pca_scree ¶
mark_pca_scree(*, cumulative_line: bool = True, threshold_line: float | None = None, position=None, **mark_kwargs) -> 'Chart'
Render a PCA scree plot.
Displays explained variance ratio per component as bars and optionally
overlays the cumulative variance ratio as a line. Data must carry the
schema emitted by ModelSource.pca_variance(): component,
explained_variance_ratio, cumulative_variance_ratio.
When threshold_line is non-None a sentinel _threshold_line
column is injected so the downstream mark_rule draws a single
horizontal reference line at the threshold value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cumulative_line
|
bool
|
Whether to overlay a cumulative explained variance line. Default
is |
True
|
threshold_line
|
float or None
|
Y-position of an optional horizontal threshold reference line
(e.g. |
None
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the bar layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_intercluster_distance ¶
mark_intercluster_distance(*, label_clusters: bool = True, color_field: str | None = 'cluster', position=None, **mark_kwargs) -> 'Chart'
Render a 2-D intercluster distance (MDS) plot.
Embeds cluster centres into 2-D using MDS and visualises each centre
as a point whose area encodes cluster size. With label_clusters=True
a mark_text overlay labels each point by its cluster id. Data must
carry the schema emitted by ModelSource.intercluster_distance():
cluster, x, y, size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label_clusters
|
bool
|
Whether to overlay cluster-id text labels. Default is |
True
|
color_field
|
str or None
|
Column name driving per-cluster colour. Default is |
'cluster'
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the point layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_decision_boundary ¶
mark_decision_boundary(*, proba: bool = False, color_field: str = 'z', position=None, **mark_kwargs) -> 'Chart'
Render a decision-boundary heatmap.
Colours a pixel grid by the model's predicted class (proba=False)
or class probability (proba=True) at each grid point. Data must
carry pre-computed cell bound columns x, x2, y, y2
and a prediction column z. The chart builder helper
_decision_boundary_chart_from_source produces these columns from a
ModelSource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proba
|
bool
|
Whether to colour by predicted probability rather than class index.
Default is |
False
|
color_field
|
str
|
Column name for the colour encoding. Default is |
'z'
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the rect layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_rank1d ¶
mark_rank1d(*, orient: str = 'horizontal', color_field: str | None = None, position=None, **mark_kwargs) -> 'Chart'
Render a univariate feature-ranking bar chart.
Ranks features by a univariate score (e.g. mutual information, ANOVA
F-statistic) and displays them as a bar chart sorted by rank. Data must
carry the schema emitted by ModelSource.rank1d(): feature,
score, rank.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orient
|
('horizontal', 'vertical')
|
Bar orientation. |
"horizontal"
|
color_field
|
str or None
|
Column name driving per-feature colour. |
None
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the bar layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_rank2d ¶
mark_rank2d(*, annot: bool = True, color_field: str = 'correlation', text_field: str = 'correlation_fmt', cmap: str | None = None, position=None, **mark_kwargs) -> 'Chart'
Render a pairwise feature-ranking correlation heatmap.
Displays pairwise feature correlation scores as a colour-coded matrix.
When annot=True a text overlay renders each cell's value to 2 dp.
Data must carry the schema emitted by ModelSource.rank2d():
feature_x, feature_y, correlation. The chart builder
appends a correlation_fmt (Utf8) column when annot=True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annot
|
bool
|
Whether to overlay per-cell correlation value text. Default is
|
True
|
color_field
|
str
|
Column driving the heatmap colour scale. Default is
|
'correlation'
|
text_field
|
str
|
Column read by the text layer. Default is |
'correlation_fmt'
|
cmap
|
str or None
|
Diverging colormap name for correlation cells. |
None
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the rect layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New layered |
Examples:
mark_parallel_coordinates ¶
mark_parallel_coordinates(*, alpha: float = 0.5, color_field: str | None = None, position=None, **mark_kwargs) -> 'Chart'
Render a parallel coordinates plot.
Draws one polyline per sample across normalised feature axes. Data
must carry the long-form schema produced by
_parallel_coords_chart_from_dataframe: feature (Utf8),
value (Float64), sample_id (Utf8), and (optionally) a hue
column passed via color_field. The line layer uses
mark_style.detail = "sample_id" so each sample renders as its own
polyline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
float
|
Line opacity. Default is |
0.5
|
color_field
|
str or None
|
Column name driving per-sample (or per-class) line colour. |
None
|
position
|
Position
|
Position adjustment. |
None
|
**mark_kwargs
|
Mark-style overrides for the line layer. |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
mark_arc ¶
Render data as arcs (pie or donut slices).
Requires Chart.coord(fm.CoordPolar(theta="x")) to be set.
The theta-mapped encoding channel (x by default) determines
each slice's angular sweep proportional to its value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Mark style overrides: |
{}
|
Examples:
mark_image ¶
Render data as raster images.
Each row in the dataset becomes one image tile. Supply a base64-encoded
PNG/JPEG via the url encoding channel. Requires Cartesian coordinates;
returns an empty scene for Polar or Geo coord systems.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Mark style overrides: |
{}
|
Examples:
mark_geoshape ¶
Render geographic shapes from a GeoJSON FeatureCollection.
Pass a GeoJSON FeatureCollection dict to Chart(data) — ferrum
auto-detects the format and splits properties into encoding channels
and geometry into a __geometry__ column. Set the projection via
Chart.coord(fm.CoordGeo(projection="mercator")).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Mark style overrides: |
{}
|
Examples:
mark_label ¶
Render positioned text labels near data points with collision avoidance.
Each row in the dataset becomes one text label. By default the renderer uses a greedy collision-avoidance algorithm: for each label in row order it tries a ranked list of candidate offsets (above, below, right, left, diagonals) and picks the first placement whose estimated bounding box overlaps no previously-placed label. When every candidate overlaps something, the least-bad placement is chosen.
When both dx and dy are supplied explicitly, collision
avoidance is bypassed and those fixed offsets are applied to every
label (manual positioning path).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dx
|
float
|
Fixed horizontal offset in pixels. Must be combined with |
required |
dy
|
float
|
Fixed vertical offset in pixels. Must be combined with |
required |
font_size
|
float
|
Label font size in points (default 11). |
required |
leader_line
|
bool
|
When |
required |
**kwargs
|
Additional mark style overrides ( |
{}
|
Examples:
encode ¶
Set or update encoding channels on this chart.
Each keyword argument maps a channel name to a field shorthand string
(e.g. "species:N") or an explicit channel object (e.g.
fm.X("sepal_length", type="Q")).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
str or X
|
Field mapped to the x position. Shorthand format:
|
required |
y
|
str or Y
|
Field mapped to the y position. |
required |
x2
|
str or X2
|
Secondary x position (band / segment end). |
required |
y2
|
str or Y2
|
Secondary y position. |
required |
color
|
str or Color
|
Field or value driving mark colour. |
required |
fill
|
str or Fill
|
Field or value driving mark fill colour. |
required |
stroke
|
str or Stroke
|
Field or value driving mark stroke colour. |
required |
size
|
str or Size
|
Field or value driving mark size. |
required |
shape
|
str or Shape
|
Field or value driving mark shape. |
required |
opacity
|
str or Opacity
|
Field or value driving mark opacity. |
required |
text
|
str or Text
|
Field rendered as text labels (used with |
required |
detail
|
str or Detail
|
Additional grouping field that does not map to any visual property. |
required |
tooltip
|
str or Tooltip
|
Field shown on hover. |
required |
**channels
|
Any
|
Any other valid channel names ( |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an unknown channel name is passed. |
TypeError
|
If a value is not a string, channel instance, or Repeat placeholder. |
Examples:
layer ¶
Add one or more layer objects to this chart.
Accepts both public Layer instances (user-facing API) and
internal _Layer instances (used by ferrum internals).
When a Layer(data=df, ...) has its own data attribute, that
data is merged with the chart's existing data via diagonal concatenation
(same strategy as the + operator). Each layer's encoding references
only its own columns; null-padded rows in the merged batch are invisible
to mark renderers that skip null values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*layers
|
Layer or _Layer
|
Layer objects to append. Public |
()
|
Returns:
| Type | Description |
|---|---|
Chart
|
This chart with the new layers appended. |
transform ¶
Append one or more data transforms to the chart's pipeline.
Transforms are executed in order by the Rust engine before rendering.
Multiple calls to transform() accumulate — each appends to the
existing pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*transforms
|
One or more transform objects (e.g. |
()
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
facet ¶
facet(field: Optional[str] = None, *, row: Optional[str] = None, col: Optional[str] = None, ncols: Optional[int] = None, nrows: Optional[int] = None) -> 'Chart'
Facet this chart into small multiples by a field.
Two modes are supported:
- Wrap — a single field is wrapped across columns (rows auto).
Pass
field=or equivalentlycol=alone. - Grid — two fields define row × column layout. Pass both
row=andcol=.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name used for wrap-mode faceting. Mutually exclusive with
using both |
None
|
row
|
str
|
Column name for the row dimension (grid mode). When used alone, behaves as wrap mode on the row axis. |
None
|
col
|
str
|
Column name for the column dimension (wrap or grid mode). |
None
|
ncols
|
int or None
|
Maximum number of columns in wrap mode. |
None
|
nrows
|
int or None
|
Maximum number of rows. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither |
Examples:
theme ¶
Attach a Theme to this chart, overriding the process-level default.
Per-chart theme always wins over ferrum.set_default_theme().
Theme objects are immutable value classes — modifying the original
Theme after calling .theme() has no effect on the chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theme
|
Theme
|
A |
required |
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
axis ¶
Suppress (or restore) the chart's x/y axis decorations.
Spec-level axis suppression — when x=False (or y=False), the
corresponding axis line, ticks, tick labels, and axis title are
omitted at layout time. The plot area's pixel rect is unchanged
(gutters reserved for axis decorations are preserved), so this
method is intended for sub-charts whose axes are shared with a
neighbouring chart in a compound view: clustermap dendrograms,
JointChart marginals, RepeatChart off-diagonal panels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
bool
|
|
None
|
y
|
bool
|
|
None
|
show
|
bool
|
Shorthand for |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
Hide both axes (e.g. for a dendrogram panel):
Hide just the x axis (top marginal of a JointChart):
coord ¶
Set the coordinate system for this chart.
Currently only CoordFlip is supported (swaps x and y axes).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coord
|
CoordFlip
|
A coordinate-system object. Pass |
required |
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Examples:
properties ¶
Set chart-level display properties.
Only the keyword arguments that are explicitly provided are updated; unset properties inherit from the existing chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int or 'container' or None
|
Chart width in pixels, or |
None
|
height
|
int or 'container' or None
|
Chart height in pixels. |
None
|
title
|
str or None
|
Chart title rendered above the plot area. |
None
|
description
|
str or None
|
Accessible description attached to the SVG root. |
None
|
render_config
|
RenderConfig or None
|
Rendering policy configuration. Controls auto-raster threshold
and behavior. For one-off overrides prefer the |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
to_spec ¶
Build the Rust ChartSpec for this chart.
Resolves any pending statistical-mark desugar, converts Python encoding
channel objects to EncodingSpec instances, and constructs the
ChartSpec PyO3 object that the Rust renderer consumes.
Returns:
| Type | Description |
|---|---|
ChartSpec
|
The fully-resolved |
Examples:
to_json ¶
Serialise the chart specification to a JSON string.
Calls to_spec() to build the ChartSpec and then serialises it
via the Rust serde_json encoder. When indent is given the
compact JSON is reformatted via json.loads / json.dumps on the
Python side (the Rust encoder always produces compact output).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indent
|
int or None
|
Number of spaces to use for pretty-printing. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
JSON representation of the chart specification. |
Examples:
add_selection ¶
Attach interactive selection(s) to this chart.
Per ferrum-spec.md §3.10 (L736), the SVG/PNG renderer silently
ignores selections — they are intended for the WASM renderer (Phase 11).
This method accepts any number of selection objects and returns a new
Chart unchanged so that user code building selection-aware charts
remains forward-compatible without raising under SVG/PNG rendering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*selections
|
Any number of selection objects (currently ignored). |
()
|
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
interactive ¶
Mark this chart as interactive.
Per ferrum-spec.md §3.10 (L736), interactive features (selections,
pan/zoom, conditional encodings) are silently ignored under SVG/PNG.
Returns a new Chart so chained construction patterns work today
and will gain real interactivity once the Phase 11 WASM renderer ships.
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
conditional ¶
Apply a conditional encoding to this chart.
Convenience sugar: chart.conditional(sel.when(Color("x")).otherwise(value("#ccc")))
is equivalent to::
chart.add_selection(sel).encode(color=sel.when(Color("x")).otherwise(value("#ccc")))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
ConditionalSpec
|
A |
required |
Returns:
| Type | Description |
|---|---|
Chart
|
New |
Examples:
>>> import ferrum as fm
>>> import polars as pl
>>> from ferrum.selection import selection_point, value
>>> df = pl.DataFrame({"x": [1, 2], "y": [3, 4], "z": ["a", "b"]})
>>> sel = selection_point(fields=["z"])
>>> chart = (
... fm.Chart(df)
... .mark_point()
... .encode(x="x", y="y")
... .conditional(sel.when(fm.Color("z")).otherwise(value("#ccc")))
... )
RenderConfig
dataclass
¶
Per-chart rendering configuration.
Controls the auto-raster policy that transparently substitutes
mark_raster for per-element marks when the mark count exceeds
raster_threshold. This prevents multi-million-row charts from
producing impractically large SVG output.
For one-off overrides, prefer the raster= keyword on output
methods (chart.show(raster=False), chart.save(..., raster=False),
chart.show_svg(raster=False)). Use RenderConfig when you want
to bake the policy into the chart object itself.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster_threshold
|
int or None
|
Mark count above which auto-raster fires. |
500_000
|
raster_behavior
|
('warn', 'silent', 'error')
|
|
"warn"
|
raster_aggregate
|
str
|
Aggregation function for the substituted |
"count"
|
raster_cmap
|
str
|
Colormap for the substituted |
"viridis"
|
Identity ¶
Explicit no-op position adjustment.
Distinct from position=None (which means "no adjustment declared"):
Identity is part of the spec and round-trips through JSON. Use it
when composing layered charts that need to opt out of an inherited stack
or dodge on a per-layer basis.
Eligible marks: all.
Examples:
Dodge ¶
Side-by-side placement of marks grouped by a channel.
Eligible marks: bar, point, box, boxplot, boxen,
swarm, violin, errorbar, errorband, ribbon,
histogram, density.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
by
|
str
|
Channel name to group by. Defaults to the color/fill channel when omitted. |
None
|
padding
|
float
|
Gap between dodged groups as a fraction of band width. Must be in
|
0.05
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import ferrum as fm
>>> fm.Chart(df).encode(x="cat", y="val", color="grp").mark_bar(
... position=fm.Dodge()
... )
Jitter ¶
Random per-row noise applied to x, y, or both axes.
Uses a ChaCha8 RNG seeded from seed, making SVG output
byte-deterministic for a given dataset and seed. When seed=None the
Rust renderer derives a per-row seed from the row's data values via
xxh3 — output remains deterministic across runs for fixed inputs.
Eligible marks: point, swarm, tick.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis
|
('x', 'y', 'both')
|
Which axis or axes to jitter. |
"x"
|
width
|
float
|
Maximum absolute displacement in scaled units. Must be |
0.4
|
seed
|
int or None
|
RNG seed. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
Examples:
>>> import ferrum as fm
>>> fm.Chart(df).encode(x="grp", y="value").mark_point(
... position=fm.Jitter(width=0.3, seed=42)
... )
Stack ¶
Vertical accumulation of marks grouped by a channel.
Eligible marks: rect-style (bar, area, ribbon,
histogram, density) and annotation-style (text,
point, rule, tick). The latter sit on top of a
stacked layer to label segments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
by
|
str
|
Channel name whose distinct values define the stack groups. Defaults to the color/fill channel when omitted. |
None
|
offset
|
('zero', 'normalize', 'center')
|
Stack baseline strategy:
|
"zero"
|
anchor
|
('top', 'mid')
|
Where each row's y output lands within its segment. |
"top"
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import ferrum as fm
>>> fm.Chart(df).encode(x="year", y="count", color="category").mark_bar(
... position=fm.Stack(offset="normalize")
... )
CoordFlip
dataclass
¶
CoordCartesian
dataclass
¶
Standard Cartesian coordinates with optional domain and clip overrides.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xlim
|
(float, float) | None
|
Explicit x-axis domain |
None
|
ylim
|
(float, float) | None
|
Explicit y-axis domain |
None
|
expand
|
bool
|
Add padding around the data extent (default |
True
|
clip
|
bool
|
Clip marks to the plot area (default |
True
|
Examples:
>>> fm.Chart(df).mark_point().encode(x="x", y="y").coord(
... fm.CoordCartesian(xlim=(0, 100))
... )
CoordPolar
dataclass
¶
Polar coordinates for pie and radial charts.
The theta parameter names which encoding channel ("x" or "y")
is interpreted as the angular variable. The other channel is used as the
radial variable (for scatter-in-polar mode); omit it for pie/donut charts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
('x', 'y')
|
Which encoding channel maps to the angle. |
"x"
|
start
|
float
|
Starting angle in radians (default |
0.0
|
direction
|
(1, -1)
|
|
1
|
inner_radius
|
float
|
Inner radius in pixels. |
0.0
|
outer_radius
|
float or None
|
Outer radius in pixels. |
None
|
pad_angle
|
float
|
Angular gap between adjacent slices in radians (default |
0.0
|
Examples:
Pie chart::
fm.Chart(df).mark_arc().encode(x="value", color="category").coord(
fm.CoordPolar(theta="x")
)
Donut with 60 px hole::
fm.Chart(df).mark_arc().encode(x="value", color="category").coord(
fm.CoordPolar(theta="x", inner_radius=60)
)
CoordGeo
dataclass
¶
Geographic map-projection coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
projection
|
str
|
One of |
'mercator'
|
Examples:
CoordFixed
dataclass
¶
Cartesian coordinates with a fixed aspect ratio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ratio
|
float
|
Width-to-height ratio of one data unit. |
1.0
|
xlim
|
(float, float) | None
|
Explicit x-axis domain. |
None
|
ylim
|
(float, float) | None
|
Explicit y-axis domain. |
None
|
expand
|
bool
|
Add padding around data extent (default |
True
|
clip
|
bool
|
Clip marks to plot area (default |
True
|
Examples:
Layer ¶
Single rendering layer inside a multi-layer Chart.
Most multi-layer charts are built via the + operator on two Chart
instances (chart1 + chart2). Direct construction of Layer objects
is rarely needed outside of ferrum internals and composite-mark expansion
code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
object
|
DataFrame or Arrow-compatible object for this layer. When |
None
|
mark
|
str or MarkSpec
|
Mark type string (e.g. |
None
|
encoding
|
dict
|
Mapping of channel names to |
None
|
transforms
|
list
|
Sequence of transform objects applied to this layer's data before rendering. Defaults to an empty list when omitted. |
None
|
mark_kwargs
|
dict
|
Extra keyword arguments forwarded to the mark renderer (e.g.
|
None
|
Examples:
>>> from ferrum.layer import Layer
>>> layer = Layer(mark="text", encoding={"x": "x", "y": "y"}, mark_kwargs={"dx": 5})
HConcatChart ¶
Bases: _CompositeBase
Horizontal concatenation of two or more charts.
Each sub-chart retains its own scales, axes, and legend. Construct via
the | operator on Chart instances or directly with a list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
charts
|
list of Chart
|
Sub-charts to concatenate left-to-right. |
required |
spacing
|
float
|
Horizontal pixel gap between adjacent charts. |
10.0
|
Examples:
>>> import ferrum as fm
>>> combined = fm.Chart(df).encode(x="hp", y="mpg").mark_point() | fm.Chart(df).encode(x="hp").mark_histogram()
>>> combined.save("side_by_side.svg")
show_png ¶
Render to PNG bytes (2x retina by default).
Rasterises the SVG produced by show_svg() through the Rust
resvg pipeline -- the same rasteriser Chart.show_png() uses,
with the same 2x default scale.
Returns:
| Type | Description |
|---|---|
bytes
|
PNG image as raw bytes suitable for |
save ¶
Save the composition to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Destination file path. The extension determines the format when format is omitted. |
required |
format
|
str
|
|
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If format is not |
share_scale ¶
Share scales across this composition's member charts.
Computes the union domain for each channel marked "shared"
and re-emits every member chart with an explicit scale= dict
on that channel, so the participating axes lock to the same
ticks. Channels marked "independent" (the default for any
channel not listed) keep their per-chart domains.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**channels
|
str
|
Channel name → |
{}
|
Returns:
| Type | Description |
|---|---|
_ChartLike
|
A new composition of the same type with the shared scales
injected. No-op (returns |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any value is not |
Examples:
theme ¶
Apply a theme to every sub-chart and return a new composition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
Theme
|
Theme value to apply. |
required |
Returns:
| Type | Description |
|---|---|
_ChartLike
|
A new instance of the same composition class with t applied to each sub-chart. |
properties ¶
Forward properties(**kwargs) to every sub-chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Keyword arguments accepted by |
{}
|
Returns:
| Type | Description |
|---|---|
_ChartLike
|
A new instance of the same composition class with updated sub-chart properties. |
VConcatChart ¶
Bases: _CompositeBase
Vertical concatenation of two or more charts.
Each sub-chart retains its own scales, axes, and legend. Construct via
the & operator on Chart instances or directly with a list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
charts
|
list of Chart
|
Sub-charts to stack top-to-bottom. |
required |
spacing
|
float
|
Vertical pixel gap between adjacent charts. |
10.0
|
Examples:
>>> import ferrum as fm
>>> stacked = fm.Chart(df).encode(x="hp", y="mpg").mark_point() & fm.Chart(df).encode(x="hp").mark_histogram()
>>> stacked.save("stacked.svg")
show_png ¶
Render to PNG bytes (2x retina by default).
Rasterises the SVG produced by show_svg() through the Rust
resvg pipeline -- the same rasteriser Chart.show_png() uses,
with the same 2x default scale.
Returns:
| Type | Description |
|---|---|
bytes
|
PNG image as raw bytes suitable for |
save ¶
Save the composition to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Destination file path. The extension determines the format when format is omitted. |
required |
format
|
str
|
|
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If format is not |
share_scale ¶
Share scales across this composition's member charts.
Computes the union domain for each channel marked "shared"
and re-emits every member chart with an explicit scale= dict
on that channel, so the participating axes lock to the same
ticks. Channels marked "independent" (the default for any
channel not listed) keep their per-chart domains.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**channels
|
str
|
Channel name → |
{}
|
Returns:
| Type | Description |
|---|---|
_ChartLike
|
A new composition of the same type with the shared scales
injected. No-op (returns |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any value is not |
Examples:
theme ¶
Apply a theme to every sub-chart and return a new composition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
Theme
|
Theme value to apply. |
required |
Returns:
| Type | Description |
|---|---|
_ChartLike
|
A new instance of the same composition class with t applied to each sub-chart. |
properties ¶
Forward properties(**kwargs) to every sub-chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Keyword arguments accepted by |
{}
|
Returns:
| Type | Description |
|---|---|
_ChartLike
|
A new instance of the same composition class with updated sub-chart properties. |
JointChart ¶
Bases: _ChartLike
Joint distribution view: center chart plus optional top and right marginals.
Lays out a 2 × 2 grid: center chart occupies the bottom-left cell, top marginal goes top-left, right marginal goes bottom-right, and the top-right corner is empty. The x-axis is shared between the center and top charts; the y-axis is shared between the center and right charts.
The cell size ratio between the center and each marginal is controlled by
ratio. A ratio of 5 gives the center 5/(5+1) of each dimension and
each marginal 1/(5+1).
Most users obtain a JointChart from ferrum.jointplot rather than
constructing one directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
Chart
|
Primary scatter / distribution chart occupying the main panel. |
required |
top
|
Chart
|
Marginal chart drawn above the center (e.g. a histogram of the x variable). |
None
|
right
|
Chart
|
Marginal chart drawn to the right of the center (e.g. a histogram of the y variable). |
None
|
ratio
|
int
|
Size ratio of the center panel to each marginal panel. Must be > 0. |
5
|
spacing
|
float
|
Pixel gap between adjacent cells. |
10.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If ratio is not > 0. |
Examples:
show_png ¶
Render to PNG bytes (2x retina by default).
Rasterises the SVG produced by show_svg() through the Rust
resvg pipeline -- the same rasteriser Chart.show_png() uses,
with the same 2x default scale.
Returns:
| Type | Description |
|---|---|
bytes
|
PNG image as raw bytes suitable for |
save ¶
Save the composition to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Destination file path. The extension determines the format when format is omitted. |
required |
format
|
str
|
|
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If format is not |
share_scale ¶
Share scales across this composition's member charts.
Computes the union domain for each channel marked "shared"
and re-emits every member chart with an explicit scale= dict
on that channel, so the participating axes lock to the same
ticks. Channels marked "independent" (the default for any
channel not listed) keep their per-chart domains.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**channels
|
str
|
Channel name → |
{}
|
Returns:
| Type | Description |
|---|---|
_ChartLike
|
A new composition of the same type with the shared scales
injected. No-op (returns |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any value is not |
Examples:
theme ¶
Apply a theme to every sub-chart and return a new composition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
Theme
|
Theme value to apply. |
required |
Returns:
| Type | Description |
|---|---|
_ChartLike
|
A new instance of the same composition class with t applied to each sub-chart. |
properties ¶
Forward properties(**kwargs) to the center chart.
The marginals (top, right) are kept unchanged because their width /
height is derived from the center plus ratio at render time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Keyword arguments accepted by |
{}
|
Returns:
| Type | Description |
|---|---|
JointChart
|
A new instance with updated center-chart properties. |
RepeatChart ¶
Bases: _ChartLike
Repeat a template chart over a grid of row / column field combinations.
Use Repeat.column, Repeat.row, or Repeat.layer typed sentinels
in the template's .encode(...) call to mark which encoding channel
receives the per-cell field substitution. RepeatChart.expand()
materializes the grid into fully-resolved (row_field, col_field, Chart)
tuples.
diagonal= provides an alternate template for cells where
row_field == col_field (symmetric n × n repeat). corner=True
filters the expanded grid to the lower triangle including the diagonal.
Most users obtain a RepeatChart through Chart.repeat() or
ferrum.pairplot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template
|
Chart
|
Template chart whose |
required |
row
|
list of str
|
Field names assigned to the row axis. |
None
|
column
|
list of str
|
Field names assigned to the column axis. |
None
|
layer
|
list of str
|
Field names assigned to the layer axis (for non-grid repeat layouts). |
None
|
diagonal
|
Chart
|
Alternate template used when |
None
|
corner
|
bool
|
When |
False
|
spacing
|
float
|
Pixel gap between adjacent cells. |
10.0
|
columns
|
int
|
Maximum number of columns for a wrapped 1-D repeat layout (no-op for 2-D row/column repeat). |
None
|
resolve
|
dict
|
Per-channel scale-sharing overrides — e.g.
|
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If diagonal is set but row or column is not. |
Examples:
>>> import ferrum as fm
>>> base = fm.Chart(df).encode(x=fm.Repeat.column, y=fm.Repeat.row).mark_point()
>>> grid = fm.RepeatChart(base, row=["mpg", "hp"], column=["mpg", "hp"])
>>> grid.save("pair_grid.svg")
show_png ¶
Render to PNG bytes (2x retina by default).
Rasterises the SVG produced by show_svg() through the Rust
resvg pipeline -- the same rasteriser Chart.show_png() uses,
with the same 2x default scale.
Returns:
| Type | Description |
|---|---|
bytes
|
PNG image as raw bytes suitable for |
save ¶
Save the composition to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Destination file path. The extension determines the format when format is omitted. |
required |
format
|
str
|
|
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If format is not |
theme ¶
Apply a theme to every sub-chart and return a new composition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
Theme
|
Theme value to apply. |
required |
Returns:
| Type | Description |
|---|---|
_ChartLike
|
A new instance of the same composition class with t applied to each sub-chart. |
properties ¶
Forward properties(**kwargs) to every sub-chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Keyword arguments accepted by |
{}
|
Returns:
| Type | Description |
|---|---|
_ChartLike
|
A new instance of the same composition class with updated sub-chart properties. |
expand ¶
Materialize the template into fully-resolved chart cells.
Cell iteration shape:
- 2-D grid (both row and column set):
len(row) × len(column)cells, optionally filtered by corner; diagonal substitutes the template onrow_field == col_fieldcells. - 1-D wrap (only one of row or column set): the populated
field list, paired with
Noneon the missing axis. Geometry is applied by :meth:show_svgdriven bycolumns. - Layer-only (
layer=set, row and column bothNone): a single cell containing all layers.
When layer= is set, each cell becomes a layered Chart
with one layer per element in self.layer (substituted into
every Repeat.layer placeholder). Diagonal cells skip
layering — the diagonal template already defines that cell.
Returns:
| Type | Description |
|---|---|
list of tuple
|
Each element is |
Raises:
| Type | Description |
|---|---|
ValueError
|
If diagonal is set but |
share_scale ¶
Share scales across this repeat's cells by merging into resolve=.
Equivalent to constructing the chart with resolve={...} set
— both paths run through :meth:_apply_resolve at expand()
time, so the union-domain computation sees every cell (including
each layer of layered cells) exactly once. Passing the same
channel twice with different modes takes the call's value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**channels
|
str
|
Channel name → |
{}
|
Returns:
| Type | Description |
|---|---|
RepeatChart
|
A new |
show_svg ¶
Render the repeated grid to an SVG string.
Returns:
| Type | Description |
|---|---|
str
|
SVG markup containing all materialized cell charts in a grid. |
Notes
2-D grids (both row and column set) lay out as
len(row) × len(column). 1-D layouts (only one axis set) wrap
by columns — column-only spreads left-to-right and wraps
downward; row-only spreads top-to-bottom in a single column unless
columns opens additional columns. When columns is unset
the 1-D layout is a single row (column-only) or column (row-only).
ClusterMapChart ¶
Bases: _ChartLike
Clustered heatmap with optional row and column dendrograms.
Lays out a 2 × 2 grid: the heatmap occupies the bottom-right cell, the column dendrogram goes top-right, the row dendrogram (rotated 90°) goes bottom-left, and the top-left corner is empty. Dendrogram value axes are hidden; categorical axes align with the heatmap row/column labels.
Cell size is split by dendrogram_ratio: dendrograms receive that
fraction of the total width/height, the heatmap receives the remainder.
Most users obtain a ClusterMapChart from ferrum.clustermap rather
than constructing one directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
heatmap
|
Chart
|
The central heatmap chart. |
required |
row_dendrogram
|
Chart
|
Dendrogram chart for the row axis. Displayed to the left of the heatmap, rotated 90°. |
None
|
col_dendrogram
|
Chart
|
Dendrogram chart for the column axis. Displayed above the heatmap. |
None
|
dendrogram_ratio
|
float
|
Fraction of the total width/height allocated to each dendrogram panel. Must be in the open interval (0, 1). |
0.2
|
spacing
|
float
|
Pixel gap between adjacent cells. |
10.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If dendrogram_ratio is not in the open interval (0, 1). |
Examples:
>>> import ferrum as fm
>>> cm = fm.clustermap(df, method="ward", cmap="rdbu")
>>> cm.save("clustermap.svg")
charts
property
¶
List of Chart : All non-None sub-charts in __init__ order
(heatmap, row_dendrogram, col_dendrogram).
show_png ¶
Render to PNG bytes (2x retina by default).
Rasterises the SVG produced by show_svg() through the Rust
resvg pipeline -- the same rasteriser Chart.show_png() uses,
with the same 2x default scale.
Returns:
| Type | Description |
|---|---|
bytes
|
PNG image as raw bytes suitable for |
save ¶
Save the composition to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Destination file path. The extension determines the format when format is omitted. |
required |
format
|
str
|
|
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If format is not |
share_scale ¶
Share scales across this composition's member charts.
Computes the union domain for each channel marked "shared"
and re-emits every member chart with an explicit scale= dict
on that channel, so the participating axes lock to the same
ticks. Channels marked "independent" (the default for any
channel not listed) keep their per-chart domains.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**channels
|
str
|
Channel name → |
{}
|
Returns:
| Type | Description |
|---|---|
_ChartLike
|
A new composition of the same type with the shared scales
injected. No-op (returns |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any value is not |
Examples:
theme ¶
Apply a theme to every sub-chart and return a new composition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
Theme
|
Theme value to apply. |
required |
Returns:
| Type | Description |
|---|---|
_ChartLike
|
A new instance of the same composition class with t applied to each sub-chart. |
properties ¶
Forward properties(**kwargs) to the heatmap chart.
The dendrogram panels are kept unchanged because their width / height
is derived from the heatmap plus dendrogram_ratio at render time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Keyword arguments accepted by |
{}
|
Returns:
| Type | Description |
|---|---|
ClusterMapChart
|
A new instance with updated heatmap-chart properties. |
Repeat ¶
Namespace for typed RepeatChart template sentinels.
Access the three sentinels via class attributes — do not instantiate
Repeat directly:
Attributes:
| Name | Type | Description |
|---|---|---|
column |
_RepeatPlaceholder
|
Sentinel that resolves to the column-axis field for each cell. |
row |
_RepeatPlaceholder
|
Sentinel that resolves to the row-axis field for each cell. |
layer |
_RepeatPlaceholder
|
Sentinel that resolves to the layer-axis field for each cell. |
Examples:
>>> import ferrum as fm
>>> base = (
... fm.Chart(df)
... .encode(x=fm.Repeat.column, y=fm.Repeat.row)
... .mark_point()
... )
>>> grid = fm.RepeatChart(base, row=["mpg", "hp"], column=["mpg", "hp"])
AUCLabel
dataclass
¶
Auto-placed AUC annotation for ROC charts.
chart + AUCLabel() reads the surrounding chart's line data
(x = FPR, y = TPR), computes trapezoidal AUC per series
(grouped by color when present), and emits one text annotation
per series at the line endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
('end', 'corner')
|
Where to place the label. |
"end"
|
format
|
str
|
Python format spec applied to the AUC value (e.g. |
".3f"
|
prefix
|
str
|
Text prepended to the formatted metric value. |
"AUC = "
|
Examples:
>>> import ferrum as fm
>>> chart = fm.roc_chart(model, X_test, y_test)
>>> annotated = chart + fm.AUCLabel()
APLabel
dataclass
¶
Auto-placed Average Precision annotation for PR charts.
Sibling of :class:AUCLabel for precision-recall curves. x is
treated as recall and y as precision. Computes step-function
area under the curve per series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
('end', 'corner')
|
Where to place the label. |
"end"
|
format
|
str
|
Python format spec applied to the AP value. |
".3f"
|
prefix
|
str
|
Text prepended to the formatted metric value. |
"AP = "
|
Examples:
>>> import ferrum as fm
>>> chart = fm.pr_chart(model, X_test, y_test)
>>> annotated = chart + fm.APLabel()
BrierLabel
dataclass
¶
Auto-placed Brier-score annotation for calibration charts.
x is treated as predicted probability and y as observed rate
per bin. Multi-series charts emit one Brier score per series. Lower
scores indicate better calibration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
('end', 'corner')
|
Where to place the label. |
"end"
|
format
|
str
|
Python format spec applied to the Brier score value. |
".3f"
|
prefix
|
str
|
Text prepended to the formatted metric value. |
"Brier = "
|
Examples:
>>> import ferrum as fm
>>> chart = fm.calibration_chart(model, X_test, y_test)
>>> annotated = chart + fm.BrierLabel()
OutlierLabel
dataclass
¶
Auto-label high-leverage or high-residual points on a scatter chart.
chart + OutlierLabel() scans the chart's y column for values
whose z-score exceeds threshold, then overlays text labels at those
points. The label text is taken from label_field when supplied,
otherwise from the field column, otherwise from the y value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
Z-score threshold above which a point is considered an outlier and labelled. |
3.0
|
field
|
str
|
Column to compute z-scores from. Defaults to the chart's |
None
|
label_field
|
str
|
Column whose value is used as the text label. Defaults to |
None
|
max_labels
|
int
|
Maximum number of labels to emit. Points are ranked by absolute
z-score and only the top |
10
|
Examples:
>>> import ferrum as fm
>>> chart = fm.residuals_chart(model, X_test, y_test)
>>> annotated = chart + fm.OutlierLabel(threshold=2.5, max_labels=5)
Title
dataclass
¶
Chart title with optional subtitle.
Accepted everywhere a title string is accepted: Chart(title=...),
Chart.properties(title=...), HConcat/VConcat/Layer(title=...).
Passing a bare string is equivalent to Title(text=string).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Primary title text. |
required |
subtitle
|
str
|
Secondary line below the title; |
None
|
anchor
|
('start', 'middle', 'end')
|
Horizontal anchor. |
"start"
|
offset
|
float
|
Pixel offset from plot area; defaults to the theme's |
None
|
font_size
|
float
|
Title font size in points. |
None
|
font_weight
|
str
|
Title font weight (e.g. |
None
|
color
|
str
|
Title color as a CSS color string. |
None
|
subtitle_font_size
|
float
|
Subtitle font size; defaults to |
None
|
subtitle_color
|
str
|
Subtitle color; defaults to the theme's |
None
|
Examples:
>>> import ferrum as fm
>>> title = fm.Title("My Chart", subtitle="subtitle text", anchor="start")
>>> fm.Chart(df).mark_point().encode(x="x", y="y").properties(title=title)
to_spec_dict ¶
Serialize to the dict shape the Rust binding expects.
Only emits non-default fields so the JSON sent to Rust stays minimal and forward-compatible.
Selection
dataclass
¶
Immutable selection descriptor.
Created by selection_point(), selection_interval(),
selection_single(), or selection_multi() — do not construct
directly.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Stable identifier used to link this selection to conditional encodings and to the WASM renderer. |
kind |
{'point', 'interval'}
|
Selection type. |
params |
dict
|
Resolved parameters forwarded to the Rust |
Examples:
Build a conditional encoding from a selection:
SelectionMark
dataclass
¶
Visual style for the interval selection brush rectangle.
Pass an instance to selection_interval(mark=...) to override the
default brush appearance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fill
|
str
|
Hex colour string for the brush fill (e.g. |
None
|
stroke
|
str
|
Hex colour string for the brush border. Defaults to the renderer's built-in grey. |
None
|
fill_opacity
|
float
|
Opacity of the fill (0.0 = transparent, 1.0 = opaque). |
0.3
|
stroke_opacity
|
float
|
Opacity of the border. |
1.0
|
stroke_width
|
float
|
Border line width in pixels. |
1.0
|
stroke_dash
|
list of float
|
Dash pattern for the border (e.g. |
None
|
Examples:
>>> import ferrum as fm
>>> brush_style = fm.SelectionMark(fill="#ff9900", fill_opacity=0.2, stroke_dash=[4, 2])
>>> brush = fm.selection_interval(mark=brush_style)
to_spec_dict ¶
Serialize to a dict matching the Rust SelectionMarkStyle shape.
ConditionalSpec
dataclass
¶
Resolved conditional encoding — produced by sel.when(...).otherwise(...).
Do not construct directly. Build one through the selection fluent API::
sel.when(<if_encoding>).otherwise(<else_encoding>)
Attributes:
| Name | Type | Description |
|---|---|---|
selection_name |
str
|
Name of the |
if_selected |
encoding channel or value(...)
|
Encoding applied when a datum falls inside the selection. |
if_not |
encoding channel or value(...)
|
Encoding applied when a datum falls outside the selection. |
Examples:
>>> import ferrum as fm
>>> sel = fm.selection_point()
>>> cond = sel.when(fm.Color("category")).otherwise(fm.value("#cccccc"))
>>> type(cond).__name__
'ConditionalSpec'
to_spec_dict ¶
Serialize to a dict matching the Rust ConditionalEncoding shape.
ComparedModelSource ¶
Multi-model wrapper exposing the same surface as ModelSource.
Every derived-data method is proxied through each underlying
ModelSource and the per-model outputs are concatenated with a
model: Utf8 column stamped on each frame, so downstream chart
builders can route color="model" to render one curve per model.
_X, _y, _feature_names, and _class_names resolve to
the first source's values (every wrapped source shares X / y
by construction in ModelSource.compare, so any one will do);
accessing _model raises since there is no single estimator.
model_names reports the configured ordering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sources
|
dict[str, ModelSource]
|
Mapping from model name (used for the |
required |
Examples:
>>> import ferrum as fm
>>> cms = fm.ModelSource.compare({"ridge": ridge, "lasso": lasso}, X, y)
>>> fm.roc_chart(cms) # overlay both curves
>>> cms.model_names
['ridge', 'lasso']
>>> cms.roc_curve() # long-form frame with `model` column
model_names
property
¶
Ordered list of model display names.
Returns the keys of the sources dict supplied at construction time,
in insertion order. Each name corresponds to the value written into the
model column on every derived-data DataFrame.
Returns:
| Type | Description |
|---|---|
list[str]
|
Model names in the order they were registered. |
ModelSource ¶
Bases: PredictionsMixin, ClassificationCurvesMixin, FeatureImportanceMixin, ModelSelectionMixin, ClusteringMixin, RankingMixin, BaseSource
Wrap a fitted estimator + dataset and expose model-diagnostic derived data as polars DataFrames.
Constructing a ModelSource is sklearn-free — only attribute
introspection runs at __init__ time. Derived-data methods that
need sklearn / shap / umap lazy-import on call, so import ferrum
never pulls those packages into the user's process unless they
actually compute a diagnostic that requires them.
Each derived-data method returns a long-form polars DataFrame
whose schema is documented in ferrum._diagnostics.schemas —
chart builders and Visualizers consume the same frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
A fitted estimator. Must expose at least |
required |
X
|
DataFrame | DataFrame | Table | ndarray
|
Feature matrix. Coerced internally to a polars DataFrame; any
|
required |
y
|
array - like
|
Target. Required by methods that depend on ground truth (every
method except |
None
|
feature_names
|
sequence of str
|
Column labels. Defaults to |
None
|
class_names
|
sequence of str
|
Per-class display labels for classification diagnostics.
Defaults to |
None
|
sample_weight
|
array - like
|
Per-row weights forwarded to sklearn scorers that accept them. |
None
|
random_state
|
int
|
Seed propagated to every derived-data method whose underlying compute consumes randomness (importances permutation, SHAP background sampling, UMAP / t-SNE / MDS embeddings, cross-validation curves, partial-dependence sampling). Deterministic methods ignore the value. |
None
|
Examples:
>>> import ferrum as fm
>>> source = fm.ModelSource(model, X, y, random_state=0)
>>> fm.roc_chart(source) # use directly with a figure function
>>> source.predictions() # access derived data as a DataFrame
>>> source.confusion_matrix(normalize="true")
X
property
¶
Feature matrix coerced to a polars DataFrame.
Returns the value supplied to __init__ (after coercion).
Use this for read-only access from chart builders and external
callers — source._X is an internal alias preserved for
back-compat.
y
property
¶
Target series, or None when no y was supplied.
Returns the polars Series the constructor coerced from the
y argument. None means unsupervised — methods that
need ground truth raise on call.
model
property
¶
The wrapped fitted estimator.
Returns the model object supplied at construction time unchanged.
Chart builders use it for occasional native introspection (e.g.
model.classes_, model.n_clusters); prefer the public
derived-data methods when one exists.
feature_names
property
¶
capabilities
property
¶
Protocol attributes present on the wrapped estimator.
A frozen subset of _PROTOCOL_ATTRS ("predict",
"predict_proba", "coef_", "feature_importances_", …)
detected at construction time via hasattr. Derived-data methods
gate on this set to pick the appropriate code path and raise
AttributeError with a clear message when a required attribute
is absent.
Returns:
| Type | Description |
|---|---|
frozenset[str]
|
Attribute names that are present on the wrapped model. |
rank1d ¶
Univariate feature ranking.
algorithm in {"shapiro", "variance", "covariance"}. The
Shapiro-Wilk and variance algorithms operate on X alone;
"covariance" ranks features by absolute sample covariance with
y and therefore requires y to be present.
Output schema (SCHEMA_RANK1D): feature: Utf8,
score: Float64, rank: Int64. Rows are pre-sorted by descending
score so rank=1 is always the top feature.
rank2d ¶
Pairwise feature ranking — long-form correlation matrix.
algorithm in {"pearson", "spearman", "kendall", "covariance"}.
All algorithms now run in Rust (Kendall uses Knight's O(n log n)).
Output schema (SCHEMA_RANK2D): feature_x: Utf8,
feature_y: Utf8, correlation: Float64 — one row per
ordered pair of features, p × p rows total.
silhouette ¶
Per-sample silhouette values, sorted within cluster descending.
Returns one row per sample with columns sample_id (original X
index), y_position (sequential 0..n-1 stack order — used by
mark_silhouette to render bars in a tightly-packed Rousseeuw
layout), cluster, and silhouette_value.
k is informational; if provided, the result is filtered to
clusters in range(k).
pca_variance ¶
Explained-variance ratio per principal component plus the cumulative running sum.
If the wrapped model exposes explained_variance_ratio_ (e.g.
sklearn.decomposition.PCA), reads it directly (backward compat).
Otherwise computes from raw X via Rust SVD.
embeddings ¶
Low-dimensional embedding of X via UMAP / t-SNE / PCA.
Returns dim_0 … dim_{n_components-1} plus a label column
(y when provided, else zeros — used to color the scatter).
random_state is taken from the source's random_state.
intercluster_distance ¶
2D embedding of cluster centers + cluster size.
Returns one row per cluster with cluster (Int64), x / y
(Float64, the 2D embedded coordinate), and size (Int64, sample
count). Requires the wrapped model to expose cluster_centers_.
learning_curve ¶
Learning curve: score per (train_size, fold, split).
Returns long-form rows — one per (train_size, fold, split). Each
row carries the per-fold score plus the per-(train_size, split)
aggregates mean_score, std_score, lower, upper (95%
CI on the mean). Chart builders dedupe by (train_size, split) to
render a ribbon + line; the per-fold rows enable per-fold strip
overlays if a future caller wants them.
validation_curve ¶
Validation curve: score per (param_value, fold, split).
Same shape as learning_curve but parameterized by an
estimator hyperparameter sweep. param is the kwarg name on
the wrapped estimator (e.g. "alpha" for Ridge).
cv_scores ¶
Per-fold cross-validation scores.
Returns one row per (fold, split) — train and test scores for each cross-validation fold. Chart builders use this for boxplot / bar / strip distributions across folds.
alpha_selection ¶
Regularization-strength sweep for linear models.
Returns one row per (alpha, fold) — the per-fold test score on the
held-out split — plus per-alpha mean_score / std_score
aggregates. Chart builders dedupe by alpha to render a single
line, and use argmax(mean_score) to mark the best alpha.
importances ¶
importances(*, method: str = 'builtin', n_repeats: int = 30, scoring: Any = None, random_state: int | None = None) -> pl.DataFrame
Feature importance per feature, sorted by descending |importance|.
method="builtin" reads the wrapped model's feature_importances_
(tree-based estimators) or coef_ (linear estimators, averaged
absolute value across classes for multi-output linears). std is
zero in this path — sklearn's built-in attribute exposes no
per-feature variance.
method="permutation" calls sklearn's
permutation_importance with n_repeats/scoring and
populates std with the per-feature standard deviation across
repeats.
shap_values ¶
Long-form SHAP values per (sample, feature, class).
Returns a DataFrame with sample_id, feature, shap_value,
feature_value, feature_value_normalized, class_label.
- Regression:
class_labelis the constant"target"on every row. - Binary classifiers:
class_labelis the positive-class name on every row; SHAP values are for the positive class. - Multi-class classifiers: one row per (sample, feature, class);
class_labelcarries the class name. The result hasn_samples * n_features * n_classesrows total.
Explainer is auto-picked by model capability:
coef_:shap.LinearExplainer(deterministic, fast).feature_importances_:shap.TreeExplainer(deterministic for tree ensembles).- otherwise:
shap.KernelExplainer(model-agnostic; uses the firstmin(50, N)rows of X as the background unless an explicitbackgroundarray is passed).
partial_dependence ¶
partial_dependence(features: list[str | int], *, grid_resolution: int = 100, kind: str = 'average') -> pl.DataFrame
Partial dependence per feature.
kind="average" (default) returns the marginal PD curve per
feature with sample_id = -1 (one row per grid point per
feature).
kind="individual" returns per-sample ICE curves: one row per
(feature, sample_id, grid_point) triple with sample_id in
[0, n_samples). Chart builders pair this with the detail
encoding channel on sample_id to render one polyline per
sample.
kind="both" returns the union of the two: ICE rows plus
average rows (sample_id = -1), so a downstream chart can
overlay both layers on the same DataFrame.
roc_curve ¶
ROC curve(s). One row per (class, threshold). auc repeats per class.
For binary classifiers with average=None (default), returns a
single curve on the positive (second) class. For multiclass,
returns one-vs-rest curves per class; pass average in
{"micro", "macro", "weighted"} to additionally include a summary
curve under class="<average>".
pr_curve ¶
Precision-recall curve(s). One row per (class, threshold).
For binary classifiers, returns a single curve on the positive
(second) class — average is accepted for API symmetry with
the multiclass path but has no effect because binary classifiers
have only one curve to draw. For multiclass:
average=None(default) — returns one-vs-rest curves per class.average in {"micro", "macro", "weighted"}— returns a single summary curve withclass="<average>"and no per-class rows. Macro / weighted variants interpolate per- class precision over a shared recall grid (100 points); micro ravels the binarized labels into one curve.thresholdis NaN on every row of macro / weighted summaries (recall-grid interpolation discards thresholds) and follows sklearn's padding convention for micro.
threshold is NaN at the final (recall=0) point of every
per-class curve per sklearn's convention.
calibration_curve ¶
Calibration (reliability) curve for binary classifiers.
Returns one row per non-empty bin with mean_predicted,
fraction_positive, and count. Uses sklearn's
calibration_curve for the means/fractions and a parallel pass
over y_score to count rows per bin.
cumulative_gain ¶
Cumulative-gain curve per class. Appends a 2-row class='baseline'
diagonal for plotting reference.
lift_curve ¶
Lift curve per class. Appends a 2-row class='baseline' line at
lift=1.0.
discrimination_threshold ¶
Discrimination threshold sweep — binary classifiers only.
Sweeps n_thresholds evenly-spaced thresholds in [0, 1] and
reports precision, recall, F1, and queue_rate at each. queue_rate
is the hand-computed fraction (y_score >= t).mean().
When cv is an int, runs the same sweep on each fold's held-out
scores from a freshly-cloned + re-fit estimator and averages
per-threshold metrics across folds. Pass a splitter object with a
.split() method to override.
confusion_matrix ¶
Confusion matrix in long form: one row per (actual, predicted) cell.
normalize: None for raw counts, "true"/"pred"/"all"
for sklearn-style normalization. value is the (possibly
normalized) count; value_fmt is a stringified label suitable for
mark_text overlay (integer counts when unnormalized, two-decimal
fractions when normalized).
predictions ¶
Return y_true, y_pred, residual, studentized_residual, cooks_distance, leverage.
leverage is the diagonal of the hat matrix
H = X (XᵀX)⁻¹ Xᵀ for linear estimators (those exposing
coef_); NaN otherwise. Used by the residuals-vs-leverage
panel of multi-panel residuals charts.
probabilities ¶
Return y_true + one column per class with predicted probability.
compare
classmethod
¶
Build a ComparedModelSource over one ModelSource per model.
Each value in models is wrapped in its own ModelSource with the
shared X and y. The returned ComparedModelSource proxies
every derived-data method through all wrapped sources and stamps the
model name as a model column on the concatenated output, so
downstream chart builders can route color="model".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
models
|
dict[str, Any]
|
Mapping from display name to fitted estimator. Each estimator is
wrapped in its own |
required |
X
|
array - like
|
Feature matrix shared by all models. Accepted types match
|
required |
y
|
array - like
|
Target shared by all models. Required by most derived-data
methods (same constraints as |
None
|
**kwargs
|
Any
|
Keyword arguments forwarded verbatim to each |
{}
|
Returns:
| Type | Description |
|---|---|
ComparedModelSource
|
Multi-model wrapper whose derived-data methods return long-form
DataFrames with an extra |
Examples:
CalibrationVisualizer ¶
Bases: FerrumVisualizer
Calibration (reliability) diagram for a probability classifier.
Wraps ModelSource.calibration_curve(). Records the mean squared
deviation between mean_predicted and fraction_positive as
calibration_error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*models
|
Any
|
One or more fitted classifiers. Pass a single model for a
single-curve diagram; pass two or more (or a single dict
positional argument like |
()
|
n_bins
|
int
|
Number of bins for the calibration histogram. |
10
|
strategy
|
('uniform', 'quantile')
|
Bin-edge strategy (matches |
"uniform"
|
random_state
|
int
|
|
None
|
theme
|
Theme
|
|
None
|
Examples:
>>> import ferrum as fm
>>> viz = fm.CalibrationVisualizer(clf, n_bins=5).fit(X, y)
>>> viz_overlay = fm.CalibrationVisualizer(clf_a, clf_b).fit(X, y)
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
ClassBalanceVisualizer ¶
Bases: FerrumVisualizer
Bar chart of per-class label counts, computed from target labels alone.
Accepts both the standard sklearn fit(X, y) signature and the
label-only shorthand fit(y) — when the second argument is omitted,
the first positional argument is treated as the label array. No model
is required; pass nothing for the model argument (it is always
None internally).
After fit, _metrics contains:
n_classes— number of unique class labels.imbalance_ratio—max_count / max(min_count, 1), where 1.0 indicates perfectly balanced classes and larger values indicate increasing imbalance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
random_state
|
int
|
Accepted for API symmetry with model-backed visualizers but
intentionally never consumed — |
None
|
theme
|
Theme
|
Per-chart theme override. Falls back to the global default when |
None
|
Examples:
>>> import ferrum as fm
>>> viz = fm.ClassBalanceVisualizer().fit(X, y)
>>> viz.show() # returns the per-class count bar Chart
>>> viz._metrics["imbalance_ratio"]
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
ClassificationReportVisualizer ¶
Bases: FerrumVisualizer
Per-class precision, recall, and F1-score heatmap with text overlay.
Wraps _classification_report_chart(). Produces a rect-mark heatmap
with one row per class and columns for precision, recall, and F1.
Records f1_macro (macro-averaged F1 across all classes, computed via
sklearn.metrics.f1_score) as the headline scalar metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Fitted classifier implementing |
required |
random_state
|
int
|
Seed forwarded to |
None
|
theme
|
Theme
|
Ferrum theme applied to the output chart. |
None
|
Examples:
>>> import ferrum as fm
>>> viz = fm.ClassificationReportVisualizer(clf).fit(X, y)
>>> viz._metrics["f1_macro"]
0.91
>>> viz.show()
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
ClassPredictionErrorVisualizer ¶
Bases: FerrumVisualizer
Stacked-bar chart of actual-class composition per predicted class.
For each predicted class label on the x-axis, the bar is stacked by
the true class, showing how often a predicted class is correct vs.
confused with another class. When normalize=True every bar is
scaled to 100 % so proportions are comparable across imbalanced
classes.
After fit, overall accuracy (total correct / total predictions,
computed from raw counts regardless of normalize) is stored in
_metrics["accuracy"].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Fitted sklearn classifier that exposes |
required |
normalize
|
bool
|
When |
False
|
random_state
|
int
|
Seed forwarded to |
None
|
theme
|
Theme
|
Per-chart theme override. Falls back to the global default when |
None
|
Examples:
>>> import ferrum as fm
>>> viz = fm.ClassPredictionErrorVisualizer(model).fit(X, y)
>>> viz.show() # returns the stacked-bar Chart
>>> viz._metrics["accuracy"] # proportion of correct predictions
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
ConfusionMatrixVisualizer ¶
Bases: FerrumVisualizer
Confusion-matrix heatmap with per-cell counts or normalized fractions.
Wraps ModelSource.confusion_matrix(). Renders a rect-mark heatmap
with cell-value text overlaid. Records accuracy (diagonal sum / total,
always computed from raw counts regardless of the normalize setting).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Fitted classifier implementing |
required |
normalize
|
('true', 'pred', 'all')
|
Row-normalization strategy passed to the chart builder.
|
"true"
|
random_state
|
int
|
Seed forwarded to |
None
|
theme
|
Theme
|
Ferrum theme applied to the output chart. |
None
|
Examples:
>>> import ferrum as fm
>>> viz = fm.ConfusionMatrixVisualizer(clf).fit(X, y)
>>> viz._metrics["accuracy"]
0.94
>>> viz.show()
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
CooksDistanceVisualizer ¶
Bases: FerrumVisualizer
Cook's distance diagnostic for a regression estimator.
Surfaces max_studentized (the largest absolute studentized
residual) as a quick proxy for influential observations; the
leverage-aware Cook's D itself is materialized by
ModelSource.predictions().cooks_distance for linear estimators
and is rendered by mark_residuals(cook_threshold=...). This
visualizer plots the residuals chart with the leverage panel
enabled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Fitted regression estimator (must expose |
required |
threshold
|
float or 'auto'
|
Cook's-distance threshold for highlighting outliers on the
residuals-vs-leverage panel. Forwarded to
|
None
|
random_state
|
int
|
|
None
|
theme
|
Theme
|
|
None
|
Examples:
>>> import ferrum as fm
>>> viz = fm.CooksDistanceVisualizer(linear_model).fit(X, y)
>>> viz._metrics["max_studentized"]
3.42
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
DiscriminationThresholdVisualizer ¶
Bases: FerrumVisualizer
Sweep a decision threshold for a binary classifier and plot four metric curves.
Evaluates precision, recall, f1, and queue_rate (or a
caller-supplied subset) at n_thresholds evenly-spaced probability
thresholds between 0 and 1. After fit, the F1-maximising threshold
and its F1 score are available via _metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Fitted binary sklearn estimator that exposes |
required |
n_thresholds
|
int
|
Number of probability thresholds to evaluate across |
50
|
metrics
|
tuple of str
|
Which per-threshold metrics to include as curves in the chart.
Passed through to the underlying |
("precision", "recall", "f1", "queue_rate")
|
cv
|
Any
|
Cross-validation strategy forwarded to |
None
|
threshold_line
|
bool
|
When |
False
|
random_state
|
int
|
Seed forwarded to |
None
|
theme
|
Theme
|
Per-chart theme override. Falls back to the global default when |
None
|
Examples:
>>> import ferrum as fm
>>> viz = fm.DiscriminationThresholdVisualizer(model).fit(X, y)
>>> viz.show() # returns the four-curve Chart
>>> viz._metrics["best_threshold"], viz._metrics["best_f1"]
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
FeatureImportancesVisualizer ¶
Bases: FerrumVisualizer
Visualize feature importances from a fitted sklearn estimator.
Wraps importance_chart in the sklearn-protocol visualizer interface.
method="builtin" reads feature_importances_ or coef_ directly
from the estimator (std is 0 in this case). method="permutation" runs
sklearn.inspection.permutation_importance using the supplied
random_state seed. The headline metric recorded in _metrics is
top_feature_importance — the importance of the highest-ranked feature
after sorting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Fitted sklearn-compatible estimator. Must expose
|
required |
method
|
('builtin', 'permutation')
|
Strategy for extracting importances. |
"builtin"
|
top_k
|
int or None
|
Maximum number of features to display, ranked by importance. Pass
|
20
|
orient
|
('horizontal', 'vertical')
|
Bar orientation in the rendered chart. |
"horizontal"
|
error_bars
|
bool
|
Whether to draw ±1 std error bars. Has no visual effect when
|
True
|
random_state
|
int or None
|
RNG seed forwarded to |
None
|
theme
|
Theme or None
|
Per-chart theme override. Falls back to the global default when
|
None
|
Examples:
>>> import ferrum as fm
>>> from sklearn.ensemble import RandomForestClassifier
>>> model = RandomForestClassifier(n_estimators=50, random_state=0).fit(X_train, y_train)
>>> viz = fm.FeatureImportancesVisualizer(model).fit(X_train, y_train)
>>> viz.show()
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
FerrumVisualizer ¶
Base class for sklearn-protocol model-diagnostic visualizers.
Concrete visualizers either override _materialize +
_build_chart (the standard model-backed flow) or override
fit directly (no-model / multi-fit / label-only flow).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Fitted estimator that will be wrapped in a |
None
|
random_state
|
int
|
Seed forwarded to the underlying |
None
|
theme
|
Theme
|
Per-chart theme override. Falls back to the global default
when |
None
|
Examples:
>>> import ferrum as fm
>>> viz = fm.ROCVisualizer(model, random_state=0).fit(X, y)
>>> viz.show() # returns a Chart
>>> viz._metrics # headline metric(s)
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
PRVisualizer ¶
Bases: FerrumVisualizer
Precision-recall curve(s) for binary or multiclass classifiers.
Wraps ModelSource.pr_curve(). Records ap_mean (average
precision averaged across classes) as the headline metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Fitted classifier exposing |
required |
random_state
|
int
|
|
None
|
theme
|
Theme
|
|
None
|
Examples:
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
PredictionErrorVisualizer ¶
Bases: FerrumVisualizer
Actual-vs-predicted scatter for a regression estimator.
Wraps ModelSource.predictions(). Records rmse as the headline
metric; the chart shows y_true on x and y_pred on y with an
optional identity line and CI / reference band overlays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Fitted regression estimator. |
required |
reference_line
|
bool
|
Overlay the dashed |
True
|
ci
|
float
|
Confidence level in |
None
|
reference_band
|
bool
|
When |
False
|
random_state
|
int
|
|
None
|
theme
|
Theme
|
|
None
|
Examples:
>>> import ferrum as fm
>>> viz = fm.PredictionErrorVisualizer(model, ci=0.95).fit(X, y)
>>> viz.show()
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
ResidualsVisualizer ¶
Bases: FerrumVisualizer
Residuals-vs-fitted diagnostic for a regression estimator.
Wraps ModelSource.predictions(). Records rmse and mae as
headline metrics; the chart shows y_pred on x and the chosen
residual variant on y with a horizontal reference line at zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Fitted regression estimator (must implement |
required |
kind
|
('studentized', 'raw', 'scaled')
|
Which residual variant to plot. |
"studentized"
|
random_state
|
int
|
Forwarded to the underlying |
None
|
theme
|
Theme
|
|
None
|
Examples:
>>> import ferrum as fm
>>> viz = fm.ResidualsVisualizer(model).fit(X, y)
>>> viz._metrics["rmse"]
1.234
>>> viz.show()
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
ROCVisualizer ¶
Bases: FerrumVisualizer
ROC curve(s) for binary or multiclass classifiers.
Wraps ModelSource.roc_curve(). per_class=True (default)
draws one curve per class; pass per_class=False to plot a
single averaged curve. Records auc_mean as the headline metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Fitted classifier (must implement |
required |
micro
|
bool
|
Compute the micro-averaged AUC. |
True
|
macro
|
bool
|
Compute the macro-averaged AUC. Takes precedence over |
True
|
per_class
|
bool
|
Render one curve per class. When False, only the averaged curve is rendered. |
True
|
random_state
|
int
|
|
None
|
theme
|
Theme
|
|
None
|
Examples:
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
SHAPVisualizer ¶
Bases: FerrumVisualizer
Visualize SHAP values from a fitted sklearn estimator.
Wraps the shap_chart family in the sklearn-protocol visualizer
interface. Requires the shap library (pip install ferrum[shap]).
Three chart kinds are supported: "beeswarm" shows per-sample SHAP
scatter colored by feature value; "bar" shows mean absolute SHAP
aggregated per feature; "waterfall" shows the cumulative contribution
for a single sample selected by sample_idx. The headline metric
recorded in _metrics is top_abs_shap — the maximum mean absolute
SHAP value across all features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Fitted sklearn-compatible estimator supported by the |
required |
kind
|
('beeswarm', 'bar', 'waterfall')
|
Chart style to render. |
"beeswarm"
|
max_display
|
int
|
Maximum number of features to include in the chart, ranked by mean absolute SHAP value. |
20
|
sample_idx
|
int or None
|
Row index of the sample to explain. Required when |
None
|
order
|
('abs_mean', 'max')
|
Feature ordering strategy applied to all three |
"abs_mean"
|
background
|
Any or None
|
Background dataset passed to the SHAP explainer for models that
require a reference distribution (e.g. kernel SHAP). Pass |
None
|
random_state
|
int or None
|
RNG seed forwarded to the underlying |
None
|
theme
|
Theme or None
|
Per-chart theme override. Falls back to the global default when
|
None
|
Examples:
>>> import ferrum as fm
>>> from sklearn.ensemble import GradientBoostingClassifier
>>> model = GradientBoostingClassifier(random_state=0).fit(X_train, y_train)
>>> viz = fm.SHAPVisualizer(model, kind="beeswarm").fit(X_train, y_train)
>>> viz.show()
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
SHAPBeeswarmVisualizer ¶
Bases: _SHAPBaseMixin, FerrumVisualizer
Per-sample SHAP scatter colored by z-scored feature value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Fitted sklearn-compatible estimator supported by the |
required |
max_display
|
int
|
Maximum number of features ranked by |
20
|
order
|
('abs_mean', 'max')
|
Feature ranking criterion. |
"abs_mean"
|
background
|
Any
|
Background dataset passed to the SHAP explainer for kernel- SHAP models. Tree SHAP ignores this. |
None
|
random_state
|
forwarded to ``FerrumVisualizer``.
|
|
None
|
theme
|
forwarded to ``FerrumVisualizer``.
|
|
None
|
Examples:
>>> import ferrum as fm
>>> viz = fm.SHAPBeeswarmVisualizer(model, max_display=15).fit(X, y)
>>> viz.show()
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
SHAPBarVisualizer ¶
Bases: _SHAPBaseMixin, FerrumVisualizer
Mean-absolute SHAP per feature as a horizontal bar chart.
Parameters mirror :class:SHAPBeeswarmVisualizer; see that class
for the full parameter list.
Examples:
>>> import ferrum as fm
>>> from sklearn.ensemble import GradientBoostingClassifier
>>> viz = fm.SHAPBarVisualizer(GradientBoostingClassifier().fit(X_train, y_train))
>>> chart = viz.chart(X_test, y_test)
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
SHAPWaterfallVisualizer ¶
Bases: _SHAPBaseMixin, FerrumVisualizer
Cumulative per-feature SHAP contributions for one sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Fitted sklearn-compatible estimator supported by the |
required |
sample_idx
|
int
|
Row index (0-based) of the sample to explain. Required. |
required |
max_display
|
int
|
Maximum number of features to include in the waterfall, ranked
by |
20
|
order
|
('abs_mean', 'max')
|
Feature ranking criterion (drives both the top- |
"abs_mean"
|
background
|
Any
|
Background dataset passed to the SHAP explainer. |
None
|
random_state
|
forwarded to ``FerrumVisualizer``.
|
|
None
|
theme
|
forwarded to ``FerrumVisualizer``.
|
|
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import ferrum as fm
>>> viz = fm.SHAPWaterfallVisualizer(model, sample_idx=3).fit(X, y)
>>> viz.show()
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
LearningCurveVisualizer ¶
Bases: FerrumVisualizer
Visualize training and cross-validation scores as training size grows.
Wraps learning_curve_chart in the sklearn visualizer protocol.
Call fit(X, y) to run cross-validation across the requested
training-size grid; call show() to retrieve the rendered
Chart. The headline metric final_test_score (mean test score
at the largest training size) is recorded in _metrics and shown
in repr.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Unfitted or fitted sklearn-compatible estimator. |
required |
cv
|
int
|
Number of cross-validation folds passed to
|
5
|
scoring
|
str or callable
|
Sklearn scoring string or callable. Defaults to the estimator's
own |
None
|
train_sizes
|
array - like
|
Relative or absolute training-set sizes to evaluate. Passed
directly to |
None
|
ci_style
|
('band', 'bar')
|
How to render the cross-validation confidence interval.
|
"band"
|
random_state
|
int
|
Seed forwarded to |
None
|
theme
|
Theme
|
Per-chart theme override. Falls back to the global default
when |
None
|
Examples:
>>> import ferrum as fm
>>> from sklearn.linear_model import LogisticRegression
>>> viz = fm.LearningCurveVisualizer(
... LogisticRegression(), cv=5, scoring="accuracy"
... ).fit(X_train, y_train)
>>> chart = viz.show()
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
ValidationCurveVisualizer ¶
Bases: FerrumVisualizer
Visualize train/test scores as a single hyperparameter is swept.
Wraps validation_curve_chart in the sklearn visualizer protocol.
For each value in values, sklearn.model_selection.validation_curve
runs cv folds and records the mean score. The value that
maximises the mean test score is stored as best_param in
_metrics; the corresponding mean score is stored as
best_test_score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Unfitted or fitted sklearn-compatible estimator. |
required |
param
|
str
|
Name of the hyperparameter to sweep, e.g. |
required |
values
|
array - like
|
Grid of candidate values for |
required |
cv
|
int
|
Number of cross-validation folds. |
5
|
scoring
|
str or callable
|
Sklearn scoring string or callable. Defaults to the estimator's
own |
None
|
log_scale
|
bool or 'auto'
|
Whether to render the x-axis (param values) on a log scale.
|
"auto"
|
ci_style
|
('band', 'bar')
|
How to render the cross-validation confidence interval.
|
"band"
|
random_state
|
int
|
Seed forwarded to |
None
|
theme
|
Theme
|
Per-chart theme override. Falls back to the global default
when |
None
|
Examples:
>>> import ferrum as fm
>>> from sklearn.svm import SVC
>>> import numpy as np
>>> viz = fm.ValidationCurveVisualizer(
... SVC(), param="C", values=np.logspace(-3, 3, 7), cv=5
... ).fit(X_train, y_train)
>>> chart = viz.show()
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
CVScoresVisualizer ¶
Bases: FerrumVisualizer
Visualize the distribution of per-fold cross-validation scores.
Wraps cv_scores_chart in the sklearn visualizer protocol. After
fit(X, y), _metrics contains test_mean (mean test-fold
score across all folds) and test_std (standard deviation of
test-fold scores).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Unfitted or fitted sklearn-compatible estimator. |
required |
cv
|
int
|
Number of cross-validation folds. |
5
|
scoring
|
str or callable
|
Sklearn scoring string or callable. Defaults to the estimator's
own |
None
|
kind
|
('box', 'bar', 'strip')
|
Chart geometry used to display the fold-score distributions. |
"box"
|
split
|
('both', 'test', 'train')
|
Which CV splits to include in the chart. |
"both"
|
random_state
|
int
|
Seed forwarded to |
None
|
theme
|
Theme
|
Per-chart theme override. Falls back to the global default
when |
None
|
Examples:
>>> import ferrum as fm
>>> from sklearn.ensemble import RandomForestClassifier
>>> viz = fm.CVScoresVisualizer(
... RandomForestClassifier(n_estimators=100), cv=10, kind="box"
... ).fit(X_train, y_train)
>>> chart = viz.show()
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
AlphaSelectionVisualizer ¶
Bases: FerrumVisualizer
Visualize cross-validated scores over a regularization-strength grid.
Wraps alpha_selection_chart in the sklearn visualizer protocol.
Designed for regularized regressors such as Ridge, Lasso, and
ElasticNet — estimators that expose an alpha hyperparameter
controlling L1/L2 penalty strength. For each value in alphas,
cross-validation produces a mean score; the alpha that maximises the
mean test score is stored as best_alpha in _metrics, and the
corresponding score as best_score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Unfitted regularized regressor with an |
required |
alphas
|
array - like
|
Grid of regularization-strength values to evaluate. Passed
directly to the underlying |
required |
cv
|
int
|
Number of cross-validation folds. |
5
|
scoring
|
str or callable
|
Sklearn scoring string or callable. Defaults to the estimator's
own |
None
|
log_scale
|
bool
|
Whether to render the x-axis (alpha values) on a log scale.
Defaults to |
True
|
highlight_best
|
bool
|
When |
True
|
random_state
|
int
|
Seed forwarded to |
None
|
theme
|
Theme
|
Per-chart theme override. Falls back to the global default
when |
None
|
Examples:
>>> import ferrum as fm
>>> from sklearn.linear_model import Ridge
>>> import numpy as np
>>> viz = fm.AlphaSelectionVisualizer(
... Ridge(), alphas=np.logspace(-4, 4, 40), cv=5
... ).fit(X_train, y_train)
>>> chart = viz.show()
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
SilhouetteVisualizer ¶
Bases: FerrumVisualizer
Rousseeuw silhouette plot for a fitted clusterer.
Computes per-sample silhouette coefficients via ModelSource.silhouette
and renders a horizontal bar chart sorted by cluster, one bar per sample.
Records mean_silhouette — the grand mean silhouette coefficient
averaged across all samples — as the headline metric.
Takes a fitted estimator (not a class); for the k-sweep variant use
ElbowVisualizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Fitted clustering estimator (e.g. |
required |
random_state
|
int
|
Seed forwarded to the underlying |
None
|
theme
|
Theme
|
Per-chart theme override. Falls back to the global default when
|
None
|
Examples:
>>> import ferrum as fm
>>> from sklearn.cluster import KMeans
>>> model = KMeans(n_clusters=3, random_state=0).fit(X)
>>> viz = fm.SilhouetteVisualizer(model).fit(X)
>>> viz.show()
>>> viz._metrics["mean_silhouette"]
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
ElbowVisualizer ¶
Bases: FerrumVisualizer
Elbow / score sweep over a range of k for a clusterer class.
Unlike other ferrum visualizers, ElbowVisualizer takes a model class
(e.g. KMeans) — not a fitted instance — and constructs and fits one
model per k value inside its own fit() override. The ModelSource
round-trip is skipped entirely; per-k models are transient and discarded
after their score is recorded. Renders a score-vs-k line chart.
Records best_k — the integer k whose score is optimal for the
selected metric — as the headline metric. For "distortion" the
optimal score is the minimum; for "silhouette" and
"calinski_harabasz" it is the maximum (higher is better).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_class
|
type
|
Uninstantiated clustering class (e.g. |
required |
ks
|
sequence of int
|
The candidate k values to sweep (e.g. |
required |
metric
|
('distortion', 'silhouette', 'calinski_harabasz')
|
Score to optimize. |
"distortion"
|
random_state
|
int
|
Integer seed passed as |
None
|
theme
|
Theme
|
Per-chart theme override. Falls back to the global default when
|
None
|
Examples:
>>> import ferrum as fm
>>> from sklearn.cluster import KMeans
>>> viz = fm.ElbowVisualizer(KMeans, ks=range(2, 9)).fit(X)
>>> viz.show()
>>> viz._metrics["best_k"]
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
ManifoldVisualizer ¶
Bases: FerrumVisualizer
Low-dimensional manifold-embedding scatter (UMAP / t-SNE / PCA).
Projects the input data to two dimensions via the method selected by
method and renders a point chart with axes dim_0 / dim_1
colored by cluster label. The embedding is computed by
ModelSource.embeddings and cached so _build_chart does not
recompute it.
Takes a fitted clustering estimator whose labels_ attribute is used
to color points. Pass model=None only if you override fit in a
subclass and supply labels_ by other means.
Records n_samples — the number of rows in the embedding — as the
headline metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Fitted clustering estimator (e.g. |
None
|
method
|
str
|
Embedding algorithm forwarded to |
"umap"
|
random_state
|
int
|
Seed forwarded to the underlying |
None
|
theme
|
Theme
|
Per-chart theme override. Falls back to the global default when
|
None
|
Examples:
>>> import ferrum as fm
>>> from sklearn.cluster import KMeans
>>> model = KMeans(n_clusters=4, random_state=0).fit(X)
>>> viz = fm.ManifoldVisualizer(model, method="umap").fit(X)
>>> viz.show()
>>> viz._metrics["n_samples"]
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
InterclusterDistanceVisualizer ¶
Bases: FerrumVisualizer
Cluster-center 2D embedding with cluster-size bubble overlay.
Projects cluster centers into 2D via the algorithm selected by method
and renders a bubble chart where each bubble represents one cluster; bubble
area encodes the cluster's sample count. Built on
ferrum.intercluster_distance_chart.
Takes a fitted clustering estimator that exposes either n_clusters or
cluster_centers_ so the number of clusters can be inferred.
Records max_intercluster_dist — the largest Euclidean distance from any
cluster center to the centroid of all centers in the 2D embedding — as a
rough measure of how spread-out the clusters are.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Fitted clustering estimator (e.g. |
required |
method
|
str
|
Dimensionality-reduction algorithm forwarded to
|
"mds"
|
random_state
|
int
|
Seed forwarded to the underlying |
None
|
theme
|
Theme
|
Per-chart theme override. Falls back to the global default when
|
None
|
Examples:
>>> import ferrum as fm
>>> from sklearn.cluster import KMeans
>>> model = KMeans(n_clusters=5, random_state=0).fit(X)
>>> viz = fm.InterclusterDistanceVisualizer(model).fit(X)
>>> viz.show()
>>> viz._metrics["max_intercluster_dist"]
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
PCAVarianceVisualizer ¶
Bases: FerrumVisualizer
PCA scree plot showing explained variance per principal component.
Retrieves per-component explained-variance ratios via
ModelSource.pca_variance and renders a bar chart of
explained-variance ratio vs. component index, optionally limited to the
first n_components components. Built on ferrum.pca_scree_chart.
Takes a fitted decomposition estimator (e.g. sklearn.decomposition.PCA
instance) that exposes explained_variance_ratio_.
Records first_component_var — the fraction of total variance captured
by the first principal component — as the headline metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Fitted decomposition estimator (e.g. |
required |
n_components
|
int
|
Number of components to display in the scree plot. When |
None
|
random_state
|
int
|
Seed forwarded to the underlying |
None
|
theme
|
Theme
|
Per-chart theme override. Falls back to the global default when
|
None
|
Examples:
>>> import ferrum as fm
>>> from sklearn.decomposition import PCA
>>> model = PCA(n_components=10).fit(X)
>>> viz = fm.PCAVarianceVisualizer(model, n_components=5).fit(X)
>>> viz.show()
>>> viz._metrics["first_component_var"]
fit ¶
Materialize derived data from X / y and build the chart.
Constructs a ModelSource from the wrapped model, calls
_materialize to populate _metrics, then _build_chart to
assemble the ferrum Chart. Returns self for method chaining.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. Accepted types match |
required |
y
|
array - like
|
Target vector. Required by most classification / regression diagnostics; optional for unsupervised variants. |
None
|
Returns:
| Type | Description |
|---|---|
FerrumVisualizer
|
|
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
Rank1DVisualizer ¶
Bases: FerrumVisualizer
Rank features by a univariate statistic and display as a bar chart.
A no-model visualizer (model=None) that computes a scalar score
for each feature column and renders them as a ranked horizontal or
vertical bar chart. fit is overridden directly — the base-class
ModelSource round-trip is bypassed entirely.
Records top_feature_score (the score of the highest-ranked
feature) in _metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm
|
('shapiro', 'variance', 'covariance')
|
Scoring algorithm.
|
"shapiro"
|
orient
|
('horizontal', 'vertical')
|
Bar orientation of the resulting chart. |
"horizontal"
|
top_k
|
int
|
If given, display only the top |
None
|
color_field
|
str
|
Column name forwarded to the chart's color encoding. |
None
|
random_state
|
int
|
Accepted for API symmetry with model-backed visualizers but
intentionally never consumed — this visualizer bypasses
|
None
|
theme
|
Theme
|
Per-chart theme override. Falls back to the global default
when |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Examples:
>>> import ferrum as fm
>>> import polars as pl
>>> df = pl.read_csv("wine.csv")
>>> X, y = df.drop("target"), df["target"]
>>> viz = fm.Rank1DVisualizer(algorithm="variance").fit(X)
>>> viz.show()
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
Rank2DVisualizer ¶
Bases: FerrumVisualizer
Rank feature pairs by pairwise correlation and display as a heatmap.
A no-model visualizer (model=None) that computes an N×N
correlation matrix and renders it as an annotated heatmap. fit
is overridden directly — the base-class ModelSource round-trip is
bypassed entirely.
The "kendall" algorithm routes pairwise computation through
ferrum._core.kendall_tau_b (Rust) for performance.
Records max_abs_corr (the largest absolute off-diagonal
correlation value) in _metrics — useful for detecting
multicollinearity at a glance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm
|
('pearson', 'spearman', 'kendall', 'covariance')
|
Pairwise association measure.
|
"pearson"
|
annot
|
bool
|
Whether to annotate each heatmap cell with its numeric value. |
True
|
random_state
|
int
|
Accepted for API symmetry with model-backed visualizers but
intentionally never consumed — this visualizer bypasses
|
None
|
theme
|
Theme
|
Per-chart theme override. Falls back to the global default
when |
None
|
Examples:
>>> import ferrum as fm
>>> import polars as pl
>>> df = pl.read_csv("wine.csv")
>>> X = df.drop("target")
>>> viz = fm.Rank2DVisualizer(algorithm="spearman").fit(X)
>>> viz.show()
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
ParallelCoordinatesVisualizer ¶
Bases: FerrumVisualizer
Visualize multivariate samples as a parallel-coordinates chart.
A no-model visualizer (model=None) that draws one polyline per
sample across a set of parallel vertical axes (one per feature).
fit is overridden directly — the base-class ModelSource
round-trip is bypassed entirely.
Records n_samples and n_features in _metrics so the
repr surfaces the chart's shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
list of str
|
Subset of column names to include as axes. When |
None
|
hue
|
str
|
Column name used to color-encode each sample line. |
None
|
rescale
|
('minmax', 'zscore', None)
|
Per-axis normalization applied before plotting.
|
"minmax"
|
alpha
|
float
|
Opacity of each sample line (0 = fully transparent, 1 = opaque). |
0.5
|
random_state
|
int
|
Accepted for API symmetry with model-backed visualizers but
intentionally never consumed — this visualizer bypasses
|
None
|
theme
|
Theme
|
Per-chart theme override. Falls back to the global default
when |
None
|
Examples:
>>> import ferrum as fm
>>> import polars as pl
>>> df = pl.read_csv("iris.csv")
>>> viz = fm.ParallelCoordinatesVisualizer(hue="species", rescale="minmax")
>>> viz.fit(df.drop("species"), df["species"])
>>> viz.show()
score ¶
Returns 0.0 for visualizers that do not compute a test-set score.
Subclasses that wrap a fitted estimator override this to return an
appropriate metric (e.g. roc_auc_score for ROCVisualizer,
r2_score for ResidualsVisualizer). The base implementation
returns 0.0 so that no-model / exploratory visualizers satisfy
the sklearn visualizer protocol without raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix, same type accepted by |
required |
y
|
array - like
|
True target values. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
show ¶
Return the ferrum Chart for this visualizer.
Must be called after fit; raises RuntimeError otherwise.
The returned Chart can be rendered in a notebook (_repr_svg_),
saved with .save(path), or composed with other charts via +
/ /.
Returns:
| Type | Description |
|---|---|
Chart
|
The assembled diagnostic chart. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
X ¶
Bases: ChannelBase
Positional X channel — maps a field to the horizontal axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name in the input DataFrame. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type: quantitative, nominal, ordinal, temporal. Inferred from the column dtype when omitted. |
"Q"
|
bin
|
bool or Bin
|
If truthy, bin the field before mapping. Pass a |
required |
aggregate
|
str
|
Aggregation operation applied before mapping (e.g. |
required |
scale
|
Scale
|
Explicit scale override (e.g. |
required |
title
|
str
|
Axis title override. When omitted the field name is used. |
required |
Notes
axis, legend, sort, stack, and impute kwargs are
accepted and forwarded to the EncodingSpec; per-channel axis/legend
customization depends on Rust-side support for the channel.
Examples:
Y ¶
Bases: ChannelBase
Positional Y channel — maps a field to the vertical axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name in the input DataFrame. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type: quantitative, nominal, ordinal, temporal. Inferred from the column dtype when omitted. |
"Q"
|
bin
|
bool or Bin
|
If truthy, bin the field before mapping. Pass a |
required |
aggregate
|
str
|
Aggregation operation applied before mapping (e.g. |
required |
scale
|
Scale
|
Explicit scale override (e.g. |
required |
title
|
str
|
Axis title override. When omitted the field name is used. |
required |
Notes
axis, legend, sort, stack, and impute kwargs are
accepted and forwarded to the EncodingSpec; per-channel axis/legend
customization depends on Rust-side support for the channel.
Examples:
X2 ¶
Bases: ChannelBase
Secondary X channel — maps a field to the second x position.
Used for ranged marks (rule, rect, ribbon) where a mark spans
from x to x2 along the horizontal axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name in the input DataFrame. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
Notes
bin, aggregate, scale, and title kwargs are accepted but
are reserved for future use (no-op today) — they trigger a one-time
deprecation warning.
Examples:
Y2 ¶
Bases: ChannelBase
Secondary Y channel — maps a field to the second y position.
Used for ranged marks (rule, rect, ribbon) where a mark spans
from y to y2 along the vertical axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name in the input DataFrame. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
Notes
bin, aggregate, scale, and title kwargs are accepted but
are reserved for future use (no-op today) — they trigger a one-time
deprecation warning.
Examples:
XError ¶
Bases: ChannelBase
X-axis error channel — maps a field to symmetric error around x.
The error bar extends x ± x_error along the horizontal axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name whose values are the error magnitude. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
Notes
Other kwargs are accepted but are reserved for future use (no-op today) — they trigger a one-time deprecation warning.
Examples:
YError ¶
Bases: ChannelBase
Y-axis error channel — maps a field to symmetric error around y.
The error bar extends y ± y_error along the vertical axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name whose values are the error magnitude. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
Notes
Other kwargs are accepted but are reserved for future use (no-op today) — they trigger a one-time deprecation warning.
Examples:
XError2 ¶
Bases: ChannelBase
Secondary x-axis error channel — for asymmetric error bounds.
When paired with XError, sets the upper bound of the error bar
independently of the lower bound, enabling asymmetric error bars.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name whose values are the upper-side error magnitude. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
Notes
Other kwargs are accepted but are reserved for future use (no-op today) — they trigger a one-time deprecation warning.
Examples:
YError2 ¶
Bases: ChannelBase
Secondary y-axis error channel — for asymmetric error bounds.
When paired with YError, sets the upper bound of the error bar
independently of the lower bound, enabling asymmetric error bars.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name whose values are the upper-side error magnitude. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
Notes
Other kwargs are accepted but are reserved for future use (no-op today) — they trigger a one-time deprecation warning.
Examples:
Theta ¶
Bases: ChannelBase
Polar angle channel — maps a field to the angular position in polar coords.
Typically used with arc or pie marks; the field values determine the sweep angle of each arc segment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name in the input DataFrame. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
stack
|
bool or str
|
Stacking behaviour for arc segments. |
required |
Notes
Requires CoordPolar() on the chart to activate polar rendering;
without it the channel is registered but the mark renders in Cartesian
space.
Other kwargs are accepted but are reserved for future use (no-op today) — they trigger a one-time deprecation warning.
Examples:
Radius ¶
Bases: ChannelBase
Polar radius channel — maps a field to the radial position in polar coords.
Controls how far each mark is placed from the center of the polar plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name in the input DataFrame. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
Notes
Requires CoordPolar() on the chart to activate polar rendering;
without it the channel is registered but the mark renders in Cartesian
space.
Other kwargs are accepted but are reserved for future use (no-op today) — they trigger a one-time deprecation warning.
Examples:
Color ¶
Bases: ChannelBase
Color encoding channel — maps a field to mark color (fill and stroke).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name to map to color. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type: quantitative, nominal, ordinal, temporal. Inferred from the column dtype when omitted. |
"Q"
|
scheme
|
str
|
Named color scheme for categorical data (e.g. |
required |
scale
|
Scale
|
Explicit scale override (e.g. |
required |
title
|
str
|
Legend title override. When omitted the field name is used. |
required |
Notes
legend is honored: passing legend={"disabled": True},
legend=None, or legend=False suppresses the color legend in the
rendered SVG. sort is honored: pass a list of strings to set the
explicit domain order for the color scale. condition is accepted but
reserved for future use.
Examples:
Fill ¶
Bases: ChannelBase
Fill color channel — maps a field to filled-mark fill color.
Distinct from stroke, which controls only the outline color. When
both Fill and Color are encoded, Fill takes precedence for the
interior of the mark.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name to map to fill color. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
Notes
scale, title, legend, and condition kwargs are accepted
but are reserved for future use (no-op today) — they trigger a one-time
deprecation warning.
Examples:
Stroke ¶
Bases: ChannelBase
Stroke color channel — maps a field to mark stroke (outline) color.
Distinct from fill, which controls only the interior color.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name to map to stroke color. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
Notes
scale, title, legend, and condition kwargs are accepted
but are reserved for future use (no-op today) — they trigger a one-time
deprecation warning.
Examples:
Opacity ¶
Bases: ChannelBase
Opacity channel — maps a field to overall mark opacity.
Controls both fill and stroke opacity simultaneously. Values are mapped
to the range [0, 1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name to map to opacity. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
scale
|
Scale
|
Explicit scale override. |
required |
title
|
str
|
Legend title override. |
required |
Notes
legend and condition kwargs are accepted but are reserved for
future use (no-op today) — they trigger a one-time deprecation warning.
Examples:
FillOpacity ¶
Bases: ChannelBase
Fill-opacity channel — maps a field to fill opacity.
Independent of stroke opacity; controls only how transparent the interior
of a mark is. Values are mapped to the range [0, 1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name to map to fill opacity. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
Notes
scale, title, legend, and condition kwargs are accepted
but are reserved for future use (no-op today) — they trigger a one-time
deprecation warning.
Examples:
StrokeOpacity ¶
Bases: ChannelBase
Stroke-opacity channel — maps a field to stroke opacity.
Independent of fill opacity; controls only how transparent the outline of
a mark is. Values are mapped to the range [0, 1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name to map to stroke opacity. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
Notes
scale, title, legend, and condition kwargs are accepted
but are reserved for future use (no-op today) — they trigger a one-time
deprecation warning.
Examples:
StrokeWidth ¶
Bases: ChannelBase
Stroke-width channel — maps a field to stroke width in pixels.
Larger values produce thicker mark outlines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name to map to stroke width. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
Notes
scale, title, legend, and condition kwargs are accepted
but are reserved for future use (no-op today) — they trigger a one-time
deprecation warning.
Examples:
StrokeDash ¶
Bases: ChannelBase
Stroke-dash channel — maps a field to a dash pattern.
Each level of the field maps to a distinct dash-gap pattern for the mark stroke (e.g. solid, dashed, dotted).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name (typically nominal or ordinal) to map to dash pattern. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
Notes
scale, title, legend, and condition kwargs are accepted
but are reserved for future use (no-op today) — they trigger a one-time
deprecation warning.
Examples:
Size ¶
Bases: ChannelBase
Size channel — maps a field to mark size (point area in square pixels).
For point marks the size value corresponds to the area of the mark in square pixels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name to map to size. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
scale
|
Scale
|
Explicit scale override. |
required |
title
|
str
|
Legend title override. |
required |
Notes
legend and condition kwargs are accepted but are reserved for
future use (no-op today) — they trigger a one-time deprecation warning.
Examples:
Shape ¶
Bases: ChannelBase
Shape channel — maps a categorical field to point shape.
Supported shapes include "circle", "square", "triangle",
"cross", "diamond", and "star".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name (should be nominal or ordinal) to map to shape. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted; |
"Q"
|
scale
|
Scale
|
Explicit scale override. |
required |
title
|
str
|
Legend title override. |
required |
Notes
legend and condition kwargs are accepted but are reserved for
future use (no-op today) — they trigger a one-time deprecation warning.
Examples:
Angle ¶
Bases: ChannelBase
Angle channel — maps a field to mark rotation in degrees.
Rotates each mark around its center point. A value of 0 is
upright; values increase clockwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name to map to rotation angle. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
Notes
scale, title, legend, and condition kwargs are accepted
but are reserved for future use (no-op today) — they trigger a one-time
deprecation warning.
Examples:
Text ¶
Bases: ChannelBase
Text channel — maps a field to text-mark content.
Renders each data point's field value as a text label. Primarily used
with the mark_text mark.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name whose values are rendered as text. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
format
|
str
|
Number or date format string (e.g. |
required |
formatType
|
str
|
Format type hint; |
required |
Notes
Other kwargs are accepted but are reserved for future use (no-op today) — they trigger a one-time deprecation warning.
Examples:
Detail ¶
Bases: ChannelBase
Detail channel — adds a field to the encoding without a visual variable.
Groups marks by the levels of the field without mapping those levels to any visual property (color, size, shape, etc.). Useful for drawing one line per group in a line chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name to group by. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
Notes
Other kwargs are accepted but are reserved for future use (no-op today) — they trigger a one-time deprecation warning.
Examples:
Tooltip ¶
Bases: ChannelBase
Tooltip channel — specifies which fields appear in the hover tooltip.
Accepts one or more field names (as strings or TooltipField helpers)
that are shown when the viewer hovers over a mark in an interactive
renderer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*fields
|
str or TooltipField
|
One or more column names or |
()
|
Notes
type kwarg is accepted but is reserved for future use (no-op today)
— it triggers a one-time deprecation warning.
Examples:
TooltipField ¶
Bases: ChannelBase
Helper for an individual tooltip field with optional title and format.
Used inside Tooltip(*fields) to customise how a single column is
displayed in the hover tooltip. Not used as a top-level encoding channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
title
|
str
|
Custom tooltip label for this field. |
required |
format
|
str
|
Number or date format string (e.g. |
required |
formatType
|
str
|
Format type hint; |
required |
Notes
Other kwargs are accepted but are reserved for future use (no-op today) — they trigger a one-time deprecation warning.
Examples:
Href ¶
Bases: ChannelBase
URL-link channel — maps a field to a clickable URL.
When the chart is rendered in an interactive renderer, marks become
clickable hyperlinks pointing to the URL stored in field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name containing the URL string for each mark. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
Notes
Other kwargs are accepted but are reserved for future use (no-op today) — they trigger a one-time deprecation warning. Interactive renderers only; SVG export does not embed hyperlinks.
Examples:
Description ¶
Bases: ChannelBase
Accessibility description channel — maps a field to per-mark alt text.
The description text is used by screen readers and other accessibility tools to describe each individual mark.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name whose values are used as the accessibility description. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
Notes
Other kwargs are accepted but are reserved for future use (no-op today) — they trigger a one-time deprecation warning.
Examples:
Key ¶
Bases: ChannelBase
Key channel — maps a field to a unique key per mark.
Provides a stable identity for each mark when joining across data updates (e.g. animated transitions or streaming data).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name whose values uniquely identify each mark. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted. |
"Q"
|
Notes
Other kwargs are accepted but are reserved for future use (no-op today) — they trigger a one-time deprecation warning.
Examples:
Url ¶
Bases: ChannelBase
Image URL channel — maps a field to a base64 data URL for mark_image tiles.
Each row provides a data:image/...;base64,<payload> URL that is
placed as an image tile at the position given by the x and y
encodings. Used exclusively with :meth:~ferrum.Chart.mark_image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name containing the base64 data URL for each tile. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted (typically
|
"Q"
|
Examples:
Facet ¶
Bases: ChannelBase
Facet channel — splits a chart into a grid by levels of a field.
Wraps the chart into a faceted layout where each panel shows data for
one level of the facet field. Pass this channel object to
Chart.encode(facet=...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name to facet by. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted; |
"Q"
|
title
|
str
|
Facet panel title override. When omitted the field name is used. |
required |
Notes
columns (number of facets per row) is accepted as a kwarg but is
reserved for future use (no-op today) — it triggers a one-time
deprecation warning. If you need column-wrap control today, use
Chart.facet(ncols=N) directly.
Examples:
FacetRow ¶
Bases: ChannelBase
Facet-row channel — splits a chart into rows by levels of a field.
Pass this channel object to Chart.encode(facet_row=...) to create a
row-faceted layout where each row shows data for one level of the field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name to facet rows by. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted; |
"Q"
|
title
|
str
|
Row-facet title override. When omitted the field name is used. |
required |
Notes
Other kwargs are accepted but are reserved for future use (no-op today) — they trigger a one-time deprecation warning.
Examples:
FacetCol ¶
Bases: ChannelBase
Facet-column channel — splits a chart into columns by levels of a field.
Pass this channel object to Chart.encode(facet_col=...) to create a
column-faceted layout where each column shows data for one level of the
field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Column name to facet columns by. |
None
|
type_
|
('Q', 'N', 'O', 'T')
|
Data type. Inferred from the column dtype when omitted; |
"Q"
|
title
|
str
|
Column-facet title override. When omitted the field name is used. |
required |
Notes
Other kwargs are accepted but are reserved for future use (no-op today) — they trigger a one-time deprecation warning.
Examples:
compute_layout ¶
compute_layout(spec, *, viewport: tuple[float, float], x_tick_labels: list[str], y_tick_labels: list[str], x_title: str | None = None, y_title: str | None = None, facet_groups: list[tuple[str, str, int]] | None = None, legend_entries: list[tuple[str, str]] | None = None, legend_orient: str = 'right', label_angle: float | None = None) -> dict
process_batch ¶
render_png ¶
render_svg ¶
compose_svg_horizontal ¶
compose_svg_vertical ¶
compose_svg_grid ¶
continuous_palette ¶
Look up a built-in continuous colormap by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
('viridis', 'plasma', 'magma', 'inferno', 'cividis')
|
Built-in colormap name. |
"viridis"
|
Returns:
| Type | Description |
|---|---|
ContinuousScheme
|
A ferrum continuous scheme suitable for |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
set_default_theme ¶
Set the process-default theme for all subsequent charts.
The returned object is a context manager. Use it with with to scope
the default to a block (previous default is restored on __exit__).
Fire-and-forget usage (without with) is also supported.
Per-chart Chart.theme(t) always overrides this process default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theme
|
Theme
|
Theme to install as the process default. |
required |
Returns:
| Type | Description |
|---|---|
AbstractContextManager
|
Context manager that restores the prior default on |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Examples:
Fire-and-forget:
Scoped to a block:
get_default_theme ¶
Return the current process-default theme.
Returns:
| Type | Description |
|---|---|
Theme
|
The currently active process-default theme. Starts as
|
Examples:
theme_context ¶
Scope a theme to a with block — alias for set_default_theme().
Prefer this spelling over set_default_theme() when the intent is
always context-manager usage (e.g. in tests or notebook cells).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theme
|
Theme
|
Theme to activate for the duration of the |
required |
Returns:
| Type | Description |
|---|---|
AbstractContextManager
|
Context manager; restores the prior default on |
Examples:
annotate_hline ¶
annotate_hline(y: float, *, label: Optional[str] = None, stroke: Optional[str] = None, stroke_dash=None) -> Chart
Horizontal reference line at a fixed y position.
Returns a single-mark Chart suitable for | / & concatenation
composition; for true overlay/layer, use + with a chart that shares
the same DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
float
|
Y position of the line in data coordinates. |
required |
label
|
str
|
Reserved for future use (no-op today). |
None
|
stroke
|
str
|
Line color as a CSS color string. Defaults to the mark default when omitted. |
None
|
stroke_dash
|
list of float
|
SVG dash array, e.g. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Annotation chart suitable for |
Examples:
annotate_vline ¶
annotate_vline(x: float, *, label: Optional[str] = None, stroke: Optional[str] = None, stroke_dash=None) -> Chart
Vertical reference line at a fixed x position.
Returns a single-mark Chart suitable for | / & concatenation
composition; for true overlay/layer, use + with a chart that shares
the same DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
X position of the line in data coordinates. |
required |
label
|
str
|
Reserved for future use (no-op today). |
None
|
stroke
|
str
|
Line color as a CSS color string. |
None
|
stroke_dash
|
list of float
|
SVG dash array, e.g. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Annotation chart suitable for |
Examples:
annotate_rect ¶
annotate_rect(x1: float, x2: float, y1: float, y2: float, *, fill: Optional[str] = None, opacity: float = 0.1, label: Optional[str] = None) -> Chart
Shaded rectangle region spanning (x1, y1) to (x2, y2).
Returns a mark_rect annotation chart for | / & concatenation
composition; for true overlay/layer, use + with a chart that shares
the same DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1
|
float
|
Left x boundary in data coordinates. |
required |
x2
|
float
|
Right x boundary in data coordinates. |
required |
y1
|
float
|
Bottom y boundary in data coordinates. |
required |
y2
|
float
|
Top y boundary in data coordinates. |
required |
fill
|
str
|
Fill color as a CSS color string. |
None
|
opacity
|
float
|
Fill opacity in |
0.1
|
label
|
str
|
Reserved for future use (no-op today). |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Annotation chart suitable for |
Examples:
annotate_text ¶
annotate_text(x: float, y: float, text: str, *, dx: float = 0, dy: float = 0, align: str = 'center', baseline: str = 'middle', font_size: Optional[float] = None, color: Optional[str] = None, angle: Optional[float] = None) -> Chart
Free-floating text annotation at a fixed (x, y) position.
Returns a mark_text chart for | / & concatenation composition;
for true overlay/layer, use + with a chart that shares the same
DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
X position in data coordinates. |
required |
y
|
float
|
Y position in data coordinates. |
required |
text
|
str
|
Text string to display. |
required |
dx
|
float
|
Horizontal pixel offset from |
0
|
dy
|
float
|
Vertical pixel offset from |
0
|
align
|
str
|
Horizontal text alignment (SVG |
"center"
|
baseline
|
str
|
Vertical text baseline: |
"middle"
|
font_size
|
float
|
Font size in points. |
None
|
color
|
str
|
Text fill color as a CSS color string. |
None
|
angle
|
float
|
Rotation angle in degrees (clockwise). |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Annotation chart suitable for |
Examples:
annotate_arrow ¶
annotate_arrow(x1: float, y1: float, x2: float, y2: float, *, label: Optional[str] = None, label_side: str = 'start', stroke: Optional[str] = None) -> Chart
Draw an arrow from (x1, y1) to (x2, y2) with an optional text label.
Composes a mark_segment (the arrow shaft) with an optional
annotate_text placed at the label_side endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1
|
float
|
Horizontal data coordinate of the arrow start. |
required |
y1
|
float
|
Vertical data coordinate of the arrow start. |
required |
x2
|
float
|
Horizontal data coordinate of the arrow end (tip). |
required |
y2
|
float
|
Vertical data coordinate of the arrow end (tip). |
required |
label
|
str
|
Text to display alongside the arrow. When omitted, no text is rendered. |
None
|
label_side
|
('start', 'end')
|
Which end of the arrow to place the label. |
"start"
|
stroke
|
str
|
Hex colour string for the arrow line (e.g. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Layered chart containing the arrow segment and, when label is provided, the annotation text. |
Examples:
Simple unlabelled arrow:
Arrow with a label at the tip:
selection_point ¶
selection_point(*, fields: list[str] | None = None, encodings: list[str] | None = None, nearest: bool = False, toggle: str = 'event.shiftKey', on: str = 'click', clear: str = 'mouseout', resolve: Literal['global', 'union', 'intersect'] = 'global', name: str | None = None) -> Selection
Create a point selection activated by clicking on marks.
A point selection highlights individual marks. Shift-click adds to the
selection by default (toggle="event.shiftKey"). Use
selection_single to disable toggle, or selection_multi to keep
the shift-click default explicitly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
list of str
|
Data fields to project the selection onto. When omitted the selection binds to all fields. |
None
|
encodings
|
list of str
|
Encoding channels to project onto (e.g. |
None
|
nearest
|
bool
|
When |
False
|
toggle
|
str
|
JavaScript event expression controlling when clicking adds to the
selection instead of replacing it. Pass |
"event.shiftKey"
|
on
|
str
|
Event that triggers the selection (e.g. |
"click"
|
clear
|
str
|
Event that clears the selection. |
"mouseout"
|
resolve
|
('global', 'union', 'intersect')
|
How to resolve this selection when the chart is faceted. |
"global"
|
name
|
str
|
Stable identifier for the selection. Auto-generated when omitted. |
None
|
Returns:
| Type | Description |
|---|---|
Selection
|
Immutable selection descriptor. Pass to |
Examples:
Highlight selected marks by colour:
>>> import ferrum as fm
>>> sel = fm.selection_point()
>>> fm.Chart(df).mark_point().encode(
... x=fm.X("x"), y=fm.Y("y"),
... color=sel.when(fm.Color("category")).otherwise(fm.value("#cccccc")),
... ).add_selection(sel)
Nearest-mark selection on mouse-over:
selection_interval ¶
selection_interval(*, fields: list[str] | None = None, encodings: list[str] | None = None, translate: bool = True, zoom: bool = True, mark: SelectionMark | None = None, resolve: Literal['global', 'union', 'intersect'] = 'global', name: str | None = None) -> Selection
Create an interval (brush) selection activated by dragging.
An interval selection lets the user drag a rectangular brush over the
chart. All marks inside the brush are considered selected. The brush
supports panning (translate=True) and scroll-to-zoom (zoom=True)
after it is drawn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
list of str
|
Data fields to project the brush onto. When omitted the brush applies to all fields represented by the brushed encodings. |
None
|
encodings
|
list of str
|
Encoding channels to constrain the brush to (e.g. |
None
|
translate
|
bool
|
Allow the user to reposition the brush by dragging inside it. |
True
|
zoom
|
bool
|
Allow the user to scroll inside the brush to zoom the view. |
True
|
mark
|
SelectionMark
|
Visual style of the brush rectangle. Defaults to a semi-transparent blue fill with a solid grey border. |
None
|
resolve
|
('global', 'union', 'intersect')
|
How to resolve this selection when the chart is faceted. |
"global"
|
name
|
str
|
Stable identifier for the selection. Auto-generated when omitted. |
None
|
Returns:
| Type | Description |
|---|---|
Selection
|
Immutable selection descriptor. Pass to |
Examples:
Brush that greys out unselected points:
>>> import ferrum as fm
>>> brush = fm.selection_interval()
>>> fm.Chart(df).mark_point().encode(
... x=fm.X("x"), y=fm.Y("y"),
... color=brush.when(fm.Color("category")).otherwise(fm.value("#cccccc")),
... ).add_selection(brush)
Horizontal-only brush:
Custom brush style:
value ¶
Wrap a literal value for use in conditional encodings.
Returns an opaque literal wrapper that can be passed as the
if_selected or if_not argument of
sel.when(...).otherwise(...) when a constant (rather than a field
mapping) is needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
str, int, or float
|
The constant to embed. Hex colour strings (e.g. |
required |
Returns:
| Type | Description |
|---|---|
_LiteralValue
|
Opaque wrapper consumed by |
Examples:
Grey-out unselected marks:
>>> import ferrum as fm
>>> sel = fm.selection_point()
>>> fm.Chart(df).mark_point().encode(
... x=fm.X("x"), y=fm.Y("y"),
... color=sel.when(fm.Color("category")).otherwise(fm.value("#cccccc")),
... ).add_selection(sel)
Fade unselected marks with low opacity:
residuals_chart ¶
residuals_chart(model: Any = None, X: Any = None, y: Any = None, *, y_true: Any = None, y_pred: Any = None, kind: str = 'studentized', cook_threshold: float | str | None = None, panels: Any = 'auto', annotate_metrics: bool = True, subtitle: str | None = None, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Residuals diagnostic chart for a regression estimator.
Plots residuals vs. fitted values. Optional Cook's distance
highlighting marks observations whose leverage-adjusted influence
exceeds a user-supplied threshold. panels="auto" returns the
canonical 4-panel diagnostic layout (residuals-vs-fitted, QQ,
scale-location, residuals-vs-leverage) as a 2x2 grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator or ModelSource
|
A fitted sklearn-compatible regression estimator, an explicit
|
None
|
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
Target vector. Required when |
None
|
y_true
|
array - like
|
Ground-truth target values for the precomputed path. Must be
paired with |
None
|
y_pred
|
array - like
|
Predicted target values for the precomputed path. |
None
|
kind
|
('studentized', 'raw')
|
Residual type to plot on the y axis. |
"studentized"
|
cook_threshold
|
float, "auto", or None
|
Threshold for Cook's distance outlier highlighting. A float is
used as an absolute cutoff; |
None
|
panels
|
"auto", None, "single", or list of str
|
Panel selection. |
"auto"
|
annotate_metrics
|
bool
|
Overlay a top-right corner annotation showing R^2/RMSE/MAE
computed from the fit. Pass |
True
|
subtitle
|
str or None
|
Optional subtitle rendered beneath the active chart title. |
None
|
random_state
|
int or None
|
Seed forwarded to |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Residuals-vs-fitted scatter chart with optional Cook's-distance outlier overlay. |
Examples:
>>> import ferrum as fm
>>> from sklearn.linear_model import Ridge
>>> fm.residuals_chart(Ridge().fit(X_train, y_train), X_test, y_test)
Precomputed path — residuals are computed as y_true − y_pred internally.
Leverage and Cook's distance are unavailable, so the leverage panel is
omitted when panels="auto":
prediction_error_chart ¶
prediction_error_chart(model: Any = None, X: Any = None, y: Any = None, *, y_true: Any = None, y_pred: Any = None, reference_line: bool = True, ci: float | None = None, reference_band: bool = False, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Actual-vs-predicted scatter for a regression estimator.
Plots y_true on the y axis against y_pred on the x axis with
an optional reference line (y = x diagonal) and an optional
residual-based confidence ribbon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator or ModelSource
|
A fitted sklearn-compatible regression estimator, an explicit
|
None
|
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
Target vector. Required when |
None
|
y_true
|
array - like
|
Pre-computed true labels. Use with |
None
|
y_pred
|
array - like
|
Pre-computed predictions. Use with |
None
|
reference_line
|
bool
|
Overlay the dashed |
True
|
ci
|
float or None
|
Confidence level in |
None
|
reference_band
|
bool
|
When |
False
|
random_state
|
int or None
|
Seed forwarded to |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Actual-vs-predicted scatter with optional reference line and confidence ribbon. |
Examples:
cooks_distance_chart ¶
cooks_distance_chart(model: Any = None, X: Any = None, y: Any = None, *, threshold: float | str | None = None, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Cook's distance / residuals-vs-leverage diagnostic for a linear estimator.
Renders the residuals-vs-leverage panel with optional Cook's-distance outlier highlighting. Useful for identifying influential observations in a linear regression fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator or ModelSource
|
A fitted sklearn-compatible regression estimator that exposes
|
None
|
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
Target vector. Required when |
None
|
threshold
|
float, "auto", or None
|
Cook's-distance threshold for outlier highlighting. A float is
used as an absolute cutoff; |
None
|
random_state
|
int or None
|
Seed forwarded to |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Residuals-vs-leverage panel with optional Cook's-distance outlier overlay. |
Examples:
roc_chart ¶
roc_chart(model: Any = None, X: Any = None, y: Any = None, *, y_true: Any = None, y_pred: Any = None, per_class: bool = True, average: str | None = 'macro', annotate_auc: bool = True, subtitle: str | None = None, compare: dict[str, Any] | None = None, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
ROC curve chart for a classifier.
Plots true-positive rate vs. false-positive rate, one curve per
class (default) or a single macro/micro/weighted-averaged curve.
Supports multi-model comparison via compare=.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator, ModelSource, or dict of str -> estimator
|
Fitted sklearn-compatible classifier, an explicit
|
None
|
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
True class labels. Required when |
None
|
y_true
|
array - like
|
Ground-truth class labels for the precomputed path. Must be
paired with |
None
|
y_pred
|
array - like
|
Soft scores / probabilities for the precomputed path. 1-D for
binary classifiers (positive-class scores); 2-D
|
None
|
per_class
|
bool
|
When |
True
|
average
|
('macro', 'micro', 'weighted')
|
Averaging method used when |
"macro"
|
annotate_auc
|
bool
|
When |
True
|
subtitle
|
str or None
|
Optional subtitle rendered beneath the active chart title. |
None
|
compare
|
dict of str -> estimator or None
|
Additional estimators to overlay. Keys become model labels.
|
None
|
random_state
|
int or None
|
Seed forwarded to |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
ROC curve chart with one line per class (or averaged curve). |
Examples:
>>> import ferrum as fm
>>> from sklearn.linear_model import LogisticRegression
>>> fm.roc_chart(LogisticRegression().fit(X_train, y_train), X_test, y_test)
Precomputed path — bypass the model entirely:
pr_chart ¶
pr_chart(model: Any = None, X: Any = None, y: Any = None, *, y_true: Any = None, y_pred: Any = None, per_class: bool = True, average: str | None = 'macro', annotate_ap: bool = True, iso_lines: bool = False, subtitle: str | None = None, compare: dict[str, Any] | None = None, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Precision-recall curve chart for a classifier.
Plots precision vs. recall, one curve per class (default) or a single
averaged curve. Both axes are pinned to [0, 1.05] so curves
render against the full precision-recall space (same convention as
sklearn and yellowbrick). Supports multi-model comparison via
compare=.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator, ModelSource, or dict of str -> estimator
|
Fitted sklearn-compatible classifier, an explicit
|
None
|
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
True class labels. Required when |
None
|
y_true
|
array - like
|
Ground-truth class labels for the precomputed path. Must be
paired with |
None
|
y_pred
|
array - like
|
Soft scores / probabilities for the precomputed path. 1-D for
binary classifiers (positive-class scores); 2-D
|
None
|
per_class
|
bool
|
When |
True
|
average
|
('macro', 'micro', 'weighted')
|
Averaging method used when |
"macro"
|
annotate_ap
|
bool
|
When |
True
|
iso_lines
|
bool
|
When |
False
|
subtitle
|
str or None
|
Optional subtitle rendered beneath the active chart title. |
None
|
compare
|
dict of str -> estimator or None
|
Additional estimators to overlay. Keys become model labels.
|
None
|
random_state
|
int or None
|
Seed forwarded to |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Precision-recall curve chart with one line per class (or an averaged summary curve). |
Examples:
>>> import ferrum as fm
>>> from sklearn.linear_model import LogisticRegression
>>> fm.pr_chart(LogisticRegression().fit(X_train, y_train), X_test, y_test)
Precomputed path:
calibration_chart ¶
calibration_chart(model: Any = None, X: Any = None, y: Any = None, *, y_true: Any = None, y_pred: Any = None, n_bins: int = 10, strategy: str = 'uniform', annotate_brier: bool = True, subtitle: str | None = None, compare: dict[str, Any] | None = None, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Calibration (reliability) curve for one or more classifiers.
Plots mean predicted probability vs. fraction of positives in each
bin, following sklearn's calibration_curve convention. Supports
multi-model comparison via compare=.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator, ModelSource, or dict of str -> estimator
|
Fitted sklearn-compatible classifier, an explicit
|
None
|
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
True binary labels. Required when |
None
|
y_true
|
array - like
|
Ground-truth class labels for the precomputed path. Must be
paired with |
None
|
y_pred
|
array - like
|
Soft scores / probabilities for the precomputed path. 1-D for
binary classifiers (positive-class scores); 2-D
|
None
|
n_bins
|
int
|
Number of probability bins for the reliability diagram. |
10
|
strategy
|
('uniform', 'quantile')
|
Binning strategy forwarded to |
"uniform"
|
annotate_brier
|
bool
|
When |
True
|
subtitle
|
str or None
|
Optional one-line subtitle drawn beneath the chart title. |
None
|
compare
|
dict of str -> estimator or None
|
Additional estimators to overlay. Keys become model labels.
|
None
|
random_state
|
int or None
|
Seed forwarded to |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Reliability diagram with one curve per model plus a perfect- calibration diagonal reference. |
Examples:
>>> import ferrum as fm
>>> from sklearn.linear_model import LogisticRegression
>>> fm.calibration_chart(LogisticRegression().fit(X_train, y_train), X_test, y_test)
Precomputed path (y_pred = 1-D predicted probabilities for positive class):
gain_chart ¶
gain_chart(model: Any = None, X: Any = None, y: Any = None, *, y_true: Any = None, y_pred: Any = None, compare: dict[str, Any] | None = None, subtitle: str | None = None, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Cumulative-gain curve for a classifier.
Plots the fraction of positive cases captured vs. the fraction of
samples scored, one curve per class. Useful for evaluating the
benefit of targeting a top-ranked subset. The categorical legend
is replaced with endpoint-anchored direct labels -- unconditional,
matching the learning_curve / validation_curve / lift sibling
figures (Schwabish C8 audit-rework, 2026-05-12). Use
Chart(df).mark_gain(...) directly to keep the legend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator or ModelSource
|
Fitted sklearn-compatible classifier or an explicit
|
None
|
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
True class labels. Required when |
None
|
y_true
|
array - like
|
Ground-truth class labels for the precomputed path. Must be
paired with |
None
|
y_pred
|
array - like
|
Soft scores / probabilities for the precomputed path. 1-D for
binary classifiers (positive-class scores); 2-D
|
None
|
compare
|
dict[str, estimator] or None
|
Multi-model overlay. Keys are display names; values are fitted
estimators. Routes through |
None
|
subtitle
|
str or None
|
Optional subtitle rendered beneath the active chart title. |
None
|
random_state
|
int or None
|
Seed forwarded to |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Cumulative-gain curve with one line per class. |
Examples:
>>> import ferrum as fm
>>> from sklearn.linear_model import LogisticRegression
>>> fm.gain_chart(LogisticRegression().fit(X_train, y_train), X_test, y_test)
Precomputed path (y_pred = soft scores, 1-D binary or 2-D multiclass):
lift_chart ¶
lift_chart(model: Any = None, X: Any = None, y: Any = None, *, y_true: Any = None, y_pred: Any = None, compare: dict[str, Any] | None = None, subtitle: str | None = None, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Lift curve for a classifier.
Plots the ratio of positive-hit rate in the scored top-n vs. random
baseline, one curve per class. Values above 1 indicate the model
outperforms random selection at that depth. The categorical legend
is replaced with endpoint-anchored direct labels -- unconditional
(Schwabish C8 audit-rework, 2026-05-12). Use
Chart(df).mark_lift(...) directly to keep the legend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator or ModelSource
|
Fitted sklearn-compatible classifier or an explicit
|
None
|
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
True class labels. Required when |
None
|
y_true
|
array - like
|
Ground-truth class labels for the precomputed path. Must be
paired with |
None
|
y_pred
|
array - like
|
Soft scores / probabilities for the precomputed path. 1-D for
binary classifiers (positive-class scores); 2-D
|
None
|
compare
|
dict[str, estimator] or None
|
Multi-model overlay. Keys are display names; values are fitted
estimators. Routes through |
None
|
subtitle
|
str or None
|
Optional subtitle rendered beneath the active chart title. |
None
|
random_state
|
int or None
|
Seed forwarded to |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Lift curve with one line per class. |
Examples:
>>> import ferrum as fm
>>> from sklearn.linear_model import LogisticRegression
>>> fm.lift_chart(LogisticRegression().fit(X_train, y_train), X_test, y_test)
Precomputed path (y_pred = soft scores, 1-D binary or 2-D multiclass):
discrimination_threshold_chart ¶
discrimination_threshold_chart(model: Any = None, X: Any = None, y: Any = None, *, y_true: Any = None, y_pred: Any = None, n_thresholds: int = 50, metrics: tuple[str, ...] = ('precision', 'recall', 'f1', 'queue_rate'), cv: Any = None, threshold_line: bool = False, optimum_label: bool = True, compare: dict[str, Any] | None = None, subtitle: str | None = None, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Discrimination-threshold sweep chart for a binary classifier.
Plots multiple classification metrics (precision, recall, F1, queue rate) as a function of the decision threshold, allowing users to select an operating point that balances competing objectives. The underlying data is unpivoted to long form for multi-metric rendering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator or ModelSource
|
Fitted sklearn-compatible binary classifier or an explicit
|
None
|
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
True binary labels. Required when |
None
|
y_true
|
array - like
|
Ground-truth class labels for the precomputed path. Must be
paired with |
None
|
y_pred
|
array - like
|
Soft scores / probabilities for the precomputed path. 1-D for
binary classifiers (positive-class scores); 2-D
|
None
|
n_thresholds
|
int
|
Number of evenly spaced threshold values in |
50
|
metrics
|
tuple of str
|
Metric names to plot. Each must be a column in the threshold sweep DataFrame. |
("precision", "recall", "f1", "queue_rate")
|
cv
|
int, cross-validator, or None
|
When provided, the threshold sweep is computed via cross- validation rather than a single train/test split. |
None
|
threshold_line
|
bool
|
When |
False
|
optimum_label
|
bool
|
When |
True
|
compare
|
dict[str, estimator] or None
|
Multi-model overlay. Keys are display names; values are fitted
estimators. Routes through |
None
|
subtitle
|
str or None
|
Optional subtitle rendered beneath the active chart title. |
None
|
random_state
|
int or None
|
Seed forwarded to |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Multi-metric line chart over the threshold range. |
Examples:
>>> import ferrum as fm
>>> from sklearn.linear_model import LogisticRegression
>>> fm.discrimination_threshold_chart(LogisticRegression().fit(X_train, y_train), X_test, y_test)
Precomputed path (y_pred = 1-D positive-class scores; cv= not supported):
confusion_matrix_chart ¶
confusion_matrix_chart(model: Any = None, X: Any = None, y: Any = None, *, y_true: Any = None, y_pred: Any = None, normalize: str | None = 'true', annotate: bool = True, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Confusion matrix heatmap for a classifier.
Renders an ordinal heatmap of (actual class, predicted class) cell
values with optional per-cell text annotations. Normalization
follows sklearn's confusion_matrix conventions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator or ModelSource
|
Fitted sklearn-compatible classifier or an explicit
|
None
|
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
True class labels. Required when |
None
|
y_true
|
array - like
|
Ground-truth class labels for the precomputed path. Must be
paired with |
None
|
y_pred
|
array - like
|
Predicted class labels for the precomputed path. |
None
|
normalize
|
('true', 'pred', 'all')
|
Normalization scheme for cell values. |
"true"
|
annotate
|
bool
|
When |
True
|
random_state
|
int or None
|
Seed forwarded to |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Confusion matrix heatmap with optional cell annotations. |
Examples:
>>> import ferrum as fm
>>> from sklearn.linear_model import LogisticRegression
>>> fm.confusion_matrix_chart(LogisticRegression().fit(X_train, y_train), X_test, y_test)
Precomputed path (y_pred = 1-D hard class labels):
class_prediction_error_chart ¶
class_prediction_error_chart(model: Any = None, X: Any = None, y: Any = None, *, y_true: Any = None, y_pred: Any = None, normalize: bool = False, show_counts: bool = True, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Class prediction-error stacked bar chart for a classifier.
One bar per predicted class, stacked by actual class so misclassified segments are visually distinct. The data source is the unnormalized confusion matrix reshaped to long form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator or ModelSource
|
Fitted sklearn-compatible classifier or an explicit
|
None
|
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
True class labels. Required when |
None
|
y_true
|
array - like
|
Ground-truth class labels for the precomputed path. Must be
paired with |
None
|
y_pred
|
array - like
|
Predicted class labels for the precomputed path. |
None
|
normalize
|
bool
|
When |
False
|
show_counts
|
bool
|
When |
True
|
random_state
|
int or None
|
Seed forwarded to |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Stacked bar chart with one bar per predicted class. |
Examples:
>>> import ferrum as fm
>>> from sklearn.linear_model import LogisticRegression
>>> fm.class_prediction_error_chart(LogisticRegression().fit(X_train, y_train), X_test, y_test)
Precomputed path (y_pred = 1-D hard class labels):
classification_report_chart ¶
classification_report_chart(model: Any = None, X: Any = None, y: Any = None, *, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Per-class precision / recall / F1 heatmap for a classifier.
Renders a rect-plus-text heatmap where rows are class labels, columns
are metrics (precision, recall, f1-score), and cell color
encodes the metric value. Each cell is annotated with its value to two
decimal places.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator or ModelSource
|
A fitted sklearn-compatible classifier that exposes |
None
|
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
True labels. Required when |
None
|
random_state
|
int or None
|
Seed forwarded to |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Heatmap with per-class precision / recall / F1-score cells. |
Examples:
class_balance_chart ¶
class_balance_chart(y: Any, *, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Bar chart of per-class label counts.
Computes the count of each unique class label and renders a vertical bar chart. No model is required — operates on the target array alone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
array - like
|
Target label array (1-D). Accepts polars |
required |
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Vertical bar chart with class labels on x and counts on y. |
Examples:
importance_chart ¶
importance_chart(model: Any, X: Any = None, y: Any = None, *, method: str = 'builtin', top_k: int | None = 20, orient: str = 'horizontal', error_bars: bool = True, show_values: bool = True, subtitle: str | None = None, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Feature-importance bar chart for an estimator.
Extracts feature importances from the model via the selected method
and renders a ranked bar chart. Error bars are drawn from
importance +/- std when available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator or ModelSource
|
Fitted sklearn-compatible estimator or an explicit
|
required |
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
Target vector. Required when |
None
|
method
|
('builtin', 'permutation')
|
Importance extraction method. |
"builtin"
|
top_k
|
int or None
|
Maximum number of features to display, ordered by descending
absolute importance. Pass |
20
|
orient
|
('horizontal', 'vertical')
|
Bar orientation. |
"horizontal"
|
error_bars
|
bool
|
When |
True
|
show_values
|
bool
|
When |
True
|
subtitle
|
str or None
|
Optional subtitle rendered beneath the active chart title. |
None
|
random_state
|
int or None
|
Seed forwarded to |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Feature-importance bar chart ranked by absolute importance. |
Examples:
shap_chart ¶
shap_chart(model: Any, X: Any = None, y: Any = None, *, kind: str = 'beeswarm', max_display: int = 20, sample_idx: int | None = None, order: str = 'abs_mean', background: Any = None, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
SHAP value chart for an estimator.
Dispatches to one of three chart types based on kind. The
beeswarm (default) shows per-sample per-feature SHAP values colored
by z-scored feature magnitude. The bar chart aggregates mean absolute
SHAP per feature. The waterfall chart shows cumulative contributions
for a single sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator or ModelSource
|
Fitted sklearn-compatible estimator or an explicit
|
required |
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
Target vector. Required when |
None
|
kind
|
('beeswarm', 'bar', 'waterfall')
|
Chart type. |
"beeswarm"
|
max_display
|
int
|
Maximum number of features to display, selected by the |
20
|
sample_idx
|
int or None
|
Row index (0-based) of the sample to explain. Required when
|
None
|
order
|
('abs_mean', 'max')
|
Feature ranking criterion across all three kinds. |
"abs_mean"
|
background
|
array - like or None
|
Background dataset for kernel SHAP explainers. When |
None
|
random_state
|
int or None
|
Seed forwarded to |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
SHAP beeswarm, bar, or waterfall chart depending on |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
Examples:
shap_beeswarm_chart ¶
shap_beeswarm_chart(model: Any, X: Any = None, y: Any = None, *, max_display: int = 20, order: str = 'abs_mean', background: Any = None, per_class: bool = False, zero_line: bool = True, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
SHAP beeswarm chart -- per-sample SHAP scatter colored by z-scored value.
per_class=True on a multi-class classifier facets the chart by
class. per_class=False (default) renders a single panel using
the first class (the only group on regression and binary).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator or ModelSource
|
Fitted sklearn-compatible estimator or an explicit
|
required |
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
Target vector. Required when |
None
|
max_display
|
int
|
Maximum number of features to display. |
20
|
order
|
('abs_mean', 'max')
|
Feature ranking criterion. |
"abs_mean"
|
background
|
array - like or None
|
Background dataset for kernel SHAP explainers. Ignored for tree SHAP. |
None
|
per_class
|
bool
|
Facet by class on multi-class classifiers. |
False
|
zero_line
|
bool
|
Overlay a dashed vertical reference rule at |
True
|
random_state
|
int or None
|
Seed forwarded to |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
SHAP beeswarm chart. |
Examples:
shap_bar_chart ¶
shap_bar_chart(model: Any, X: Any = None, y: Any = None, *, max_display: int = 20, order: str = 'abs_mean', background: Any = None, per_class: bool = False, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
SHAP bar chart -- mean absolute SHAP per feature.
per_class=True on a multi-class classifier facets the chart by
class. per_class=False (default) renders a single panel using
the first class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator or ModelSource
|
Fitted sklearn-compatible estimator or an explicit
|
required |
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
Target vector. Required when |
None
|
max_display
|
int
|
Maximum number of features to display. |
20
|
order
|
('abs_mean', 'max')
|
Feature ranking criterion. |
"abs_mean"
|
background
|
array - like or None
|
Background dataset for kernel SHAP explainers. Ignored for tree SHAP. |
None
|
per_class
|
bool
|
Facet by class on multi-class classifiers. |
False
|
random_state
|
int or None
|
Seed forwarded to |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
SHAP bar chart (features x mean |SHAP|). |
Examples:
shap_waterfall_chart ¶
shap_waterfall_chart(model: Any, X: Any = None, y: Any = None, *, sample_idx: int, max_display: int = 20, order: str = 'abs_mean', background: Any = None, per_class: bool = False, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
SHAP waterfall chart -- cumulative per-feature contributions for one sample.
per_class=True on a multi-class classifier facets the chart by
class (one waterfall panel per class for the same sample).
per_class=False (default) renders a single panel using the first
class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator or ModelSource
|
Fitted sklearn-compatible estimator or an explicit
|
required |
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
Target vector. Required when |
None
|
sample_idx
|
int
|
Row index (0-based) of the sample to explain. Required. |
required |
max_display
|
int
|
Maximum number of features to display. |
20
|
order
|
('abs_mean', 'max')
|
Feature ranking criterion. |
"abs_mean"
|
background
|
array - like or None
|
Background dataset for kernel SHAP explainers. Ignored for tree SHAP. |
None
|
per_class
|
bool
|
Facet by class on multi-class classifiers. |
False
|
random_state
|
int or None
|
Seed forwarded to |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
SHAP waterfall chart for the sample at |
Examples:
pdp_chart ¶
pdp_chart(model: Any, X: Any = None, y: Any = None, *, features: list | None = None, grid_resolution: int = 100, kind: str = 'average', ice_alpha: float = 0.2, center: bool = False, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Partial-dependence plot (PDP) for one or more features.
Renders one facet panel per feature, each showing how the model prediction changes as that feature varies across its observed range while all other features are held at their column means. Supports average PDP, individual conditional expectation (ICE), and both overlaid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator or ModelSource
|
Fitted sklearn-compatible estimator or an explicit
|
required |
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
Target vector. Required when |
None
|
features
|
list of str or int, required
|
Column names or integer indices of the features to plot. Each
feature gets its own facet panel. Must be provided; raises
|
None
|
grid_resolution
|
int
|
Number of evenly spaced grid points along each feature's range. |
100
|
kind
|
('average', 'individual', 'both')
|
|
"average"
|
ice_alpha
|
float
|
Opacity of individual ICE lines when |
0.2
|
center
|
bool
|
When |
False
|
random_state
|
int or None
|
Seed forwarded to |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Faceted PDP chart with one panel per feature. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
learning_curve_chart ¶
learning_curve_chart(model: Any, X: Any = None, y: Any = None, *, cv: int = 5, scoring: Any = None, train_sizes: Any = None, ci_style: str = 'band', subtitle: str | None = None, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Learning curve chart showing score vs. training set size.
Plots cross-validated train and validation scores as training size grows, revealing overfitting, underfitting, and data-hunger. The CI band is drawn from per-fold score variance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator or ModelSource
|
Fitted (or unfitted) sklearn-compatible estimator or an explicit
|
required |
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
Target vector. Required when |
None
|
cv
|
int
|
Number of cross-validation folds. |
5
|
scoring
|
str, callable, or None
|
Scoring metric forwarded to
|
None
|
train_sizes
|
array - like or None
|
Relative or absolute training sizes to evaluate. When |
None
|
ci_style
|
('band', 'errorbar')
|
Visual style of the confidence interval. |
"band"
|
subtitle
|
str or None
|
Optional subtitle rendered beneath the active chart title. |
None
|
random_state
|
int or None
|
Seed forwarded to |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Learning curve with train and validation score lines plus CI. |
Examples:
validation_curve_chart ¶
validation_curve_chart(model: Any, X: Any = None, y: Any = None, *, param: str = 'alpha', values: Any = None, cv: int = 5, scoring: Any = None, log_scale: Any = 'auto', ci_style: str = 'band', subtitle: str | None = None, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Plot score vs. a single hyperparameter value.
Sweeps one hyperparameter over a supplied value range and plots cross-validated train and validation scores, revealing the bias- variance tradeoff for that parameter. The x axis is log-scaled automatically when the value range spans more than two orders of magnitude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator or ModelSource
|
Fitted (or unfitted) sklearn-compatible estimator or an explicit
|
required |
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
Target vector. Required when |
None
|
param
|
str
|
Name of the hyperparameter to sweep, passed to
|
"alpha"
|
values
|
(array - like, required)
|
Values of |
None
|
cv
|
int
|
Number of cross-validation folds. |
5
|
scoring
|
str, callable, or None
|
Scoring metric. When |
None
|
log_scale
|
bool or 'auto'
|
Whether to use a log scale on the x axis. |
"auto"
|
ci_style
|
('band', 'errorbar')
|
Visual style of the confidence interval. |
"band"
|
subtitle
|
str or None
|
Optional subtitle rendered beneath the active chart title. |
None
|
random_state
|
int or None
|
Seed forwarded to |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Validation curve with train and validation score lines plus CI. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
cv_scores_chart ¶
cv_scores_chart(model: Any, X: Any = None, y: Any = None, *, cv: int = 5, scoring: Any = None, kind: str = 'box', split: str = 'both', random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Per-fold cross-validation score distribution chart.
Visualizes the distribution of scores across folds for train and/or validation splits, making variance and consistency across folds immediately visible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator or ModelSource
|
Fitted (or unfitted) sklearn-compatible estimator or an explicit
|
required |
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
Target vector. Required when |
None
|
cv
|
int
|
Number of cross-validation folds. |
5
|
scoring
|
str, callable, or None
|
Scoring metric. When |
None
|
kind
|
('box', 'strip', 'bar')
|
Chart type. |
"box"
|
split
|
('both', 'train', 'test')
|
Which CV split to show. |
"both"
|
random_state
|
int or None
|
Seed forwarded to |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Per-fold CV score distribution chart. |
Examples:
alpha_selection_chart ¶
alpha_selection_chart(model: Any, X: Any = None, y: Any = None, *, alphas: Any = None, cv: int = 5, scoring: Any = None, log_scale: bool = True, highlight_best: bool = True, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Regularization-strength (alpha) selection chart.
Plots cross-validated mean score as a function of regularization strength, helping users identify the optimal alpha for penalized estimators such as Ridge, Lasso, and ElasticNet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator or ModelSource
|
Fitted (or unfitted) sklearn-compatible penalized estimator or
an explicit |
required |
X
|
array - like
|
Feature matrix. Required when |
None
|
y
|
array - like
|
Target vector. Required when |
None
|
alphas
|
(array - like, required)
|
Regularization-strength values to sweep. Must be provided;
raises |
None
|
cv
|
int
|
Number of cross-validation folds. |
5
|
scoring
|
str, callable, or None
|
Scoring metric. When |
None
|
log_scale
|
bool
|
When |
True
|
highlight_best
|
bool
|
When |
True
|
random_state
|
int or None
|
Seed forwarded to |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
CV-score-vs-alpha line chart with optional best-alpha rule. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
pca_scree_chart ¶
pca_scree_chart(model: Any, X: Any = None, *, n_components: int | None = None, cumulative_line: bool = True, threshold: float | None = 0.95, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
PCA scree chart showing explained variance per component.
Plots per-component explained variance ratio as bars, with an optional cumulative-variance overlay line and a horizontal reference rule at a target cumulative-variance threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
PCA estimator, ModelSource, or DataFrame
|
A fitted |
required |
X
|
array - like
|
Feature matrix. Required when |
None
|
n_components
|
int or None
|
Number of components to display. When |
None
|
cumulative_line
|
bool
|
When |
True
|
threshold
|
float or None
|
When a float is given, draws a horizontal reference rule at
that cumulative-variance level (e.g. |
0.95
|
random_state
|
int or None
|
Seed forwarded to |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
PCA scree bar chart with optional cumulative line and threshold rule. |
Examples:
>>> import ferrum as fm
>>> from sklearn.decomposition import PCA
>>> fm.pca_scree_chart(PCA(n_components=10).fit(X_train), threshold=0.90)
Raw DataFrame (no sklearn required):
cluster_diagnostics ¶
cluster_diagnostics(X: Any, *, ks: Any, method: str = 'kmeans', scoring: str = 'both', n_init: int = 10, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart | HConcatChart'
Elbow and silhouette diagnostics over a range of cluster counts.
Fits one clusterer per value of k and renders the requested
diagnostic panel(s): distortion (inertia) vs. k, mean silhouette
score vs. k, or both side-by-side. Unlike the other figure
functions, this sweeps the model class itself rather than wrapping
a single pre-fitted ModelSource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Feature matrix. All samples are used for fitting and scoring. Polars DataFrames, pandas DataFrames, and 2D numpy arrays are accepted. |
required |
ks
|
iterable of int
|
Values of k (number of clusters) to evaluate. |
required |
method
|
('kmeans', 'hierarchical')
|
Clustering algorithm.
DBSCAN is intentionally not supported -- its number of clusters
is determined by |
"kmeans"
|
scoring
|
('elbow', 'silhouette', 'both')
|
Which diagnostic panel(s) to render.
|
"elbow"
|
n_init
|
int
|
Number of KMeans initializations per k; forwarded to
|
10
|
random_state
|
int or None
|
Random seed for KMeans initialisation. When |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
Returns:
| Type | Description |
|---|---|
Chart or HConcatChart
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
intercluster_distance_chart ¶
intercluster_distance_chart(model: Any, X: Any = None, *, k: int | None = None, method: str = 'mds', random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Intercluster distance map: 2D embedding of cluster centers.
Embeds cluster centers into 2D using MDS so their pairwise distances are approximately preserved. Each center is rendered as a size-encoded circle (bubble area proportional to cluster count). A 15% padding is added around the data range so large bubbles do not clip at axis edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
fitted clusterer or ModelSource
|
A fitted sklearn-compatible clusterer (must expose
|
required |
X
|
array - like
|
Feature matrix used to compute cluster member counts.
Required when |
None
|
k
|
int or None
|
Number of clusters. When |
None
|
method
|
('mds', 'tsne')
|
Dimensionality-reduction method for embedding cluster centers.
|
"mds"
|
random_state
|
int or None
|
Seed forwarded to |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
2D scatter chart of embedded cluster centers sized by cluster population. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
silhouette_chart ¶
silhouette_chart(model: Any, X: Any = None, *, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Rousseeuw silhouette plot for a fitted clusterer.
Computes per-sample silhouette coefficients and renders a horizontal bar chart sorted by cluster, one bar per sample, colored by cluster label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
fitted clusterer or ModelSource
|
A fitted sklearn-compatible clustering estimator that exposes
|
required |
X
|
array - like
|
Feature matrix. Required when |
None
|
random_state
|
int or None
|
Seed forwarded to |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Horizontal silhouette bar chart with per-cluster color encoding. |
Examples:
manifold_chart ¶
manifold_chart(model: Any, X: Any = None, *, method: str = 'umap', random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Low-dimensional manifold-embedding scatter (UMAP / t-SNE / PCA).
Projects the input data to two dimensions via the selected embedding
algorithm and renders a point chart with axes dim_0 / dim_1
colored by cluster label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
fitted clusterer or ModelSource
|
A fitted clustering estimator whose |
required |
X
|
array - like
|
Feature matrix. Required when |
None
|
method
|
str
|
Embedding algorithm. Typical values are |
"umap"
|
random_state
|
int or None
|
Seed forwarded to |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
2-D scatter plot of the embedded data, colored by cluster label. |
Examples:
elbow_chart ¶
elbow_chart(model: Any, X: Any, *, ks: Any, metric: str = 'distortion', random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Elbow / score sweep over a range of k for a clustering algorithm.
Fits one model per k value and plots the selected score metric against k. Useful for identifying the optimal number of clusters visually.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
type
|
Uninstantiated clustering class (e.g. |
required |
X
|
array - like
|
Feature matrix used to fit each per-k model. |
required |
ks
|
sequence of int
|
The candidate k values to sweep (e.g. |
required |
metric
|
('distortion', 'silhouette', 'calinski_harabasz')
|
Score to optimize. |
"distortion"
|
random_state
|
int or None
|
Seed passed to every per-k model instantiation. |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Score-vs-k line chart with the optimal k annotated. |
Examples:
decision_boundary_chart ¶
decision_boundary_chart(model: Any, X: Any, y: Any = None, *, features: tuple = (0, 1), grid_resolution: int = 200, proba: bool = False, scatter: bool = True, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Decision-boundary heatmap for a classifier over a 2D feature slice.
Builds a grid_resolution x grid_resolution grid over two
selected features, holds all other features fixed at their column
means, and colors each cell by the model's predicted class (or
probability). Optionally overlays training-point scatter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
estimator or ModelSource
|
Fitted sklearn-compatible classifier or an explicit
|
required |
X
|
array - like
|
Feature matrix. Must be provided (not optional) so the grid bounds and column means can be computed. |
required |
y
|
array - like or None
|
True labels. Used only for the scatter overlay when
|
None
|
features
|
tuple of (int or str, int or str)
|
Two feature indices or column names to use for the x and y axes of the grid. All other features are fixed at their column means. Exactly 2 features are required. |
(0, 1)
|
grid_resolution
|
int
|
Number of grid points along each axis; total cells =
|
200
|
proba
|
bool
|
When |
False
|
scatter
|
bool
|
When |
False
|
random_state
|
int or None
|
Seed forwarded to |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Decision-boundary heatmap, optionally with training-point scatter overlay. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
rank_chart ¶
rank_chart(source: Any, X: Any = None, y: Any = None, *, rank: str = '2d', algorithm: str | None = None, top_k: int | None = None, annot: bool = True, orient: str = 'horizontal', color_field: str | None = None, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Feature-ranking chart: univariate bar or pairwise heatmap.
Computes a ranking score for each feature (or each feature pair)
and renders either a ranked bar chart (rank="1d") or a pairwise
correlation heatmap (rank="2d"). Accepts a fitted estimator,
ModelSource, or a raw DataFrame / 2D array (no model required
for most algorithms).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
estimator, ModelSource, DataFrame, or array-like
|
Input data. When a fitted estimator or |
required |
X
|
array - like
|
Feature matrix. Used when |
None
|
y
|
array - like
|
Target vector. Required only for
|
None
|
rank
|
('1d', '2d')
|
Ranking mode. |
"1d"
|
algorithm
|
str or None
|
Ranking algorithm. When |
None
|
top_k
|
int or None
|
For |
None
|
annot
|
bool
|
For |
True
|
orient
|
('horizontal', 'vertical')
|
Bar orientation for |
"horizontal"
|
color_field
|
str or None
|
Column name to use for bar fill color in |
None
|
random_state
|
int or None
|
Seed forwarded to |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Ranked bar chart ( |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import ferrum as fm
>>> fm.rank_chart(X_train, rank="2d")
>>> fm.rank_chart(X_train, rank="1d", algorithm="shapiro", top_k=10)
.. deprecated:: 2026-05-12
Use :func:rank1d_chart or :func:rank2d_chart directly. This
dispatcher remains as a shim that forwards to the appropriate
sibling and will be removed in a future major release.
rank1d_chart ¶
rank1d_chart(source: Any, X: Any = None, y: Any = None, *, algorithm: str | None = None, top_k: int | None = None, orient: str = 'horizontal', color_field: str | None = None, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Univariate feature-ranking bar chart.
Computes a per-feature ranking score and renders a horizontal (or
vertical with orient="vertical") bar chart sorted by score.
Accepts a fitted estimator, ModelSource, or a raw DataFrame /
2D array; the "covariance" algorithm requires y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
estimator, ModelSource, DataFrame, or array-like
|
Input data. When a fitted estimator or |
required |
X
|
optional
|
Feature matrix / target -- forwarded to |
None
|
y
|
optional
|
Feature matrix / target -- forwarded to |
None
|
algorithm
|
str or None
|
Ranking algorithm. |
None
|
top_k
|
int or None
|
Limit the chart to the top-k features by score. |
None
|
orient
|
('horizontal', 'vertical')
|
Bar orientation. |
"horizontal"
|
color_field
|
str or None
|
Column name to map to bar color. |
None
|
random_state
|
int or None
|
Seed forwarded to |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Ranked bar chart. |
Examples:
rank2d_chart ¶
rank2d_chart(source: Any, X: Any = None, y: Any = None, *, algorithm: str | None = None, annot: bool = True, random_state: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Pairwise feature-correlation heatmap.
Computes pairwise feature correlation (or covariance) and renders a
heatmap. Accepts a fitted estimator, ModelSource, or a raw
DataFrame / 2D array (no model required).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
estimator, ModelSource, DataFrame, or array-like
|
Input data. |
required |
X
|
optional
|
Feature matrix / target. |
None
|
y
|
optional
|
Feature matrix / target. |
None
|
algorithm
|
str or None
|
Ranking algorithm. |
None
|
annot
|
bool
|
Overlay the correlation value (2 decimals) on each cell. |
True
|
random_state
|
int or None
|
Seed forwarded to |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Pairwise correlation heatmap. |
Examples:
parallel_coordinates_chart ¶
parallel_coordinates_chart(data: Any, *, features: list[str] | None = None, hue: str | None = None, rescale: str | None = 'minmax', alpha: float = 0.5, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None) -> 'Chart'
Parallel coordinates chart for multivariate data.
Renders one polyline per sample, with each feature mapped to a
vertical axis. Features are optionally rescaled to a common range
before plotting so all axes are visually comparable. Samples are
colored by a grouping column when hue is provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
polars.DataFrame, pandas.DataFrame, or array-like
|
Input data. Polars and pandas DataFrames are used directly;
2D numpy arrays are auto-named |
required |
features
|
list of str or None
|
Column names to use as parallel axes. When |
None
|
hue
|
str or None
|
Column name to color samples by (e.g. a target class or cluster
id). Pass |
None
|
rescale
|
('minmax', 'zscore')
|
Per-feature rescaling applied before rendering so axes share a
common visual range. |
"minmax"
|
alpha
|
float
|
Opacity of individual polylines; lower values reduce overplot in dense datasets. |
0.5
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
theme
|
Theme or None
|
Ferrum theme to apply to the returned chart. |
None
|
Returns:
| Type | Description |
|---|---|
Chart
|
Parallel coordinates chart with one polyline per sample. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any name in |
ValueError
|
If |
Examples:
displot ¶
displot(data: Any, *, x: Any = None, y: Any = None, hue: Any = None, col: Any = None, row: Any = None, kind: str = 'hist', fill: bool = True, cumulative: bool = False, log_scale: bool = False, stat: str = 'count', bins: Any = 'sturges', bandwidth: Any = 'scott', bw_adjust: float = 1.0, multiple: str = 'layer', kde: bool = False, rug: bool = False, height: float | None = None, aspect: float | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None, **encode_kwargs: Any) -> Chart
Univariate distribution plot.
Convenience wrapper that dispatches to mark_histogram, mark_density,
or mark_tick based on kind. The multiple parameter controls how
overlapping groups (from hue) are positioned, and the kde / rug
flags optionally layer additional marks on top of the primary kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame - like
|
Input data accepted by |
required |
x
|
str or encoding
|
Column name for the distribution variable (horizontal axis). |
None
|
y
|
str or encoding
|
Column name for the distribution variable (vertical axis). |
None
|
hue
|
str or encoding
|
Column name to map to color (one distribution per level). |
None
|
col
|
str
|
Column name for faceting across columns. |
None
|
row
|
str
|
Column name for faceting across rows. |
None
|
kind
|
('hist', 'kde', 'ecdf', 'rug')
|
Which distribution mark to draw. |
"hist"
|
fill
|
bool
|
Fill the area under the KDE curve ( |
True
|
cumulative
|
bool
|
Produce a cumulative histogram or density ( |
False
|
log_scale
|
bool
|
Apply a |
False
|
stat
|
('count', 'density')
|
Statistic to plot on the value axis for |
"count"
|
bins
|
int or str
|
Binning rule for |
"sturges"
|
bandwidth
|
str
|
Bandwidth selector for |
"scott"
|
bw_adjust
|
float
|
Multiplicative bandwidth adjustment for |
1.0
|
multiple
|
('layer', 'stack', 'fill', 'dodge')
|
How to render multiple distributions (one per |
"layer"
|
kde
|
bool
|
When |
False
|
rug
|
bool
|
When |
False
|
height
|
float or None
|
Height of the chart in pixels. Width is derived from |
None
|
aspect
|
float or None
|
Aspect ratio (width = height * aspect). Requires |
None
|
theme
|
Theme
|
Visual theme applied via |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
**encode_kwargs
|
Any
|
Additional keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
Configured chart (possibly layered, faceted, or sized). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
Examples:
KDE with per-species coloring:
Stacked histogram with an overlaid rug:
catplot ¶
catplot(data: Any, *, x: Any = None, y: Any = None, hue: Any = None, col: Any = None, row: Any = None, kind: str = 'strip', order: Any = None, hue_order: Any = None, orient: Any = None, dodge: bool = False, jitter: bool = True, native_scale: bool = False, ci: Any = 95, n_boot: int = 1000, seed: int | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None, **encode_kwargs: Any) -> Chart
Categorical figure-level function.
Dispatches to the appropriate mark based on kind:
"strip"--mark_pointwithJitter(whenjitter=True, default) orDodge(whendodge=Trueandhueis set)."swarm"--mark_swarm."box"--mark_boxplot(box + whiskers + outliers)."violin"--mark_violin(kernel-density outline)."boxen"--mark_boxen(letter-value / extended box)."point"--mark_pointper observation on the categorical axis."bar"--mark_barper observation on the categorical axis."count"--Aggregate(count)+mark_bar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame - like
|
Input data accepted by |
required |
x
|
str or encoding
|
Column name for the horizontal axis (categorical by default). |
None
|
y
|
str or encoding
|
Column name for the vertical axis (value by default). |
None
|
hue
|
str or encoding
|
Column name to map to color (one visual group per level). |
None
|
col
|
str
|
Column name for faceting across columns. |
None
|
row
|
str
|
Column name for faceting across rows. |
None
|
kind
|
('strip', 'swarm', 'box', 'violin', 'boxen', 'point', 'bar', 'count')
|
Which categorical mark to draw. |
"strip"
|
order
|
list of str
|
Explicit ordering for the categorical axis levels. Passed as
|
None
|
hue_order
|
list of str
|
Explicit ordering for hue levels. Passed as |
None
|
orient
|
('h', 'v', None)
|
|
"h"
|
dodge
|
bool
|
When |
False
|
jitter
|
bool
|
For |
True
|
native_scale
|
bool
|
When |
False
|
ci
|
int or float
|
Confidence-interval level (0--100) for |
95
|
n_boot
|
int
|
Bootstrap iteration count used to compute |
1000
|
seed
|
int or None
|
Random seed forwarded to |
None
|
theme
|
Theme
|
Visual theme applied via |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
**encode_kwargs
|
Any
|
Additional keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
Configured chart (possibly faceted or coord-flipped). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
ValueError
|
If |
ValueError
|
If |
Examples:
Group by a hue variable with dodged bars:
Horizontal violin plot:
relplot ¶
relplot(data: Any, *, x: Any, y: Any, hue: Any = None, size: Any = None, style: Any = None, col: Any = None, row: Any = None, kind: str = 'scatter', height: float | None = None, aspect: float | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None, **encode_kwargs: Any) -> Chart
Relational figure-level function for scatter and line plots.
Dispatches to the appropriate mark based on kind:
"scatter"--mark_point().stylemaps toShape."line"--mark_line().stylemaps toStrokeDash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame - like
|
Input data accepted by |
required |
x
|
str or encoding
|
Column name for the horizontal axis (required). |
required |
y
|
str or encoding
|
Column name for the vertical axis (required). |
required |
hue
|
str or encoding
|
Column name to map to color (one group per level). |
None
|
size
|
str or encoding
|
Column name to map to the |
None
|
style
|
str or encoding
|
Column name to map to |
None
|
col
|
str
|
Column name for faceting across columns. |
None
|
row
|
str
|
Column name for faceting across rows. |
None
|
kind
|
('scatter', 'line')
|
Which relational mark to draw. |
"scatter"
|
height
|
float or None
|
Height of the chart in pixels. Width is derived from |
None
|
aspect
|
float or None
|
Aspect ratio (width = height * aspect). Requires |
None
|
theme
|
Theme
|
Visual theme applied via |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
**encode_kwargs
|
Any
|
Additional keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
Configured chart (possibly faceted or sized). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
Scatter with hue grouping and column faceting:
Line plot with per-level dash styling:
lmplot ¶
lmplot(data: Any, *, x: str, y: str, hue: Any = None, col: Any = None, row: Any = None, method: str = 'lm', ci: Any = 95, order: int = 1, scatter: bool = True, scatter_kws: Any = None, line_kws: Any = None, truncate: bool = True, x_bins: Any = None, x_estimator: Any = None, x_jitter: Any = None, logx: bool = False, show_metrics: bool = True, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None, **encode_kwargs: Any) -> Chart
Linear (and non-linear) regression scatter overlay.
Builds a layered chart with an optional scatter (mark_point) and a
regression fit line, dispatching to the appropriate transform:
"lm"--mark_smooth(method="lm")(polynomial degree controlled byorder)."loess"--mark_smooth(method="loess")."logistic"--Logistictransform +mark_line."glm"--Glmtransform +mark_line."robust"--Robusttransform +mark_line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame - like
|
Input data accepted by |
required |
x
|
str
|
Column name for the horizontal (predictor) axis (required). |
required |
y
|
str
|
Column name for the vertical (response) axis (required). |
required |
hue
|
str or encoding
|
Column name to map to color; fit lines are drawn per hue level. |
None
|
col
|
str
|
Column name for faceting across columns. |
None
|
row
|
str
|
Column name for faceting across rows. |
None
|
method
|
('lm', 'logistic', 'glm', 'loess', 'robust')
|
Fitting method. |
"lm"
|
ci
|
int or None
|
Confidence interval level (0--100) shown as a band around the fit
line. Pass |
95
|
order
|
int
|
Polynomial degree forwarded to |
1
|
scatter
|
bool
|
Include a scatter layer ( |
True
|
scatter_kws
|
dict
|
Extra keyword arguments forwarded to the scatter |
None
|
line_kws
|
dict
|
Extra keyword arguments forwarded to the regression-line mark
call (e.g. |
None
|
truncate
|
bool
|
When |
True
|
x_bins
|
any
|
Forwarded as |
None
|
x_estimator
|
any
|
Forwarded as |
None
|
x_jitter
|
float or None
|
When set, applies |
None
|
logx
|
bool
|
Apply a |
False
|
show_metrics
|
bool
|
Schwabish SB-followup (2026-05-12): overlay a top-right corner
annotation with |
True
|
theme
|
Theme
|
Visual theme applied via |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
**encode_kwargs
|
Any
|
Additional keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
Layered chart (scatter + fit) or fit-only when |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
Examples:
Logistic regression with per-sex fit lines:
Polynomial fit (degree 2) with no confidence band:
residplot ¶
residplot(data: Any, *, x: str, y: str, lowess: bool = False, order: int = 1, robust: bool = False, dropna: bool = True, show_metrics: bool = True, zero_line: bool = True, label: Any = None, color: Any = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None, **encode_kwargs: Any) -> Chart
Residual-diagnostic scatter plot.
Computes regression residuals via Smooth(output="residuals") (or
Robust(output="residuals") when robust=True) and plots
(x, residual) with mark_point. When lowess=True, a
mark_line lowess smoother is layered over the residuals to help
diagnose non-linearity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame - like
|
Input data accepted by |
required |
x
|
str
|
Column name for the horizontal axis (predictor; required). |
required |
y
|
str
|
Column name used to compute residuals (response; required). |
required |
lowess
|
bool
|
Overlay a lowess smoother on the residuals using
|
False
|
order
|
int
|
Polynomial degree of the regression used to compute residuals. |
1
|
robust
|
bool
|
Use |
False
|
dropna
|
bool
|
Drop rows where |
True
|
show_metrics
|
bool
|
Schwabish SB-followup (2026-05-12): overlay a top-right corner
annotation with |
True
|
zero_line
|
bool
|
Schwabish SB-followup: draw a dashed horizontal reference at
|
True
|
label
|
str
|
Legend label for the residual series. When set, a constant
|
None
|
color
|
str or encoding
|
Column name or constant color forwarded to |
None
|
theme
|
Theme
|
Visual theme applied via |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
**encode_kwargs
|
Any
|
Additional keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
Scatter of residuals (possibly with a lowess layer, zero reference line, and corner R^2/RMSE/MAE annotation). |
Examples:
Robust residuals with annotations:
regplot ¶
regplot(data: Any, *, x: str, y: str, hue: Any = None, method: str = 'lm', ci: Any = 95, order: int = 1, scatter: bool = True, scatter_kws: Any = None, line_kws: Any = None, truncate: bool = True, x_jitter: Any = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None, **encode_kwargs: Any) -> Chart
Axes-level regression scatter plot.
The axes-level equivalent of lmplot — identical API except
col= and row= are excluded because regplot does not
facet. Every parameter is forwarded to lmplot unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame - like
|
Input data accepted by |
required |
x
|
str
|
Column name for the horizontal (predictor) axis (required). |
required |
y
|
str
|
Column name for the vertical (response) axis (required). |
required |
hue
|
str or encoding
|
Column name to map to color; fit lines are drawn per hue level. |
None
|
method
|
('lm', 'logistic', 'glm', 'loess', 'robust')
|
Fitting method forwarded to |
"lm"
|
ci
|
int or None
|
Confidence interval level (0--100) shown as a band around the fit
line. Pass |
95
|
order
|
int
|
Polynomial degree forwarded to |
1
|
scatter
|
bool
|
Include a scatter layer ( |
True
|
scatter_kws
|
dict
|
Extra keyword arguments forwarded to the scatter |
None
|
line_kws
|
dict
|
Extra keyword arguments forwarded to the regression-line mark call. |
None
|
truncate
|
bool
|
When |
True
|
x_jitter
|
float or None
|
When set, applies |
None
|
theme
|
Theme
|
Visual theme applied via |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
**encode_kwargs
|
Any
|
Additional keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
Layered chart (scatter + fit) or fit-only when |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
Examples:
Robust regression:
pairplot ¶
pairplot(data: Any, *, vars: Any = None, x_vars: Any = None, y_vars: Any = None, hue: Any = None, kind: str = 'scatter', diag_kind: str = 'auto', markers: Any = None, height: float | None = None, aspect: float | None = None, corner: bool = False, dropna: bool = False, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None, **encode_kwargs: Any) -> RepeatChart
Pairwise-scatter grid (scatterplot matrix).
Returns a RepeatChart whose template repeats over the cartesian
product of row x column field lists, resolved from vars or
x_vars/y_vars. When neither is supplied, all numeric columns
in data are used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame - like
|
Input data accepted by |
required |
vars
|
sequence of str
|
Column names to plot on both axes (symmetric grid). Cannot be
combined with |
None
|
x_vars
|
sequence of str
|
Column names for the columns of the grid. Must be paired with
|
None
|
y_vars
|
sequence of str
|
Column names for the rows of the grid. Must be paired with
|
None
|
hue
|
str or encoding
|
Column name to map to color across all panels. |
None
|
kind
|
('scatter', 'kde', 'hist', 'reg')
|
Mark for the off-diagonal cells. |
"scatter"
|
diag_kind
|
('auto', 'hist', 'kde', None, 'none')
|
Mark for the diagonal cells (only when |
"auto"
|
markers
|
str or list of str
|
Point-marker shape(s). A single string (e.g. |
None
|
height
|
float or None
|
Height of each individual panel in pixels. When set alongside
|
None
|
aspect
|
float or None
|
Aspect ratio per panel (width = |
None
|
corner
|
bool
|
Render only the lower-triangle panels. |
False
|
dropna
|
bool
|
When |
False
|
theme
|
Theme
|
Visual theme applied to all panels. |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
**encode_kwargs
|
Any
|
Additional keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
RepeatChart
|
Grid of panels sharing the same off-diagonal and (optionally) diagonal chart templates. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If both |
ValueError
|
If only one of |
Examples:
Specific variables with KDE off-diagonal and per-species color:
heatmap ¶
heatmap(data: Any, *, annot: bool = True, fmt: str = '.2f', cmap: str | None = None, linewidths: float = 0.5, linecolor: str = 'white', vmin: float | None = None, vmax: float | None = None, center: float | None = None, robust: bool = False, square: bool = False, mask: Any = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None, **encode_kwargs: Any) -> Chart
2-D heatmap of a wide-format DataFrame.
Each row of data becomes a row of the heatmap; each numeric column
becomes a column. The first non-numeric column (if any) is used as the
row-label axis; rows without a label column get a synthetic integer index.
The DataFrame is unpivoted to long form via Unpivot, then rendered
with mark_rect and an optional annotation layer (mark_text).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame - like
|
Wide-format input. Numeric columns become the heatmap cells; the first non-numeric column (if present) labels the rows. |
required |
annot
|
bool
|
Overlay cell values as text using |
True
|
fmt
|
str
|
Python format specifier applied to cell values in the annotation layer. |
".2f"
|
cmap
|
str or None
|
Color scheme name (e.g. |
None
|
linewidths
|
float
|
Width of the cell border stroke in pixels. |
0.5
|
linecolor
|
str
|
Color of the cell border stroke. |
"white"
|
vmin
|
float or None
|
Minimum of the color scale domain. Overrides |
None
|
vmax
|
float or None
|
Maximum of the color scale domain. Overrides |
None
|
center
|
float or None
|
Value to center a diverging color scale on (maps to
|
None
|
robust
|
bool
|
When |
False
|
square
|
bool
|
Force equal width and height per cell so the heatmap is square. |
False
|
mask
|
array-like, "upper", "lower", or None
|
Cell-masking control. When |
None
|
theme
|
Theme
|
Visual theme applied via |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
**encode_kwargs
|
Any
|
Additional keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Chart
|
Possibly layered chart ( |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
Suppress annotations and use a custom domain:
clustermap ¶
clustermap(data: Any, *, method: str = 'ward', metric: str = 'euclidean', cmap: str | None = None, z_score: Any = None, standard_scale: Any = None, figsize: Any = None, dendrogram_ratio: float = 0.2, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None, **encode_kwargs: Any) -> 'ClusterMapChart'
Clustered heatmap with row and column dendrograms.
Returns a ClusterMapChart composed of:
- a center heatmap of the hierarchically-reordered wide-format
DataFrame (
Linkage+Reorder+Unpivot+mark_rect), - a column dendrogram (top,
mark_segment, readingcol_link_segments), and - a row dendrogram (left,
mark_segment+CoordFlip, readingrow_link_segments).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame - like
|
Wide-format input. Same layout requirements as |
required |
method
|
str
|
Linkage algorithm forwarded to |
"ward"
|
metric
|
str
|
Distance metric forwarded to |
"euclidean"
|
cmap
|
str or None
|
Color scheme name for the center heatmap (e.g. |
None
|
z_score
|
(0, 1, None)
|
Standardise data along rows ( |
0
|
standard_scale
|
(0, 1, None)
|
Normalise to [0, 1] along rows ( |
0
|
figsize
|
tuple of (float, float)
|
Overall figure size as |
None
|
dendrogram_ratio
|
float
|
Fraction of the total width/height allocated to each dendrogram
panel, forwarded to |
0.2
|
theme
|
Theme
|
Visual theme applied to the center and dendrogram charts. |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
**encode_kwargs
|
Any
|
Additional keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
ClusterMapChart
|
Compound view with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
Correlation matrix with euclidean ward clustering:
jointplot ¶
jointplot(data: Any, *, x: str, y: str, hue: Any = None, kind: str = 'scatter', marginal_kind: str = 'hist', ratio: int = 5, space: float = 0.05, xlim: Any = None, ylim: Any = None, joint_kws: Any = None, marginal_kws: Any = None, height: float | None = None, mark: dict | None = None, encode: dict | None = None, properties: dict | None = None, layers: list | None = None, theme: Any = None, **encode_kwargs: Any) -> JointChart
Joint-distribution plot with marginals.
Builds a JointChart composed of a central bivariate plot flanked by
univariate marginals along the x (top) and y (right) axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame - like
|
Input data accepted by |
required |
x
|
str
|
Column name for the horizontal axis (required). |
required |
y
|
str
|
Column name for the vertical axis (required). |
required |
hue
|
str or encoding
|
Column name to map to color in both the center and marginal charts. |
None
|
kind
|
('scatter', 'kde', 'hist', 'hex', 'reg')
|
Mark to use for the central panel. |
"scatter"
|
marginal_kind
|
('hist', 'kde', 'rug', 'box')
|
Mark to use for the marginal panels (same kind applied to both the top x-marginal and the right y-marginal). |
"hist"
|
ratio
|
int
|
Size ratio of the center panel to the marginal panels. |
5
|
space
|
float
|
Gap (in layout units) between the center and marginal panels. |
0.05
|
xlim
|
tuple
|
|
None
|
ylim
|
tuple
|
|
None
|
joint_kws
|
dict
|
Extra keyword arguments forwarded to the center-panel mark call. |
None
|
marginal_kws
|
dict
|
Extra keyword arguments forwarded to the marginal mark calls. |
None
|
height
|
float or None
|
Height and width of the square central panel in pixels. |
None
|
theme
|
Theme
|
Visual theme applied to all three panels via |
None
|
mark
|
dict
|
Per-layer mark overrides. For composite-mark charts, keys are
layer names (e.g. |
None
|
encode
|
dict
|
Additional encoding kwargs merged via |
None
|
properties
|
dict
|
Chart properties merged via |
None
|
layers
|
list
|
Extra layers appended via |
None
|
**encode_kwargs
|
Any
|
Additional keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
JointChart
|
Compound view with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
2-D histogram center with KDE marginals, colored by species:
hconcat ¶
Horizontal concatenation of charts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*charts
|
Chart or _ChartLike
|
Two or more charts to place side-by-side. |
()
|
spacing
|
float
|
Pixel gap between adjacent charts. |
10.0
|
Returns:
| Type | Description |
|---|---|
HConcatChart
|
|
Examples:
vconcat ¶
Vertical concatenation of charts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*charts
|
Chart or _ChartLike
|
Two or more charts to stack top-to-bottom. |
()
|
spacing
|
float
|
Pixel gap between adjacent charts. |
10.0
|
Returns:
| Type | Description |
|---|---|
VConcatChart
|
|
Examples: