Skip to content

Seed the uplift feature associations in make_uplift_classification_logistic - #1090

Open
aad1tyaaaaa wants to merge 1 commit into
uber:masterfrom
aad1tyaaaaa:fix-uplift-logistic-seed
Open

aad1tyaaaaa wants to merge 1 commit into
uber:masterfrom
aad1tyaaaaa:fix-uplift-logistic-seed

Conversation

@aad1tyaaaaa

Copy link
Copy Markdown
Contributor

Proposed changes

make_uplift_classification_logistic chooses the association pattern for each uplift feature (with the default random_select_association=True) using Python's random.randint. random_seed only seeds np.random, so two calls with the same random_seed return different datasets: the *_uplift_transformed columns, the conversion probabilities and the outcome all change.

import random
from causalml.dataset import make_uplift_classification_logistic as f
random.seed(1); a, _ = f(n_samples=200)
random.seed(2); b, _ = f(n_samples=200)
a.equals(b)  # False

This PR draws the index from np.random instead, so random_seed controls the whole dataset, and removes the random import, which is no longer used. Because the numpy random stream now covers this draw, a given seed produces different numbers than before; before this change those numbers were not reproducible anyway.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Further comments

The new test test_make_uplift_classification_logistic_is_reproducible in tests/test_datasets.py fails on master and passes with this change; tests/test_datasets.py passes and black is clean. This and the np.asscalar fix both add a test to tests/test_datasets.py, so whichever is merged second may need a small rebase.

I used an AI assistant (Claude Code) to help find this bug and write the fix and test. I reviewed and ran everything myself.

…gistic

The association pattern for each uplift feature was drawn with Python's
random module, which random_seed does not seed, so two calls with the same
random_seed returned different datasets. Draw it from np.random instead.

This branch has not been deployed

No deployments
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.

1 participant