Visualizers¶
Sklearn-protocol diagnostic visualizers. Each visualizer follows the
Viz(model).fit(X, y).show() pattern and is composable inside sklearn
pipelines, GridSearchCV, and external evaluators.
For the equivalent one-liner functional API, see ferrum.plots.
Base class¶
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 |
Classification¶
10b/10c classification visualizers — ROC, PR, Calibration, ConfusionMatrix, ClassificationReport.
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 |
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 |
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 |
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 |
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 |
10b/10c extra classification visualizers.
Houses visualizers that don't naturally cluster with the curve-based ones
in classification.py: threshold sweep, per-class error stack, and the
model-free class-balance bar.
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 |
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 |
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 |
Regression¶
10a regression visualizers — ResidualsVisualizer, PredictionErrorVisualizer, CooksDistanceVisualizer.
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 |
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 |
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 |
Clustering¶
10f clustering / manifold / dimensionality visualizers.
Mirrors yellowbrick's KElbow, Silhouette, InterclusterDistance, Manifold,
and PCA-decomposition surfaces. Each visualizer wraps the appropriate
ModelSource method and emits a ferrum chart via _build_chart.
ElbowVisualizer is the lone exception — it takes a model class
rather than a fitted instance and fits one clusterer per k inside its
fit() method, paralleling yellowbrick's API. Every other visualizer
follows the standard FerrumVisualizer.fit(X[, y]) protocol.
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 |
Explanation (SHAP)¶
10d explanation visualizers — feature importance, SHAP family, PDP.
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 |
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
|
per_class
|
bool
|
Facet by class on multi-class classifiers. |
False
|
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
|
per_class
|
bool
|
Facet by class on multi-class classifiers. |
False
|
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 |
Model selection¶
10e model-selection visualizers — LearningCurve, ValidationCurve, CVScores, AlphaSelection.
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 |
Ranking¶
Phase 10g — feature-ranking visualizers (no-model variants).
Mirrors yellowbrick's Rank1D / Rank2D / ParallelCoordinates
surfaces. None of these need a fitted estimator — they operate on the
raw feature matrix X (with optional y for Rank1D(algorithm="covariance"))
and skip the ModelSource round-trip. The chart is materialized
directly from the in-house compute helpers in stats.py.
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 |
Data sources¶
Per-domain split of the ModelSource adapter.
ModelSource is too large to live in a single file; the seven
phase-10 domains (predictions, classification curves, importance,
model selection, clustering, ranking, plus ComparedModelSource)
become independent mixin modules whose seam already exists as
# --- 10x --- comment headers. _base.BaseSource owns the
constructor, capability detection, and cache infrastructure; each
mixin contributes domain methods that use those bits via self.
External callers still import from ferrum._diagnostics.source
(re-export shim) — this package is the implementation home.
BaseSource ¶
Shared state + helpers for every ModelSource domain mixin.
Not part of the public API — users import :class:ferrum.ModelSource
which composes :class:BaseSource with the seven per-domain mixins.
The split exists because the original monolithic implementation
grew past 1500 lines along clear domain seams; keeping the seams
in code matches the seams in the docs.
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. |