Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions causalml/dataset/classification.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import random
import numpy as np
import pandas as pd
from sklearn.datasets import make_classification
Expand Down Expand Up @@ -358,7 +357,7 @@ def make_uplift_classification_logistic(
x_name_i = x_name_i + "_transformed"
if random_select_association:
df1[x_name_i] = _fixed_transformation(
f_list, x, random.randint(0, len(f_list) - 1)
f_list, x, np.random.randint(len(f_list))
)
else:
df1[x_name_i] = _fixed_transformation(f_list, x, xi % len(f_list))
Expand Down
16 changes: 16 additions & 0 deletions tests/test_datasets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import random

import pandas as pd
import pytest

from causalml.dataset import (
Expand All @@ -9,6 +12,7 @@
get_synthetic_preds,
get_synthetic_summary,
get_synthetic_auuc,
make_uplift_classification_logistic,
)
from causalml.dataset import get_synthetic_preds_holdout, get_synthetic_summary_holdout
from causalml.inference.meta import LRSRegressor, XGBTRegressor
Expand Down Expand Up @@ -104,3 +108,15 @@ def test_get_synthetic_preds_holdout_uses_given_estimators():
assert "My S Learner" in preds_valid
assert not [k for k in preds_train if "Learner (" in k]
assert not [k for k in preds_valid if "Learner (" in k]


def test_make_uplift_classification_logistic_is_reproducible():
# The uplift feature associations used to be drawn from Python's random module,
# which random_seed does not seed, so the same seed gave different datasets.
random.seed(1)
df1, x_names1 = make_uplift_classification_logistic(n_samples=200, random_seed=42)
random.seed(2)
df2, x_names2 = make_uplift_classification_logistic(n_samples=200, random_seed=42)

assert x_names1 == x_names2
pd.testing.assert_frame_equal(df1, df2)