modeva.TestSuite.explain_ale#

TestSuite.explain_ale(features: str | Tuple[str] = None, dataset: str = 'test', sample_size: int = 5000, grid_resolution: int = 20, response_method: str = 'auto', random_state: int = 0)#

Calculate Accumulated Local Effects (ALE) plots for one or two features.

ALE plots show how individual features influence model predictions while accounting for feature interactions by measuring effects locally rather than assuming independence across features as in partial dependence.

Parameters:
  • features (str or tuple of str) – Feature name(s) to analyze. Use a single feature name for 1D ALE plot or a tuple of two feature names for 2D ALE plot. For 2D ALE, categorical features are not supported.

  • dataset ({"main", "train", "test"}, default="test") – Dataset to use for calculating the explanation results.

  • sample_size (int, default=5000) – Number of random samples to use for calculation. If None, uses entire dataset. Smaller samples speed up calculation but may reduce accuracy.

  • grid_resolution (int, default=20) – Number of intervals to divide feature range for ALE calculation. Higher values give finer granularity but increase computation time.

  • response_method ({"auto", "decision_function", "predict_proba"}, default="auto") –

    Prediction method to use for binary classification tasks:

    • ”auto”: Uses ‘predict_proba’ if available, otherwise ‘decision_function’

    • ”predict_proba”: Probability of the positive class

    • ”decision_function”: Model’s decision function output

  • random_state (int, default=0) – Random seed for reproducible sampling when sample_size is specified.

Returns:

Object containing:

  • key: “explain_ale”

  • data: Name of the dataset used

  • model: Name of the model used

  • inputs: Input parameters used for the analysis

  • value: Dictionary containing

    • ”Value”: X grid values, can be a single 1D-array (1D) or list or 2 1D-arrays (2D);

    • ”Effect”: ALE values corresponding to grid values, can be a single 1D-array (1D) or 2D-array (2D)

  • table: DataFrame of ALE results

  • options: Dictionary of visualizations configuration for a line (1D numerical) / bar (1D categorical) / heatmap (2D) effect plot. Run results.plot() to show all plots; To display one preferred plot by results.plot(name=xxx), and the following names are available:

    • None: Effect plots of all effects specified in features.

    • ”<effect_name>”: Effect plot of the selected main effect or pairwise interaction.

Return type:

ValidationResult

Raises:

ValueError – If attempting 2D ALE plot with categorical features.

Notes

For single features, generates a line or bar plot depending on feature type. For two features, generates a heatmap showing the interaction effects.

Examples

Global Explainability

Global Explainability