Visualization¶
- class endgame.visualization.BaseVisualizer(*, title='', palette='tableau', width=900, height=500, theme='dark')[source]¶
Bases:
ABCAbstract base class for all endgame visualizers.
- Parameters:
- to_json()[source]¶
Export chart data as a JSON string.
- Return type:
- Returns:
str – JSON representation of the chart data.
- to_png(filepath, width=None, height=None)[source]¶
Export the visualization as a PNG image via headless Chrome.
- Parameters:
- Return type:
- Returns:
Path – The absolute path to the saved PNG file.
- Raises:
RuntimeError – If no Chrome/Chromium binary is found on the system.
- endgame.visualization.get_palette(name, n=None)[source]¶
Get a palette by name.
Searches categorical, sequential, and diverging palettes.
- class endgame.visualization.TreeVisualizer(model, feature_names=None, class_names=None, tree_index=0, title=None, color_by='prediction', max_depth=None, palette='tableau')[source]¶
Bases:
objectInteractive decision tree visualizer.
Generates self-contained HTML files with D3.js-powered interactive tree visualizations featuring: - Expandable/collapsible branches (click nodes) - Zoom in/out and pan (mouse wheel + drag) - Rich tooltips with node statistics - Color-coded nodes by prediction or impurity - Responsive layout
- Parameters:
model (estimator) – A fitted tree model. Supports: - sklearn DecisionTreeClassifier/Regressor - sklearn ensembles (extracts individual trees) - C50Classifier / C50Ensemble - ObliqueDecisionTreeClassifier/Regressor - ObliqueRandomForestClassifier/Regressor - EvolutionaryTreeClassifier/Regressor
feature_names (list of str, optional) – Names for each feature. If None, uses “feature_0”, “feature_1”, etc.
class_names (list of str, optional) – Names for each class (classification only).
tree_index (int, default=0) – For ensemble models, which tree to visualize.
title (str, optional) – Title displayed above the visualization.
color_by (str, default='prediction') – How to color nodes: ‘prediction’ (class color), ‘impurity’ (heatmap), or ‘samples’ (by sample count).
max_depth (int, optional) – Maximum depth to display. Deeper nodes are collapsed by default.
palette (str, default='tableau') – Color palette: ‘tableau’, ‘viridis’, ‘pastel’, or ‘dark’.
Example
>>> from sklearn.datasets import load_iris >>> from sklearn.tree import DecisionTreeClassifier >>> from endgame.visualization import TreeVisualizer >>> >>> X, y = load_iris(return_X_y=True) >>> clf = DecisionTreeClassifier(max_depth=4, random_state=42).fit(X, y) >>> viz = TreeVisualizer( ... clf, ... feature_names=load_iris().feature_names, ... class_names=load_iris().target_names.tolist(), ... title="Iris Decision Tree" ... ) >>> viz.save("iris_tree.html")
- class endgame.visualization.BarChartVisualizer(labels, values, *, series_names=None, orientation='vertical', sort=False, x_label='', y_label='', show_values=True, title='', palette='tableau', width=900, height=500, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive bar chart visualizer.
- Parameters:
values (list of float or list of list of float) – Bar values. For stacked bars, pass a list of lists where each inner list is one stack group.
series_names (list of str, optional) – Names for each series (stacked mode).
orientation (str, default='vertical') – ‘vertical’ or ‘horizontal’.
sort (bool, default=False) – If True, sort bars by value (descending).
x_label (str, optional) – X-axis label.
y_label (str, optional) – Y-axis label.
show_values (bool, default=True) – Show value labels on bars.
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette name.
width (int, default=900) – Chart width.
height (int, default=500) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- classmethod from_importances(model, *, feature_names=None, top_n=20, **kwargs)[source]¶
Create a bar chart from a fitted model’s feature importances.
- Parameters:
- Return type:
- class endgame.visualization.HeatmapVisualizer(data, *, x_labels=None, y_labels=None, annotate=True, fmt='.2f', vmin=None, vmax=None, cmap='rdbu', title='', width=700, height=600, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive heatmap visualizer.
- Parameters:
data (array-like, shape (n_rows, n_cols)) – 2D data matrix.
annotate (bool, default=True) – Show cell values.
fmt (str, default='.2f') – Format string for annotations.
vmin (float, optional) – Color scale range. Auto-computed if None.
vmax (float, optional) – Color scale range. Auto-computed if None.
cmap (str, default='rdbu') – Color palette for the heatmap (diverging palettes work best).
title (str, optional) – Chart title.
width (int, default=700) – Chart width.
height (int, default=600) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- class endgame.visualization.ConfusionMatrixVisualizer(matrix, *, class_names=None, normalize=False, title='', cmap='blues', width=650, height=600, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive confusion matrix visualizer.
- Parameters:
matrix (array-like, shape (n_classes, n_classes)) – Confusion matrix (rows = true, columns = predicted).
normalize (bool, default=False) – If True, show row-normalized values (recall per class).
title (str, optional) – Chart title.
cmap (str, default='blues') – Color palette for the matrix cells.
width (int, default=650) – Chart width.
height (int, default=600) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- classmethod from_estimator(model, X, y, *, class_names=None, **kwargs)[source]¶
Create a confusion matrix from a fitted classifier.
- Parameters:
- Return type:
- class endgame.visualization.HistogramVisualizer(data, *, series_names=None, bins='auto', density=False, kde=False, cumulative=False, x_label='', y_label='', title='', palette='tableau', width=900, height=500, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive histogram visualizer.
- Parameters:
data (array-like or list of array-like) – Data values. Pass multiple arrays for overlaid histograms.
series_names (list of str, optional) – Names for each series.
bins (int or str, default='auto') – Number of bins or ‘auto’ (Freedman-Diaconis rule).
density (bool, default=False) – If True, show density instead of counts.
kde (bool, default=False) – If True, overlay KDE curve.
cumulative (bool, default=False) – If True, show cumulative histogram.
x_label (str, optional) – X-axis label.
y_label (str, optional) – Y-axis label.
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette name.
width (int, default=900) – Chart width.
height (int, default=500) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- classmethod from_residuals(y_true, y_pred, **kwargs)[source]¶
Create a histogram of residuals.
- Parameters:
y_true (array-like) – True values.
y_pred (array-like) – Predicted values.
**kwargs – Additional keyword arguments.
- Return type:
- class endgame.visualization.LineChartVisualizer(x, series, *, error_bands=None, area=False, markers=True, x_label='', y_label='', title='', palette='tableau', width=900, height=500, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive line chart visualizer.
- Parameters:
x (list of float or list of str) – X-axis values (shared across series).
series (dict of str → list of float) – Mapping of series name to Y values.
error_bands (dict of str → (list of float, list of float), optional) – Mapping of series name to (lower, upper) error bands.
area (bool, default=False) – If True, fill area under each line.
markers (bool, default=True) – Show data point markers.
x_label (str, optional) – X-axis label.
y_label (str, optional) – Y-axis label.
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette name.
width (int, default=900) – Chart width.
height (int, default=500) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- classmethod from_learning_curve(train_sizes, train_scores, test_scores, **kwargs)[source]¶
Create a learning curve plot.
- Parameters:
train_sizes (array-like) – Training set sizes.
train_scores (array-like, shape (n_sizes,) or (n_sizes, n_folds)) – Training scores.
test_scores (array-like, shape (n_sizes,) or (n_sizes, n_folds)) – Test/validation scores.
**kwargs – Additional keyword arguments.
- Return type:
- class endgame.visualization.ScatterplotVisualizer(x, y, *, labels=None, sizes=None, colors=None, point_labels=None, x_label='', y_label='', show_diagonal=False, show_regression=False, title='', palette='tableau', width=700, height=600, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive scatterplot visualizer.
- Parameters:
x (array-like) – X coordinates.
y (array-like) – Y coordinates.
labels (array-like of str, optional) – Point labels for coloring (categorical).
sizes (array-like of float, optional) – Point sizes for bubble mode.
colors (array-like of float, optional) – Continuous values for color mapping.
point_labels (list of str, optional) – Individual point hover labels.
x_label (str, optional) – X-axis label.
y_label (str, optional) – Y-axis label.
show_diagonal (bool, default=False) – Show y=x diagonal line.
show_regression (bool, default=False) – Show linear regression line.
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette name.
width (int, default=700) – Chart width.
height (int, default=600) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- classmethod from_predictions(y_true, y_pred, **kwargs)[source]¶
Create an actual-vs-predicted scatter plot.
- Parameters:
y_true (array-like) – True values.
y_pred (array-like) – Predicted values.
**kwargs – Additional keyword arguments.
- Return type:
- classmethod from_embedding(embedding, labels=None, **kwargs)[source]¶
Create a scatter plot from 2D embeddings (t-SNE, UMAP, PCA).
- Parameters:
embedding (array-like, shape (n_samples, 2)) – 2D embedding coordinates.
labels (array-like, optional) – Labels for coloring.
**kwargs – Additional keyword arguments.
- Return type:
- class endgame.visualization.BoxPlotVisualizer(data, *, orientation='vertical', show_points=False, x_label='', y_label='', title='', palette='tableau', width=800, height=500, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive box plot visualizer.
- Parameters:
data (dict of str → list of float) – Mapping of group name to values.
orientation (str, default='vertical') – ‘vertical’ or ‘horizontal’.
show_points (bool, default=False) – Show individual data points (jittered).
x_label (str, optional) – X-axis label.
y_label (str, optional) – Y-axis label.
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=800) – Chart width.
height (int, default=500) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- class endgame.visualization.ViolinPlotVisualizer(data, *, show_box=True, x_label='', y_label='', title='', palette='tableau', width=800, height=500, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive violin plot visualizer.
- Parameters:
data (dict of str → list of float) – Mapping of group name to values.
show_box (bool, default=True) – Show mini box plot inside violin.
x_label (str, optional) – X-axis label.
y_label (str, optional) – Y-axis label.
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=800) – Chart width.
height (int, default=500) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- class endgame.visualization.ErrorBarsVisualizer(labels, means, errors, *, orientation='horizontal', sort=True, x_label='', y_label='', title='', palette='tableau', width=800, height=500, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive error bar chart for model comparison.
- Parameters:
errors (list of float or list of tuple of float) – Symmetric errors (single value) or asymmetric (lo, hi) per point.
orientation (str, default='horizontal') – ‘horizontal’ or ‘vertical’.
sort (bool, default=True) – Sort by mean value.
x_label (str, optional) – Value axis label.
y_label (str, optional) – Category axis label.
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=800) – Chart width.
height (int, default=500) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- class endgame.visualization.ParallelCoordinatesVisualizer(data, *, dimensions=None, color_by=None, cmap='viridis_seq', title='', width=900, height=500, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive parallel coordinates visualizer.
- Parameters:
data (list of dict) – List of records, each a dict of dimension_name → value.
dimensions (list of str, optional) – Which dimensions to show (and in what order). If None, use all.
color_by (str, optional) – Dimension name to use for line coloring.
cmap (str, default='viridis_seq') – Color palette for continuous coloring.
title (str, optional) – Chart title.
width (int, default=900) – Chart width.
height (int, default=500) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- class endgame.visualization.RadarChartVisualizer(dimensions, series, *, ranges=None, fill=True, title='', palette='tableau', width=600, height=600, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive radar chart visualizer.
- Parameters:
series (dict of str → list of float) – Mapping of series name to values (one per dimension).
ranges (list of tuple of float, optional) – (min, max) for each dimension. If None, auto-computed.
fill (bool, default=True) – Fill polygon area.
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=600) – Chart width.
height (int, default=600) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- class endgame.visualization.TreemapVisualizer(labels, values, *, parents=None, title='', palette='tableau', width=800, height=500, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive treemap visualizer.
- Parameters:
- class endgame.visualization.SunburstVisualizer(labels, parents, values, *, title='', palette='tableau', width=600, height=600, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive sunburst chart visualizer.
- class endgame.visualization.SankeyVisualizer(nodes, links, *, title='', palette='tableau', width=900, height=500, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive Sankey diagram visualizer.
- Parameters:
- class endgame.visualization.DotMatrixVisualizer(labels, values, *, n_dots=100, dot_shape='circle', title='', palette='tableau', width=600, height=400, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive dot matrix (waffle) chart visualizer.
- Parameters:
values (list of float) – Values for each category (will be normalized to n_dots total).
n_dots (int, default=100) – Total number of dots.
dot_shape (str, default='circle') – ‘circle’ or ‘square’.
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=600) – Chart width.
height (int, default=400) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- class endgame.visualization.VennDiagramVisualizer(sets, intersections, *, title='', palette='tableau', width=600, height=500, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive Venn diagram visualizer (2 or 3 sets).
- Parameters:
sets (dict of str → int) – Set name → total count.
intersections (dict of str → int) – Intersection keys (e.g., ‘A&B’, ‘A&B&C’) → count.
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=600) – Chart width.
height (int, default=500) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- class endgame.visualization.WordCloudVisualizer(words, *, max_words=100, min_font=12, max_font=60, title='', palette='tableau', width=800, height=500, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive word cloud visualizer.
- Parameters:
words (dict of str → float) – Word/phrase → weight/frequency.
max_words (int, default=100) – Maximum number of words to display.
min_font (int, default=12) – Minimum font size in pixels.
max_font (int, default=60) – Maximum font size in pixels.
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=800) – Chart width.
height (int, default=500) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- class endgame.visualization.ArcDiagramVisualizer(nodes, edges, *, sort_by='input', thickness_range=(1.0, 8.0), title='', palette='tableau', width=900, height=500, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive arc diagram visualizer.
Nodes are placed along a horizontal line; edges are drawn as semicircular arcs above (and optionally below) the line. Arc thickness and opacity encode edge weight.
- Parameters:
edges (list of (str, str, float)) – Edges as (source, target, weight) tuples.
sort_by (str, default='input') – Node order: ‘input’ (given order), ‘degree’ (most connected first), ‘name’ (alphabetical).
thickness_range (tuple of float, default=(1, 8)) – Min and max arc stroke width (maps to weight).
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=900) – Chart width.
height (int, default=500) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- class endgame.visualization.ChordDiagramVisualizer(matrix, labels, *, title='', palette='tableau', width=650, height=650, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive chord diagram visualizer.
- Parameters:
matrix (array-like, shape (n, n)) – Symmetric or asymmetric flow matrix.
matrix[i][j]is the flow from group i to group j.title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=650) – Chart width.
height (int, default=650) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- class endgame.visualization.DonutChartVisualizer(labels, values, *, inner_radius_ratio=0.55, center_text='', title='', palette='tableau', width=600, height=550, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive donut chart visualizer.
- Parameters:
values (list of float) – Slice values (proportions are computed automatically).
inner_radius_ratio (float, default=0.55) – Ratio of inner to outer radius (0 = pie, ~0.6 = donut).
center_text (str, optional) – Text displayed in the center hole.
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=600) – Chart width.
height (int, default=550) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- class endgame.visualization.FlowChartVisualizer(nodes, edges, *, direction='LR', title='', palette='tableau', width=900, height=500, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive flow chart visualizer.
- Parameters:
nodes (list of dict) – Each dict must have ‘id’ and ‘label’. Optional keys: ‘type’ (‘input’, ‘process’, ‘decision’, ‘output’), ‘description’ (tooltip text).
edges (list of (str, str) or (str, str, str)) – Edges as (source_id, target_id) or (source_id, target_id, label).
direction (str, default='LR') – Flow direction: ‘LR’ (left-to-right), ‘TB’ (top-to-bottom).
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=900) – Chart width.
height (int, default=500) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- class endgame.visualization.NetworkDiagramVisualizer(nodes, edges, *, directed=True, node_sizes=None, layout='force', title='', palette='tableau', width=800, height=600, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive network diagram visualizer.
- Parameters:
nodes (list of str or list of dict) – Node labels (strings) or dicts with ‘id’, ‘label’, and optional ‘group’, ‘size’, ‘description’ keys.
edges (list of (str, str) or (str, str, float)) – Edges as (source, target) or (source, target, weight) tuples.
directed (bool, default=True) – If True, draw arrows on edges (for DAGs like Bayesian Networks).
node_sizes (dict of str → float, optional) – Custom node sizes. If None, sized by degree.
layout (str, default='force') – Layout algorithm: ‘force’ (force-directed), ‘hierarchical’ (top-down DAG), ‘circular’.
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=800) – Chart width.
height (int, default=600) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- classmethod from_bayesian_network(model, *, feature_names=None, **kwargs)[source]¶
Create from an endgame Bayesian classifier (TAN, KDB, ESKDB).
Extracts the DAG structure from the model’s learned network.
- Parameters:
- Return type:
- class endgame.visualization.NightingaleRoseVisualizer(labels, values, *, series_names=None, title='', palette='tableau', width=600, height=600, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive Nightingale Rose chart visualizer.
- Parameters:
values (list of float or dict of str → list of float) – Values for each category. Pass a dict for multiple series (overlaid petals).
series_names (list of str, optional) – Series names (when values is a dict).
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=600) – Chart width.
height (int, default=600) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- class endgame.visualization.RadialBarVisualizer(labels, values, *, inner_radius_ratio=0.3, sort=False, title='', palette='tableau', width=650, height=650, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive radial bar chart visualizer.
- Parameters:
inner_radius_ratio (float, default=0.3) – Ratio of inner radius to outer radius.
sort (bool, default=False) – If True, sort bars by value descending.
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=650) – Chart width.
height (int, default=650) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- class endgame.visualization.SpiralPlotVisualizer(values, *, labels=None, n_turns=None, color_by_value=True, cmap='blues', title='', width=650, height=650, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive spiral plot visualizer.
- Parameters:
values (array-like) – Sequential data values to plot along the spiral.
labels (list of str, optional) – Labels for each data point (shown on hover).
n_turns (float, optional) – Number of spiral turns. If None, auto-computed.
color_by_value (bool, default=True) – If True, color points by value. Otherwise use position.
cmap (str, default='viridis_seq') – Color palette for value mapping.
title (str, optional) – Chart title.
width (int, default=650) – Chart width.
height (int, default=650) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- class endgame.visualization.StreamGraphVisualizer(x, series, *, baseline='wiggle', title='', palette='tableau', width=900, height=500, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive stream graph visualizer.
- Parameters:
series (dict of str → list of float) – Mapping of series name to values at each x point.
baseline (str, default='wiggle') – Baseline algorithm: ‘zero’ (stacked from zero), ‘center’ (centered around zero), ‘wiggle’ (minimizes wiggle).
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=900) – Chart width.
height (int, default=500) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- class endgame.visualization.ROCCurveVisualizer(curves, *, title='', palette='tableau', width=650, height=600, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive ROC curve visualizer.
- Parameters:
curves (list of dict) – Each dict has keys ‘fpr’ (list of float), ‘tpr’ (list of float), ‘auc’ (float), ‘label’ (str).
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=650) – Chart width.
height (int, default=600) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- classmethod from_estimator(model, X, y, *, class_names=None, **kwargs)[source]¶
Create ROC curves from a fitted classifier.
For binary classifiers, plots a single curve. For multiclass, plots one-vs-rest curves for each class.
- Parameters:
- Return type:
- classmethod from_predictions(y_true, y_score, *, label='Model', **kwargs)[source]¶
Create ROC curve from predictions (binary).
- Parameters:
y_true (array-like) – True binary labels.
y_score (array-like) – Predicted probabilities or decision scores for the positive class.
label (str, default='Model') – Curve label.
**kwargs – Additional keyword arguments.
- Return type:
- class endgame.visualization.PRCurveVisualizer(curves, *, prevalence=None, title='', palette='tableau', width=650, height=600, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive Precision-Recall curve visualizer.
- Parameters:
curves (list of dict) – Each dict has keys ‘precision’ (list of float), ‘recall’ (list of float), ‘ap’ (float), ‘label’ (str).
prevalence (float, optional) – Positive class prevalence (shown as baseline).
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=650) – Chart width.
height (int, default=600) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- classmethod from_estimator(model, X, y, *, class_names=None, **kwargs)[source]¶
Create PR curves from a fitted classifier.
- Parameters:
- Return type:
- classmethod from_predictions(y_true, y_score, *, label='Model', **kwargs)[source]¶
Create PR curve from binary predictions.
- Parameters:
y_true (array-like) – True binary labels.
y_score (array-like) – Predicted probabilities for the positive class.
label (str, default='Model') – Curve label.
**kwargs – Additional keyword arguments.
- Return type:
- class endgame.visualization.CalibrationPlotVisualizer(curves, *, n_bins=10, title='', palette='tableau', width=650, height=700, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive calibration (reliability) diagram visualizer.
- Parameters:
curves (list of dict) – Each dict has keys ‘prob_true’ (list of float), ‘prob_pred’ (list of float), ‘counts’ (list of int), ‘label’ (str), ‘ece’ (float), ‘mce’ (float).
n_bins (int, default=10) – Number of bins (for reference; actual binning in constructors).
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=650) – Chart width.
height (int, default=700) – Chart height (taller to fit histogram below).
theme (str, default='dark') – ‘dark’ or ‘light’.
- classmethod from_estimator(model, X, y, *, n_bins=10, strategy='uniform', label=None, **kwargs)[source]¶
Create from a fitted classifier.
- Parameters:
model (estimator) – Fitted classifier with
predict_proba.X (array-like) – Test features.
y (array-like) – True binary labels.
n_bins (int, default=10) – Number of calibration bins.
strategy (str, default='uniform') – Binning strategy: ‘uniform’ or ‘quantile’.
label (str, optional) – Model label.
**kwargs – Additional keyword arguments.
- Return type:
- classmethod from_predictions(y_true, y_prob, *, n_bins=10, strategy='uniform', label='Model', **kwargs)[source]¶
Create from predictions.
- Parameters:
- Return type:
- class endgame.visualization.LiftChartVisualizer(curves, *, mode='both', title='', palette='tableau', width=850, height=550, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive lift / cumulative gains chart visualizer.
- Parameters:
curves (list of dict) – Each dict has keys ‘percentiles’ (list of float 0-1), ‘gains’ (list of float), ‘lift’ (list of float), ‘label’ (str).
mode (str, default='both') – ‘gains’ (cumulative gains only), ‘lift’ (lift only), or ‘both’ (gains on left, lift on right — dual axis).
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=850) – Chart width.
height (int, default=550) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- classmethod from_estimator(model, X, y, *, label=None, **kwargs)[source]¶
Create from a fitted classifier.
- Parameters:
model (estimator) – Fitted classifier with
predict_proba.X (array-like) – Test features.
y (array-like) – True binary labels.
label (str, optional) – Model label.
**kwargs – Additional keyword arguments.
- Return type:
- class endgame.visualization.PDPVisualizer(grid_values, pdp_values, *, ice_lines=None, feature_name='', is_categorical=False, title='', palette='tableau', width=750, height=500, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive partial dependence / ICE plot visualizer.
- Parameters:
pdp_values (list of float) – Partial dependence values (mean ICE).
ice_lines (list of list of float, optional) – Individual conditional expectation curves.
feature_name (str, default='') – Feature name for axis label.
is_categorical (bool, default=False) – Whether feature is categorical.
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=750) – Chart width.
height (int, default=500) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- classmethod from_estimator(model, X, *, feature=0, ice=True, n_ice_lines=50, grid_resolution=50, percentiles=(0.05, 0.95), target_class=1, **kwargs)[source]¶
Create PDP/ICE from a fitted model.
- Parameters:
model (estimator) – Fitted sklearn-compatible estimator.
X (array-like of shape (n_samples, n_features)) – Training data (used to build the grid and compute ICE).
ice (bool, default=True) – Whether to include ICE lines.
n_ice_lines (int, default=50) – Number of ICE lines to sample.
grid_resolution (int, default=50) – Number of grid points.
percentiles (tuple, default=(0.05, 0.95)) – Feature range percentiles.
target_class (int, default=1) – For classifiers, which class probability to show.
**kwargs – Additional keyword arguments.
- Return type:
- class endgame.visualization.PDP2DVisualizer(grid_x, grid_y, values, *, feature_x='', feature_y='', title='', palette='tableau', width=700, height=600, theme='dark')[source]¶
Bases:
BaseVisualizer2D partial dependence plot (heatmap).
- Parameters:
- classmethod from_estimator(model, X, *, features=(0, 1), grid_resolution=25, percentiles=(0.05, 0.95), target_class=1, **kwargs)[source]¶
Create 2D PDP from a fitted model.
- Parameters:
model (estimator) – Fitted sklearn-compatible estimator.
X (array-like) – Training data.
features (tuple of (int or str, int or str)) – Two feature indices or names.
grid_resolution (int, default=25) – Grid resolution per axis.
percentiles (tuple, default=(0.05, 0.95)) – Feature range percentiles.
target_class (int, default=1) – For classifiers, which class probability.
**kwargs – Additional keyword arguments.
- Return type:
- class endgame.visualization.WaterfallVisualizer(categories, values, *, base_value=None, final_value=None, show_connectors=True, sort_by=None, max_display=None, title='', palette='tableau', width=750, height=550, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive waterfall chart visualizer.
- Parameters:
values (list of float) – Contribution values (positive = increase, negative = decrease).
base_value (float, optional) – Starting/baseline value (shown at bottom).
final_value (float, optional) – Final value (shown at top). If None, computed as base + sum(values).
show_connectors (bool, default=True) – Show connector lines between bars.
sort_by (str, optional) – ‘abs’ to sort by absolute contribution, None for given order.
max_display (int, optional) – Maximum features to display. Remaining are grouped into “Other”.
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=750) – Chart width.
height (int, default=550) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- classmethod from_shap(shap_values, feature_names, base_value, *, max_display=15, **kwargs)[source]¶
Create from SHAP values for a single prediction.
- Parameters:
shap_values (array-like of shape (n_features,)) – SHAP values for one sample.
base_value (float) – Expected value (model output mean).
max_display (int, default=15) – Max features to display.
**kwargs – Additional keyword arguments.
- Return type:
- class endgame.visualization.RidgelinePlotVisualizer(data, *, overlap=0.5, kde_points=100, bandwidth=None, show_quantiles=True, title='', palette='tableau', width=800, height=500, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive ridgeline (joy) plot visualizer.
- Parameters:
data (dict of str → list of float) – Group name → raw values.
overlap (float, default=0.5) – Overlap ratio between adjacent ridges (0 = no overlap, 1 = full).
kde_points (int, default=100) – Number of points for KDE evaluation.
bandwidth (float, optional) – KDE bandwidth. If None, uses Silverman’s rule.
show_quantiles (bool, default=True) – Show median and Q1/Q3 markers.
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=800) – Chart width.
height (int, default=500) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- classmethod from_cv_results(results, **kwargs)[source]¶
Create from cross-validation results.
- Parameters:
- Return type:
- classmethod from_feature_distributions(X, feature_names=None, *, max_features=15, **kwargs)[source]¶
Create from feature column distributions.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Feature matrix.
max_features (int, default=15) – Max number of features to show.
**kwargs – Additional keyword arguments.
- Return type:
- class endgame.visualization.BumpChartVisualizer(x, rankings, *, title='', palette='tableau', width=800, height=500, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive bump chart visualizer.
- Parameters:
x (list) – X-axis labels (e.g. time points, fold names, rounds).
rankings (dict of str → list of int) – Series name → ranking at each x point (1 = best).
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=800) – Chart width.
height (int, default=500) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- classmethod from_scores(x, scores, *, higher_is_better=True, **kwargs)[source]¶
Create from raw scores, converting to rankings.
- Parameters:
- Return type:
- class endgame.visualization.LollipopChartVisualizer(labels, values, *, orientation='horizontal', sort=False, highlight_top=None, baseline=0, title='', palette='tableau', width=750, height=500, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive lollipop chart visualizer.
- Parameters:
orientation (str, default='horizontal') – ‘horizontal’ (labels on Y) or ‘vertical’ (labels on X).
sort (bool, default=False) – Sort by value (descending).
highlight_top (int, optional) – Number of top items to highlight with larger dots.
baseline (float, default=0) – Baseline value where stems start.
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=750) – Chart width.
height (int, default=500) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- classmethod from_importances(model, *, feature_names=None, top_n=None, **kwargs)[source]¶
Create from model feature importances.
- Parameters:
- Return type:
- class endgame.visualization.DumbbellChartVisualizer(labels, values_start, values_end, *, start_label='Start', end_label='End', sort_by=None, title='', palette='tableau', width=750, height=500, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive dumbbell chart visualizer.
- Parameters:
start_label (str, default='Start') – Legend label for starting dots.
end_label (str, default='End') – Legend label for ending dots.
sort_by (str, optional) – ‘diff’ to sort by difference, ‘end’ to sort by end value, ‘start’ to sort by start value, None for given order.
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=750) – Chart width.
height (int, default=500) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- classmethod from_metrics(labels, before, after, *, start_label='Before', end_label='After', **kwargs)[source]¶
Create from before/after metric dicts.
- class endgame.visualization.FunnelChartVisualizer(stages, values, *, show_percentages=True, title='', palette='tableau', width=700, height=500, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive funnel chart visualizer.
- Parameters:
values (list of float) – Values at each stage (should generally decrease).
show_percentages (bool, default=True) – Show percentage of initial value and step-to-step retention.
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=700) – Chart width.
height (int, default=500) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- classmethod from_pipeline(stages, sample_counts, **kwargs)[source]¶
Create from a data pipeline with sample counts.
- Parameters:
- Return type:
- class endgame.visualization.GaugeChartVisualizer(value, *, min_value=0, max_value=1, label='', zones=None, format_str=None, title='', palette='tableau', width=450, height=350, theme='dark')[source]¶
Bases:
BaseVisualizerInteractive gauge chart visualizer.
- Parameters:
value (float) – Current metric value.
min_value (float, default=0) – Minimum scale value.
max_value (float, default=1) – Maximum scale value.
label (str, default='') – Metric label shown below the value.
zones (list of (float, float, str), optional) – Colored zones as (start, end, color). If None, uses default red/yellow/green zones dividing the range into thirds.
format_str (str, optional) – Python format string for the displayed value (e.g., ‘.1%’, ‘.3f’).
title (str, optional) – Chart title.
palette (str, default='tableau') – Color palette.
width (int, default=450) – Chart width.
height (int, default=350) – Chart height.
theme (str, default='dark') – ‘dark’ or ‘light’.
- classmethod from_score(score, metric_name='Score', *, min_value=0, max_value=1, **kwargs)[source]¶
Create from a single metric score.
- Parameters:
- Return type:
- class endgame.visualization.ClassificationReport(model, X, y, *, feature_names=None, class_names=None, model_name=None, dataset_name=None, palette='tableau', theme='dark')[source]¶
Bases:
objectComprehensive classification model evaluation report.
Generates a multi-section HTML report with metrics, charts, and model interpretability for any sklearn-compatible classifier.
- Parameters:
model (estimator) – Fitted sklearn-compatible classifier.
X (array-like) – Test features.
y (array-like) – True labels.
class_names (list of str, optional) – Class label names. Auto-detected from
model.classes_if absent.model_name (str, optional) – Display name for the model.
dataset_name (str, optional) – Display name for the dataset.
palette (str, default='tableau') – Color palette.
theme (str, default='dark') – ‘dark’ or ‘light’.
Examples
>>> from sklearn.ensemble import RandomForestClassifier >>> clf = RandomForestClassifier().fit(X_train, y_train) >>> report = ClassificationReport(clf, X_test, y_test) >>> report.save("report.html")
- class endgame.visualization.RegressionReport(model, X, y, *, feature_names=None, model_name=None, dataset_name=None, palette='tableau', theme='dark')[source]¶
Bases:
objectComprehensive regression model evaluation report.
Generates a multi-section HTML report with metrics, charts, and model interpretability for any sklearn-compatible regressor.
- Parameters:
model (estimator) – Fitted sklearn-compatible regressor.
X (array-like) – Test features.
y (array-like) – True target values.
model_name (str, optional) – Display name for the model.
dataset_name (str, optional) – Display name for the dataset.
palette (str, default='tableau') – Color palette.
theme (str, default='dark') – ‘dark’ or ‘light’.
Examples
>>> from sklearn.ensemble import RandomForestRegressor >>> reg = RandomForestRegressor().fit(X_train, y_train) >>> report = RegressionReport(reg, X_test, y_test) >>> report.save("report.html")
Tree Visualization¶
- class endgame.visualization.TreeVisualizer(model, feature_names=None, class_names=None, tree_index=0, title=None, color_by='prediction', max_depth=None, palette='tableau')[source]¶
Bases:
objectInteractive decision tree visualizer.
Generates self-contained HTML files with D3.js-powered interactive tree visualizations featuring: - Expandable/collapsible branches (click nodes) - Zoom in/out and pan (mouse wheel + drag) - Rich tooltips with node statistics - Color-coded nodes by prediction or impurity - Responsive layout
- Parameters:
model (estimator) – A fitted tree model. Supports: - sklearn DecisionTreeClassifier/Regressor - sklearn ensembles (extracts individual trees) - C50Classifier / C50Ensemble - ObliqueDecisionTreeClassifier/Regressor - ObliqueRandomForestClassifier/Regressor - EvolutionaryTreeClassifier/Regressor
feature_names (list of str, optional) – Names for each feature. If None, uses “feature_0”, “feature_1”, etc.
class_names (list of str, optional) – Names for each class (classification only).
tree_index (int, default=0) – For ensemble models, which tree to visualize.
title (str, optional) – Title displayed above the visualization.
color_by (str, default='prediction') – How to color nodes: ‘prediction’ (class color), ‘impurity’ (heatmap), or ‘samples’ (by sample count).
max_depth (int, optional) – Maximum depth to display. Deeper nodes are collapsed by default.
palette (str, default='tableau') – Color palette: ‘tableau’, ‘viridis’, ‘pastel’, or ‘dark’.
Example
>>> from sklearn.datasets import load_iris >>> from sklearn.tree import DecisionTreeClassifier >>> from endgame.visualization import TreeVisualizer >>> >>> X, y = load_iris(return_X_y=True) >>> clf = DecisionTreeClassifier(max_depth=4, random_state=42).fit(X, y) >>> viz = TreeVisualizer( ... clf, ... feature_names=load_iris().feature_names, ... class_names=load_iris().target_names.tolist(), ... title="Iris Decision Tree" ... ) >>> viz.save("iris_tree.html")