Skip to content

Commit 416723e

Browse files
jeongyoonleeclaude
andcommitted
Make sparse-group test deterministic with 1-sample minority groups
With only 1 sample per minority treatment group out of 102 total, bootstrap sampling will miss them in most trees, making the test deterministic regardless of seed or CI environment. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d169b1e commit 416723e

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

tests/test_uplift_trees.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,14 @@ def test_UpliftRandomForestClassifier_predict_shape_with_sparse_groups():
299299
"""Test that UpliftRandomForestClassifier.predict() returns correct shape
300300
when bootstrap sampling causes some trees to miss treatment groups (#569)."""
301301
np.random.seed(RANDOM_SEED)
302-
n = 60
302+
n = 102
303303
X = np.random.randn(n, 3)
304-
# Very few samples in treatment groups so bootstraps are likely to miss some
304+
# Only 1 sample per minority treatment group guarantees that bootstrap
305+
# sampling (with replacement, n draws from n) will miss them in some trees.
306+
# P(group included) = 1 - (1 - 1/n)^n ≈ 1 - 1/e ≈ 0.63 per tree,
307+
# so with 10 trees the chance ALL include both groups is ~0.63^20 ≈ 0.01%.
305308
treatment = np.array(
306-
[CONTROL_NAME] * 50 + [TREATMENT_NAMES[1]] * 5 + [TREATMENT_NAMES[2]] * 5
309+
[CONTROL_NAME] * 100 + [TREATMENT_NAMES[1]] * 1 + [TREATMENT_NAMES[2]] * 1
307310
)
308311
y = np.random.randint(0, 2, n)
309312

0 commit comments

Comments
 (0)