Abstract: A general test for conditional independence in supervised learning algorithms as proposed by Watson & Wright (2021). Implements a conditional variable importance measure which can be applied to any supervised learning algorithm and loss function. Provides statistical inference procedures without parametric assumptions and applies equally well to continuous and categorical predictors and outcomes.
Introduction
In the field of machine learning, identifying which features are truly "important" is a critical task for both model interpretability and feature selection. However, traditional variable importance measures, such as those used in Random Forests, often struggle with highly correlated features. A variable might appear significant simply because it acts as a proxy for another, or its importance might be masked when redundant predictors are present. This phenomenon can lead to misleading conclusions about the underlying data generation process.
The cpi R package addresses this by implementing a model-agnostic framework for testing Conditional Predictive Impact (CPI). Based on the work of Watson & Wright (2021), it moves beyond heuristic scores to provide a formal test for conditional independence: does a feature $X$ provide unique information about the outcome $Y$ that is not already captured by the remaining features $Z$? By leveraging rigorous statistical inference, cpi allows researchers to determine if a specific feature truly adds predictive value to a model.
Methodology: The Role of Knockoffs
The core of the CPI framework is the use of "knockoff" variables. To test the impact of a specific feature, the algorithm generates a synthetic version—a knockoff—that preserves the correlation structure with other covariates but is independent of the outcome. This approach ensures that any difference in model performance can be attributed solely to the unique information contained in the original feature.
The process involves three main steps:
- Knockoff Generation: Creating a synthetic feature that mimics the original's relationship with other variables. The package defaults to second-order knockoffs, though users can provide custom generation functions for complex data types.
- Error Inflation Measurement: Comparing the model's performance when using the original feature versus the knockoff. A significant increase in error when the original is replaced indicates high conditional predictive impact.
- Statistical Inference: Unlike standard importance scores,
cpiprovides p-values and confidence intervals. It supports various tests, including t-tests (default), Wilcoxon signed-rank tests for skewed data, and Fisher permutation or Bayesian tests for smaller samples.
Implementation and Usage
The package is integrated with the mlr3 ecosystem, allowing it to be used with any supported supervised learning algorithm, from linear models to complex neural networks. The primary cpi function accepts several key arguments to define the task, the learner, and the evaluation strategy.
Users can specify resampling strategies (e.g., holdout, out-of-bag) or provide external validation data. The choice of performance measure (e.g., MSE for regression, log-loss for classification) is also configurable, making the tool highly adaptable to different research questions.
Interpreting Results
The cpi function returns a structured output that quantifies the impact of each feature or group of features. This allows researchers to apply the same level of statistical rigor to machine learning models as they would to classical linear models.
Key metrics in the output include the CPI value (the measure of error inflation), standard error (SE), and test statistics. The package also supports "Group CPI," where multiple features (e.g., all measurements related to a single physical property) are tested collectively for their impact.
Conclusion
The cpi package provides a robust, statistically grounded approach to feature importance. By focusing on conditional impact and providing formal inference, it helps researchers identify truly non-redundant predictors. While computationally more intensive than simple heuristics—particularly when using Bayesian tests—its model-agnostic nature and integration with mlr3 make it a versatile tool for modern data science.
Summary updated