Enhance counterfactual with fixed_features and custom methods #1029 #1148
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi @rabst,
Description: This PR introduces enhancements to the create_counterfactual function to address performance bottlenecks and improve flexibility, as discussed in issue #1029.
Key Changes:
Feature Masking (fixed_features): Added a new parameter fixed_features (list of indices) that allows users to specify which features should remain constant during the optimization process. This reduces the search space dimensionality, leading to significantly faster convergence in high-dimensional datasets.
Optimization Methods: Exposed the method parameter for scipy.optimize.minimize, allowing users to choose solvers other than the default 'Nelder-Mead' (e.g., 'BFGS' or 'L-BFGS-B').
Improved Convergence: The internal objective function now dynamically handles the feature mask, ensuring that only the relevant features are updated.
API Consistency: Updated init.py and docstrings to ensure the new parameters are properly exposed and documented.
Note on CI Failures: I noticed that the build-linux and conda unit tests are currently failing. After investigating the logs, the failures are located in mlxtend/classifier/tests/test_perceptron.py with the error: TypeError: only 0-dimensional arrays can be converted to Python scalars.
This seems to be an upstream issue related to recent NumPy updates affecting the Perceptron implementation and is unrelated to the changes in this PR. I have verified that all new and existing tests in mlxtend/evaluate/tests/test_counterfactual.py are passing locally and on the CI.
Fixes: #1029