API Reference
This page is auto-generated from Python docstrings.
ml_vizkit
ML VizKit public API.
Reusable visualizations for inspecting, comparing, and explaining trained machine-learning models.
compare_models
compare_models(
scores: Mapping[str, float],
*,
ax: Axes | None = None,
metric_name: str = 'Score',
title: str = 'Model Comparison',
) -> Axes
Compare evaluation scores from already-completed model experiments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scores
|
Mapping[str, float]
|
A mapping from model names to their evaluation scores. |
required |
ax
|
Axes | None
|
The Matplotlib Axes to plot on. If None, a new Axes is created. |
None
|
metric_name
|
str
|
The name of the evaluation metric. |
'Score'
|
title
|
str
|
The title of the plot. |
'Model Comparison'
|
Returns:
| Type | Description |
|---|---|
Axes
|
The Matplotlib Axes containing the plot. |
WHY: A consistent visual basis helps analysts compare models evaluated with the same metric and experimental conditions.
NOTE: This function assumes the caller has already established that the supplied scores are meaningfully comparable.
Source code in src/ml_vizkit/comparison.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
compare_splits
compare_splits(
splits: Sequence[SplitView],
) -> tuple[Axes, ...]
Create one train/test visualization per completed split.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
splits
|
Sequence[SplitView]
|
A sequence of SplitView instances representing the completed splits. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Axes, ...]
|
A tuple of Matplotlib Axes, each containing the visualization for one split. |
WHY: Comparing several partitions makes sampling variability visible.
This function does not create splits or train models. Each visualization is created in its own figure, and all Axes are returned to the caller.
Source code in src/ml_vizkit/comparison.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
save_chart
save_chart(
ax: Axes,
path: str | Path,
*,
bbox_inches: str | None = 'tight',
) -> None
Save chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
The matplotlib Axes object containing the chart to save. |
required |
path
|
str | Path
|
The file path where the chart should be saved. |
required |
bbox_inches
|
str | None
|
The bounding box in inches. Defaults to "tight". |
'tight'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the Axes is not attached to a Figure. |
Source code in src/ml_vizkit/save.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
show_actual_vs_predicted
show_actual_vs_predicted(
y_true: Numeric1D,
y_pred: Numeric1D,
*,
ax: Axes | None = None,
title: str = 'Actual vs. Predicted',
) -> Axes
Show actual versus predicted regression values.
WHY: Good predictions should generally fall near the identity line.
The implementation delegates to scikit-learn's PredictionErrorDisplay.
Source code in src/ml_vizkit/regression.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
show_class_distribution
show_class_distribution(
y: Numeric1D,
*,
ax: Axes | None = None,
title: str = 'Class Distribution',
x_label: str = 'Class',
) -> Axes
Show the number of observations in each target class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
Numeric1D
|
The target labels. |
required |
ax
|
Axes | None
|
The Matplotlib Axes to plot on. If None, a new Axes is created. |
None
|
title
|
str
|
The title of the plot. |
'Class Distribution'
|
x_label
|
str
|
The label for the x-axis. |
'Class'
|
Returns:
| Type | Description |
|---|---|
Axes
|
The Matplotlib Axes containing the plot. |
WHY: Class imbalance can affect training, evaluation, and interpretation.
Source code in src/ml_vizkit/classification.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
show_confusion_matrix
show_confusion_matrix(
y_true: Numeric1D,
y_pred: Numeric1D,
*,
labels: Sequence[Any] | None = None,
normalize: str | None = None,
ax: Axes | None = None,
title: str = 'Confusion Matrix',
) -> Axes
Show a confusion matrix from completed classification predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
Numeric1D
|
The true labels. |
required |
y_pred
|
Numeric1D
|
The predicted labels. |
required |
labels
|
Sequence[Any] | None
|
Optional sequence of labels to include in the matrix. |
None
|
normalize
|
str | None
|
Normalization method for the confusion matrix. |
None
|
ax
|
Axes | None
|
The Matplotlib Axes to plot on. If None, a new Axes is created. |
None
|
title
|
str
|
The title of the plot. |
'Confusion Matrix'
|
Returns:
| Type | Description |
|---|---|
Axes
|
The Matplotlib Axes containing the plot. |
WHY: Overall accuracy can hide which classes are being confused.
This function delegates the matrix visualization to scikit-learn and returns the Matplotlib Axes.
Source code in src/ml_vizkit/classification.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
show_decision_boundary
show_decision_boundary(
model: Any,
X: DataFrame,
y: Sequence[Any] | None = None,
*,
ax: Axes | None = None,
response_method: str = 'auto',
plot_method: str = 'contourf',
title: str = 'Decision Boundary',
alpha: float = 0.25,
) -> Axes
Show the decision boundary for an already-trained classifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
The trained classifier to visualize. |
required |
X
|
DataFrame
|
A DataFrame containing exactly two numeric features. |
required |
y
|
Sequence[Any] | None
|
Optional sequence of true labels corresponding to X. |
None
|
ax
|
Axes | None
|
The Matplotlib Axes to plot on. If None, a new Axes is created. |
None
|
response_method
|
str
|
The response method to use for the decision boundary. |
'auto'
|
plot_method
|
str
|
The plotting method for the decision boundary. |
'contourf'
|
title
|
str
|
The title of the plot. |
'Decision Boundary'
|
alpha
|
float
|
The transparency level for the decision boundary. |
0.25
|
Returns:
| Type | Description |
|---|---|
Axes
|
The Matplotlib Axes containing the plot. |
WHY: A decision boundary makes the classifier's learned separation of feature space visible.
REQ: X must contain exactly two numeric features. REQ: model must already be fitted.
The implementation delegates boundary construction to scikit-learn's DecisionBoundaryDisplay and returns the Matplotlib Axes to the caller.
Source code in src/ml_vizkit/classification.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
show_feature_importance
show_feature_importance(
model: Any,
feature_names: Sequence[str],
*,
ax: Axes | None = None,
title: str = 'Feature Importance',
) -> Axes
Show model-provided feature importance values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
The already-trained model exposing |
required |
feature_names
|
Sequence[str]
|
The names of the features corresponding to the importance values. |
required |
ax
|
Axes | None
|
The Matplotlib Axes to plot on. If None, a new Axes is created. |
None
|
title
|
str
|
The title of the plot. |
'Feature Importance'
|
Returns:
| Type | Description |
|---|---|
Axes
|
The Matplotlib Axes containing the plot. |
WHY: Importance values can help analysts investigate which features most influenced a fitted model.
REQ: The model must already expose feature_importances_.
Source code in src/ml_vizkit/inspection.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
show_prediction_errors
show_prediction_errors(
X: DataFrame,
y_true: Numeric1D,
y_pred: Numeric1D,
*,
ax: Axes | None = None,
title: str = 'Classification Prediction Errors',
) -> Axes
Show correct and incorrect classifications in two-feature space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame
|
A DataFrame containing exactly two numeric features. |
required |
y_true
|
Numeric1D
|
The true labels. |
required |
y_pred
|
Numeric1D
|
The predicted labels. |
required |
ax
|
Axes | None
|
The Matplotlib Axes to plot on. If None, a new Axes is created. |
None
|
title
|
str
|
The title of the plot. |
'Classification Prediction Errors'
|
Returns:
| Type | Description |
|---|---|
Axes
|
The Matplotlib Axes containing the plot. |
WHY: Looking directly at mistakes can reveal overlap, unusual observations, and regions where a classifier struggles.
REQ: X must contain exactly two numeric features.
Source code in src/ml_vizkit/classification.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
show_residuals
show_residuals(
y_true: Numeric1D,
y_pred: Numeric1D,
*,
ax: Axes | None = None,
title: str = 'Residuals vs. Predicted',
) -> Axes
Show regression residuals against predicted values.
WHY: Residual plots can reveal systematic error patterns, changing variance, and unusual observations.
The implementation delegates to scikit-learn's PredictionErrorDisplay.
Source code in src/ml_vizkit/regression.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
show_train_test_split
show_train_test_split(
X_train: DataFrame,
X_test: DataFrame,
*,
ax: Axes | None = None,
title: str = 'Train/Test Split',
) -> Axes
Show which observations were assigned to training and testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X_train
|
DataFrame
|
The training feature DataFrame containing exactly two numeric features. |
required |
X_test
|
DataFrame
|
The testing feature DataFrame containing exactly two numeric features. |
required |
ax
|
Axes | None
|
The Matplotlib Axes to plot on. If None, a new Axes is created. |
None
|
title
|
str
|
The title of the plot. |
'Train/Test Split'
|
Returns:
| Type | Description |
|---|---|
Axes
|
The Matplotlib Axes containing the plot. |
WHY: Seeing the actual partition makes random splitting concrete instead of treating the random seed as unexplained boilerplate.
REQ: Both frames must contain the same two numeric features.
Source code in src/ml_vizkit/splits.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
classification
Classification visualizations.
These functions visualize trained classifiers and completed predictions. They do not fit models or choose analytical settings.
show_class_distribution
show_class_distribution(
y: Numeric1D,
*,
ax: Axes | None = None,
title: str = 'Class Distribution',
x_label: str = 'Class',
) -> Axes
Show the number of observations in each target class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
Numeric1D
|
The target labels. |
required |
ax
|
Axes | None
|
The Matplotlib Axes to plot on. If None, a new Axes is created. |
None
|
title
|
str
|
The title of the plot. |
'Class Distribution'
|
x_label
|
str
|
The label for the x-axis. |
'Class'
|
Returns:
| Type | Description |
|---|---|
Axes
|
The Matplotlib Axes containing the plot. |
WHY: Class imbalance can affect training, evaluation, and interpretation.
Source code in src/ml_vizkit/classification.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
show_confusion_matrix
show_confusion_matrix(
y_true: Numeric1D,
y_pred: Numeric1D,
*,
labels: Sequence[Any] | None = None,
normalize: str | None = None,
ax: Axes | None = None,
title: str = 'Confusion Matrix',
) -> Axes
Show a confusion matrix from completed classification predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
Numeric1D
|
The true labels. |
required |
y_pred
|
Numeric1D
|
The predicted labels. |
required |
labels
|
Sequence[Any] | None
|
Optional sequence of labels to include in the matrix. |
None
|
normalize
|
str | None
|
Normalization method for the confusion matrix. |
None
|
ax
|
Axes | None
|
The Matplotlib Axes to plot on. If None, a new Axes is created. |
None
|
title
|
str
|
The title of the plot. |
'Confusion Matrix'
|
Returns:
| Type | Description |
|---|---|
Axes
|
The Matplotlib Axes containing the plot. |
WHY: Overall accuracy can hide which classes are being confused.
This function delegates the matrix visualization to scikit-learn and returns the Matplotlib Axes.
Source code in src/ml_vizkit/classification.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
show_decision_boundary
show_decision_boundary(
model: Any,
X: DataFrame,
y: Sequence[Any] | None = None,
*,
ax: Axes | None = None,
response_method: str = 'auto',
plot_method: str = 'contourf',
title: str = 'Decision Boundary',
alpha: float = 0.25,
) -> Axes
Show the decision boundary for an already-trained classifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
The trained classifier to visualize. |
required |
X
|
DataFrame
|
A DataFrame containing exactly two numeric features. |
required |
y
|
Sequence[Any] | None
|
Optional sequence of true labels corresponding to X. |
None
|
ax
|
Axes | None
|
The Matplotlib Axes to plot on. If None, a new Axes is created. |
None
|
response_method
|
str
|
The response method to use for the decision boundary. |
'auto'
|
plot_method
|
str
|
The plotting method for the decision boundary. |
'contourf'
|
title
|
str
|
The title of the plot. |
'Decision Boundary'
|
alpha
|
float
|
The transparency level for the decision boundary. |
0.25
|
Returns:
| Type | Description |
|---|---|
Axes
|
The Matplotlib Axes containing the plot. |
WHY: A decision boundary makes the classifier's learned separation of feature space visible.
REQ: X must contain exactly two numeric features. REQ: model must already be fitted.
The implementation delegates boundary construction to scikit-learn's DecisionBoundaryDisplay and returns the Matplotlib Axes to the caller.
Source code in src/ml_vizkit/classification.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
show_prediction_errors
show_prediction_errors(
X: DataFrame,
y_true: Numeric1D,
y_pred: Numeric1D,
*,
ax: Axes | None = None,
title: str = 'Classification Prediction Errors',
) -> Axes
Show correct and incorrect classifications in two-feature space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame
|
A DataFrame containing exactly two numeric features. |
required |
y_true
|
Numeric1D
|
The true labels. |
required |
y_pred
|
Numeric1D
|
The predicted labels. |
required |
ax
|
Axes | None
|
The Matplotlib Axes to plot on. If None, a new Axes is created. |
None
|
title
|
str
|
The title of the plot. |
'Classification Prediction Errors'
|
Returns:
| Type | Description |
|---|---|
Axes
|
The Matplotlib Axes containing the plot. |
WHY: Looking directly at mistakes can reveal overlap, unusual observations, and regions where a classifier struggles.
REQ: X must contain exactly two numeric features.
Source code in src/ml_vizkit/classification.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
comparison
Higher-level visual comparisons of completed ML experiments.
SplitView
dataclass
Data needed to visualize one already-created train/test split.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
A descriptive label for the split. |
required |
X_train
|
DataFrame
|
The training feature set. |
required |
X_test
|
DataFrame
|
The testing feature set. |
required |
score
|
float | None
|
Optional evaluation score for the split. |
None
|
Returns:
| Type | Description |
|---|---|
|
An instance of SplitView containing the data for the split. |
Source code in src/ml_vizkit/comparison.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
compare_models
compare_models(
scores: Mapping[str, float],
*,
ax: Axes | None = None,
metric_name: str = 'Score',
title: str = 'Model Comparison',
) -> Axes
Compare evaluation scores from already-completed model experiments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scores
|
Mapping[str, float]
|
A mapping from model names to their evaluation scores. |
required |
ax
|
Axes | None
|
The Matplotlib Axes to plot on. If None, a new Axes is created. |
None
|
metric_name
|
str
|
The name of the evaluation metric. |
'Score'
|
title
|
str
|
The title of the plot. |
'Model Comparison'
|
Returns:
| Type | Description |
|---|---|
Axes
|
The Matplotlib Axes containing the plot. |
WHY: A consistent visual basis helps analysts compare models evaluated with the same metric and experimental conditions.
NOTE: This function assumes the caller has already established that the supplied scores are meaningfully comparable.
Source code in src/ml_vizkit/comparison.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
compare_splits
compare_splits(
splits: Sequence[SplitView],
) -> tuple[Axes, ...]
Create one train/test visualization per completed split.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
splits
|
Sequence[SplitView]
|
A sequence of SplitView instances representing the completed splits. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Axes, ...]
|
A tuple of Matplotlib Axes, each containing the visualization for one split. |
WHY: Comparing several partitions makes sampling variability visible.
This function does not create splits or train models. Each visualization is created in its own figure, and all Axes are returned to the caller.
Source code in src/ml_vizkit/comparison.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
inspection
Visual inspection of already-trained model characteristics.
show_feature_importance
show_feature_importance(
model: Any,
feature_names: Sequence[str],
*,
ax: Axes | None = None,
title: str = 'Feature Importance',
) -> Axes
Show model-provided feature importance values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
The already-trained model exposing |
required |
feature_names
|
Sequence[str]
|
The names of the features corresponding to the importance values. |
required |
ax
|
Axes | None
|
The Matplotlib Axes to plot on. If None, a new Axes is created. |
None
|
title
|
str
|
The title of the plot. |
'Feature Importance'
|
Returns:
| Type | Description |
|---|---|
Axes
|
The Matplotlib Axes containing the plot. |
WHY: Importance values can help analysts investigate which features most influenced a fitted model.
REQ: The model must already expose feature_importances_.
Source code in src/ml_vizkit/inspection.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
regression
Regression visualizations for completed predictions.
show_actual_vs_predicted
show_actual_vs_predicted(
y_true: Numeric1D,
y_pred: Numeric1D,
*,
ax: Axes | None = None,
title: str = 'Actual vs. Predicted',
) -> Axes
Show actual versus predicted regression values.
WHY: Good predictions should generally fall near the identity line.
The implementation delegates to scikit-learn's PredictionErrorDisplay.
Source code in src/ml_vizkit/regression.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
show_residuals
show_residuals(
y_true: Numeric1D,
y_pred: Numeric1D,
*,
ax: Axes | None = None,
title: str = 'Residuals vs. Predicted',
) -> Axes
Show regression residuals against predicted values.
WHY: Residual plots can reveal systematic error patterns, changing variance, and unusual observations.
The implementation delegates to scikit-learn's PredictionErrorDisplay.
Source code in src/ml_vizkit/regression.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
save
Save visualization outputs.
save_chart
save_chart(
ax: Axes,
path: str | Path,
*,
bbox_inches: str | None = 'tight',
) -> None
Save chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
The matplotlib Axes object containing the chart to save. |
required |
path
|
str | Path
|
The file path where the chart should be saved. |
required |
bbox_inches
|
str | None
|
The bounding box in inches. Defaults to "tight". |
'tight'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the Axes is not attached to a Figure. |
Source code in src/ml_vizkit/save.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
splits
Visualizations for already-created train/test partitions.
show_train_test_split
show_train_test_split(
X_train: DataFrame,
X_test: DataFrame,
*,
ax: Axes | None = None,
title: str = 'Train/Test Split',
) -> Axes
Show which observations were assigned to training and testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X_train
|
DataFrame
|
The training feature DataFrame containing exactly two numeric features. |
required |
X_test
|
DataFrame
|
The testing feature DataFrame containing exactly two numeric features. |
required |
ax
|
Axes | None
|
The Matplotlib Axes to plot on. If None, a new Axes is created. |
None
|
title
|
str
|
The title of the plot. |
'Train/Test Split'
|
Returns:
| Type | Description |
|---|---|
Axes
|
The Matplotlib Axes containing the plot. |
WHY: Seeing the actual partition makes random splitting concrete instead of treating the random seed as unexplained boilerplate.
REQ: Both frames must contain the same two numeric features.
Source code in src/ml_vizkit/splits.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |