Skip to content

Conversation

@mariam851
Copy link
Contributor

@mariam851 mariam851 commented Dec 29, 2025

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.

Screenshot (31) Screenshot (32)

Fixes: #1029

@mariam851 mariam851 force-pushed the feature-counterfactual-enhancements-1029 branch 2 times, most recently from 2d6a7ce to caade90 Compare December 29, 2025 14:10
@mariam851 mariam851 force-pushed the feature-counterfactual-enhancements-1029 branch from caade90 to 71a612b Compare December 29, 2025 14:14
@rasbt
Copy link
Owner

rasbt commented Jan 5, 2026

Thanks for the PR(s). I have been busy with other projects lately and didn't quite get the chance to check them. I hope to be able to take a look next in the next 1-2 weeks though. I just fixed the perceptron issue, and the CI should work now.

@mariam851
Copy link
Contributor Author

mariam851 commented Jan 5, 2026 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create_counterfactual enhancements (minimization method and fixed features)

2 participants