Abstract
The ingredients package provides a collection of tools for the assessment of feature importance and feature effects. Key functions include feature_importance() for global level feature importance, ceteris_paribus() for calculating what-if plots, and various aggregation methods such as partial_dependence(), conditional_dependence(), and accumulated_dependence() (ALE) plots. Additionally, the package supports aggregate_profiles() and cluster_profiles() for summarizing individual behaviors, alongside generic print(), plot(), and plotD3() functions for enhanced usability and interactivity. Descriptions in natural language are provided via the describe() function. The package is a core component of the DrWhy.AI universe (Biecek 2018).
Introduction
As machine learning models grow in complexity—transitioning from simple linear regressions to deep learning and gradient boosting—they often become "black boxes." This creates a transparency gap where high predictive accuracy is achieved at the cost of understanding why a model behaves as it does. The ingredients package addresses this by providing a unified, model-agnostic framework to audit the core components of a model: its feature importance and feature effects.
By moving beyond simple global metrics, ingredients allows researchers and engineers to explore how individual observations are handled (local explanations) and how those local behaviors aggregate into broader model trends. It serves as a bridge between raw data and human-interpretable insights within the broader DrWhy.AI ecosystem.
Methods
The package implements several algorithmic approaches to model explanation, categorized by their scope and granularity:
- Global Importance: The
feature_importance()function utilizes a permutation-based approach (Variable Dropout). By shuffling a specific feature and measuring the resulting drop in model performance, it quantifies the model's reliance on that specific "ingredient." - Individual Profiles (Ceteris Paribus): The
ceteris_paribus()function generates "what-if" profiles for single observations. It visualizes how a model's prediction changes as one variable is modified while all others remain constant (ceteris paribus).
- Aggregated Profiles: To understand general trends, the package offers three primary methods to average individual profiles:
- Partial Dependence (PD): A global average of feature effects across the dataset.
- Conditional Dependence: A local weighted average that accounts for data distribution.
- Accumulated Local Effects (ALE): Implemented via
accumulated_dependence(), this method handles correlated features more reliably than PD plots by calculating changes in predictions within local windows.
- Clustering and Natural Language:
cluster_profiles()groups similar individual profiles to identify sub-populations with distinct model behaviors. For non-technical stakeholders, thedescribe()function translates these statistical plots into human-readable text.
Datasets
The package's functionality is typically demonstrated using two primary datasets:
- Titanic: Used to predict passenger survival, demonstrating feature importance for classification (e.g., gender, age, and fare).
- Apartments: Used for predicting house prices (
m2.price), showcasing how the package handles regression models and continuous variables like surface area or construction year.
Key Insights and Ideas
- Local vs. Global Nuance: A primary insight of the package is that global importance can mask local variations. By pairing
ceteris_paribus()withfeature_importance(), users can identify variables that are globally significant but irrelevant for specific edge cases. - The Correlation Challenge: The inclusion of ALE plots is a critical advancement for practitioners. Standard Partial Dependence plots can be misleading when features are highly correlated (e.g., engine size and fuel consumption); ALE plots mitigate this by focusing on local differences rather than global marginals.
- Interactivity and Human-Centric AI: Through
plotD3(), the package acknowledges that static charts are often insufficient for complex models. Furthermore, thedescribe()function highlights that the ultimate goal of eXplainable AI (XAI) is human understanding, not just the generation of more charts.
Key Results
The ingredients package provides a flexible API that integrates seamlessly with any model via the DALEX explainer object. Key functional results include:
- Unified Visualization: A single
plot()call can combine individual profiles, aggregated trends, and "rug" plots of data distribution. - Statistical Rigor: Permutation importance supports multiple repetitions (the
Bparameter) to provide a measure of stability and uncertainty in importance rankings. - Scalability: Functions like
select_neighbours()andselect_sample()allow the package to handle large datasets by intelligently downsampling before performing computationally intensive profile calculations.
Limitations and Future Work
While robust, the package has areas for growth. The describe() function currently focuses primarily on categorical values; expanding this to complex continuous interactions is a natural next step. Additionally, while sampling tools exist, the computational cost of calculating profiles for massive datasets remains a challenge. Finally, as a model-agnostic tool, it cannot currently leverage internal model structures (like tree paths in Random Forests) for faster local explanations, representing a trade-off between flexibility and performance.
Summary updated