Skip to content

Feature: Add plot_error_analysis_chart for visual error analysis in XAI module #83

@idanmoradarthas

Description

@idanmoradarthas

Description

I would like to add a new function plot_error_analysis_chart to the XAI module. This function should automate the creation of an error analysis DataFrame (calculating TP, TN, FP, FN) and visualize feature interactions relative to prediction errors using the existing preprocessing utilities.

The function must support both binary and multi-class classification by analyzing the performance with respect to a specific positive_class.

Requirements:

Input Parameters:

  • y_true: Array-like of true labels.
  • y_pred: Array-like of predicted labels.
  • y_proba: Array-like of predicted probabilities (binary: 1D; multi-class: 2D with shape (n_samples, n_classes)).
  • positive_class: The class to treat as positive (for defining 'TP', 'FP', 'FN', 'TN' in binary or one-vs-rest for multi-class).
  • threshold: float = 0.5 (for binary probability threshold).
  • Additional kwargs passed to plot_features_interaction.

Functionality:

  • Internally create error_df:
    • Columns: 'y_true', 'y_pred', relevant probability.
    • Compute 'error_type' column: 'TP', 'TN', 'FP', 'FN' (binary directly; multi-class via one-vs-rest on positive_class).
    • Skeleton code for binary class:
    error_df = X_test.copy()
    error_df["y_true"] = y_test
    error_df["y_pred"] = y_pred
    error_df["y_proba"] = y_proba
    
    error_df["error_type"] = np.select(
    [
        (error_df.y_true == 1) & (error_df.y_pred == 0),
        (error_df.y_true == 0) & (error_df.y_pred == 1),
    ],
    ["false_negative", "false_positive"],
    default="correct"
    )
  • Call from ds_utils.preprocess import plot_features_interaction with appropriate data and kwargs to highlight errors. for example: plot_features_interaction(error_df, "y_proba", "error_type")

Here is an example plot that should be created:
Image

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions