Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect effect_learner_objective in XGBRRegressor #504

Merged
merged 1 commit into from
Apr 30, 2022
Merged
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
4 changes: 2 additions & 2 deletions causalml/inference/meta/rlearner.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def __init__(
early_stopping=True,
test_size=0.3,
early_stopping_rounds=30,
effect_learner_objective="rank:pairwise",
effect_learner_objective="reg:squarederror",
effect_learner_n_estimators=500,
random_state=42,
*args,
Expand All @@ -531,7 +531,7 @@ def __init__(
early_stopping_rounds (int, optional): validation metric needs to improve at least once in every
early_stopping_rounds round(s) to continue training
effect_learner_objective (str, optional): the learning objective for the effect learner
(default = 'rank:pairwise')
(default = 'reg:squarederror')
effect_learner_n_estimators (int, optional): number of trees to fit for the effect learner (default = 500)
"""

Expand Down
22 changes: 14 additions & 8 deletions tests/test_meta_learners.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,18 +840,24 @@ def test_BaseRClassifier_with_sample_weights(generate_classification_data):
# higher than it would be under random targeting
assert cumgain["tau_pred"].sum() > cumgain["Random"].sum()


def test_XGBRegressor_with_sample_weights(generate_regression_data):
y, X, treatment, tau, b, e = generate_regression_data()

weights = np.random.rand(y.shape[0])

# Check if XGBRRegressor successfully produces treatment effect estimation
# when sample_weight is passed
uplift_model = XGBRRegressor()
uplift_model.fit(
X=df_train[x_names].values,
p=df_train["propensity_score"].values,
treatment=df_train["treatment_group_key"].values,
y=df_train[CONVERSION].values,
sample_weight=df_train["sample_weights"],
)
tau_pred = uplift_model.predict(X=df_test[x_names].values)
assert len(tau_pred) == len(df_test["sample_weights"].values)
X=X,
p=e,
treatment=treatment,
y=y,
sample_weight=weights,
)
tau_pred = uplift_model.predict(X=X)
assert len(tau_pred) == len(weights)


def test_pandas_input(generate_regression_data):
Expand Down