iml: Interpretable Machine Learning

Giuseppe Casalicchio, Christoph Molnar, Patrick SchratzOpenalex Unknown 2018 · OpenAlex

Abstract

The iml package provides a comprehensive suite of interpretability methods to analyze the behavior and predictions of any machine learning model. It implements state-of-the-art techniques including feature importance (Fisher et al., 2018), accumulated local effects (ALE) plots (Apley, 2018), partial dependence plots (PDP) (Friedman, 2001), individual conditional expectation (ICE) plots (Goldstein et al., 2013), local models/LIME (Ribeiro et al., 2016), Shapley values (Strumbelj et al., 2014), and feature interactions (Friedman et al., 2008). By offering a model-agnostic framework, iml enables consistent evaluation across diverse algorithmic architectures.

Introduction: The Challenge of the Black Box

As machine learning models grow in complexity—transitioning from simple linear regressions to deep neural networks and massive ensembles—they often become "black boxes." While these models achieve high predictive accuracy, they offer little inherent transparency regarding their decision-making processes. This creates a significant hurdle for researchers and practitioners who require trust, accountability, and insight into model behavior.

The iml package addresses this need by providing a unified, model-agnostic interface for interpretability. Before its introduction, researchers often had to navigate disparate tools with inconsistent APIs. iml centralizes these techniques, allowing users to analyze feature importance, feature effects, and individual predictions without needing to write custom code for every specific model type, such as randomForest, keras, or mlr3.

A Unified Framework for Interpretability

The package is built on an object-oriented R6 framework designed for flexibility and ease of use. The core workflow involves wrapping a trained model and its associated data into a Predictor object. This abstraction layer allows the interpretability algorithms to interact with the model solely through its prediction function, ensuring that the package remains compatible with any existing or future machine learning library.

Global and Local Explanation Methods

iml categorizes its tools into global and local explanations, providing both a high-level overview of model logic and granular insights into specific predictions.

Global Explanations

  • Feature Importance: This is measured by the increase in prediction error when a feature's values are permuted (shuffled), effectively breaking the relationship between the feature and the target.
  • Accumulated Local Effects (ALE) & Partial Dependence Plots (PDP): These methods visualize how a feature influences the prediction on average. ALE is particularly emphasized as a superior, unbiased alternative to PDP when features are highly correlated.
  • Feature Interactions: Using Friedman’s H-statistic, the package quantifies how much of the model's logic depends on the interaction between variables rather than their individual effects.
  • Global Surrogate Models: The package can fit a simple, interpretable decision tree to the complex model’s predictions, providing a high-level "map" of the overall logic.

Local Explanations

  • Shapley Values: Based on coalitional game theory, this method fairly distributes the "payout" (the difference between the prediction and the average prediction) among the features.
  • LocalModel (LIME variant): This fits a locally weighted sparse linear model around a specific observation to explain why the model made a particular prediction for that instance.

Key Technical Insights: ALE vs. PDP

One of the most important technical takeaways from the iml framework is the preference for ALE plots over traditional PDPs. Standard Partial Dependence Plots can produce misleading results if features are correlated, as they may average predictions over unlikely or impossible feature combinations. ALE plots solve this by calculating differences based on the conditional distribution of features, making them more robust for real-world datasets where correlations are common.

Practical Implementation and Results

The "results" of the iml package are functional: it successfully implements a suite of complex XAI (Explainable AI) algorithms into a consistent syntax. Explanations are generated as objects (e.g., FeatureImp$new()), which can then be easily plotted using ggplot2 or queried for raw data. For instance, the LocalModel class provides access to the underlying Lasso model's coefficients and indices, allowing for deep inspection of local feature contributions.

Internal data structure of a LocalModel explanation object, showing the coefficients (betas) and selected features.

To ensure practical utility, the package integrates with the future package for parallelization. This is critical for computationally expensive methods like Shapley values and permutation importance, which often rely on Monte Carlo sampling.

Limitations and Future Directions

Despite its robustness, iml faces certain challenges. Methods like Shapley values remain computationally intensive for datasets with hundreds of features. Additionally, global surrogate models are approximations; if the underlying model is extremely non-linear, a shallow decision tree may have low fidelity, potentially oversimplifying the model's true behavior. Finally, while the package attempts to order categorical features by similarity for ALE plots, the authors note that handling non-numerical data in a definitive way remains an ongoing area of research in the field of interpretability.

Summary updated

Abstract

Interpretability methods to analyze the behavior and predictions of any machine learning model. Implemented methods are: Feature importance described by Fisher et al. (2018) &lt;<a href="https://doi.org/10.48550%2Farxiv.1801.01489" target="_top">doi:10.48550/arxiv.1801.01489</a>&gt;, accumulated local effects plots described by Apley (2018) &lt;<a href="https://doi.org/10.48550%2Farxiv.1612.08468" target="_top">doi:10.48550/arxiv.1612.08468</a>&gt;, partial dependence plots described by Friedman (2001) &lt;www.jstor.org/stable/2699986&gt;, individual conditional expectation ('ice') plots described by Goldstein et al. (2013) &lt;<a href="https://doi.org/10.1080%2F10618600.2014.907095" target="_top">doi:10.1080/10618600.2014.907095</a>&gt;, local models (variant of 'lime') described by Ribeiro et. al (2016) &lt;<a href="https://doi.org/10.48550%2FarXiv.1602.04938" target="_top">doi:10.48550/arXiv.1602.04938</a>&gt;, the Shapley Value described by Strumbelj et. al (2014) &lt;<a href="https://doi.org/10.1007%2Fs10115-013-0679-x" target="_top">doi:10.1007/s10115-013-0679-x</a>&gt;, feature interactions described by Friedman et. al &lt;<a href="https://doi.org/10.1214%2F07-AOAS148" target="_top">doi:10.1214/07-AOAS148</a>&gt; and tree surrogate models.
BibTeX
@inproceedings{casalicchio2018iml,
  author = {Giuseppe Casalicchio and Christoph Molnar and Patrick Schratz},
  title = {{iml: Interpretable Machine Learning}},
  booktitle = {Openalex Unknown},
  year = {2018},
  doi = {10.32614/cran.package.iml},
}
Figure