Skip to content

Conversation

@mariam851
Copy link

This pull request adds an optional parameter feature_names_to_vary to the
create_counterfactual function in mlxtend.

With this feature, users can freeze certain features while generating
counterfactual explanations, allowing only selected features to vary during
optimization. This is useful for cases where some features are immutable
or should remain constant for practical or ethical reasons.

Changes include:

  • Added feature_names_to_vary parameter (list of indices or boolean mask)
  • Updated distance calculation and loss function to respect frozen features
  • Added warnings for unsupported inputs (e.g., string feature names)
  • Maintained backward compatibility for existing code

Tested locally with a small example to ensure the function respects frozen
features and outputs valid counterfactuals.

This is an experimental feature and feedback is welcome.

@rasbt
Copy link
Owner

rasbt commented Dec 14, 2025

Thanks for the PR. The feature looks good overall, but similar to the other PR, I suggest removing the LLM-generated comments that explain what's being added as new, because outside this PR, it would clutter the code and be redundant.

@rasbt rasbt mentioned this pull request Dec 14, 2025
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.

2 participants