pycsamt.ai.plot.diagnostics#

Diagnostic plots for AI/ML model evaluation.

All functions follow the EMStyle publication conventions and accept an optional ax parameter for embedding in composite figures.

Functions

plot_confusion_matrix(y_true, y_pred, *[, ...])

Plot a confusion matrix for a classification model.

plot_feature_importance(importances[, ...])

Horizontal bar chart of feature importances.

plot_layer_errors(y_true, y_pred, n_layers, *)

Per-layer mean absolute error bar chart.

plot_residuals(y_true, y_pred, *[, ...])

Scatter plots of predicted vs. true for each model parameter.

plot_uncertainty_bands(x, y_pred, y_upper, ...)

1-D prediction curve with uncertainty bands.

pycsamt.ai.plot.diagnostics.plot_confusion_matrix(y_true, y_pred, *, class_names=None, normalise=True, cmap='Blues', title='Confusion Matrix', figsize=None, ax=None, style=True)[source]#

Plot a confusion matrix for a classification model.

Parameters:
  • y_true (int ndarray (n_samples,)) – Ground-truth class labels.

  • y_pred (int ndarray (n_samples,)) – Predicted class labels.

  • class_names (list of str or None) – Display labels for each class. Defaults to ['1-D','2-D','3-D'] for three-class problems.

  • normalise (bool) – Show row-normalised (recall) fractions.

  • cmap (str) – Matplotlib colormap.

  • title (see plot_section().)

  • figsize (see plot_section().)

  • ax (see plot_section().)

  • style (see plot_section().)

Returns:

fig

Return type:

Figure

pycsamt.ai.plot.diagnostics.plot_residuals(y_true, y_pred, *, param_names=None, n_cols=4, figsize_per_panel=(2.5, 2.5), style=True)[source]#

Scatter plots of predicted vs. true for each model parameter.

Each panel shows the 1:1 line, coloured scatter, and per-parameter R² annotation.

Parameters:
Returns:

fig

Return type:

Figure

pycsamt.ai.plot.diagnostics.plot_layer_errors(y_true, y_pred, n_layers, *, log_rho=True, ax=None, figsize=None, style=True)[source]#

Per-layer mean absolute error bar chart.

Parameters:
  • y_true (ndarray (n_samples, 2*n_layers-1))

  • y_pred (ndarray (n_samples, 2*n_layers-1))

  • n_layers (int)

  • log_rho (bool) – Label ρ columns as log₁₀(ρ).

  • ax (Axes or None)

  • figsize ((width, height) or None)

  • style (bool)

Returns:

fig

Return type:

Figure

pycsamt.ai.plot.diagnostics.plot_uncertainty_bands(x, y_pred, y_upper, y_lower, y_true=None, *, ax=None, xlabel='', ylabel='', title='Prediction with Uncertainty', figsize=None, style=True)[source]#

1-D prediction curve with uncertainty bands.

Suitable for showing per-site model parameter predictions (e.g. resistivity vs. depth) with ±1σ or 10/90 percentile bands.

Parameters:
  • x (ndarray (n_points,)) – X-axis values (e.g. depth or frequency).

  • y_pred (ndarray (n_points,)) – Central prediction.

  • y_upper (ndarray (n_points,)) – Upper and lower uncertainty bounds.

  • y_lower (ndarray (n_points,)) – Upper and lower uncertainty bounds.

  • y_true (ndarray (n_points,) or None) – Ground-truth values to overlay.

  • ax (Axes or None)

  • xlabel (str)

  • ylabel (str)

  • title (str)

  • figsize ((width, height) or None)

  • style (bool)

Returns:

fig

Return type:

Figure

pycsamt.ai.plot.diagnostics.plot_feature_importance(importances, feature_names=None, *, top_n=20, horizontal=True, ax=None, figsize=None, title='Feature Importance', style=True)[source]#

Horizontal bar chart of feature importances.

Compatible with scikit-learn feature_importances_ arrays and any non-negative importance measure.

Parameters:
  • importances (ndarray (n_features,))

  • feature_names (list of str or None)

  • top_n (int) – Show only the top n features by importance.

  • horizontal (bool) – Use horizontal bars (default) for long feature names.

  • ax (Axes or None)

  • figsize ((width, height) or None)

  • title (str)

  • style (bool)

Returns:

fig

Return type:

Figure