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 the test_accuracy function by modifying the assertion logic #867

Merged
merged 3 commits into from
Apr 10, 2024
Merged
Changes from 1 commit
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
46 changes: 23 additions & 23 deletions econml/tests/test_discrete_outcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,35 @@ def test_accuracy(self):
discrete_outcome = True
discrete_treatment = True
true_ate = 0.3
W = np.random.uniform(-1, 1, size=(n, 1))
D = np.random.binomial(1, .5 + .1 * W[:, 0], size=(n,))
Y = np.random.binomial(1, .5 + true_ate * D + .1 * W[:, 0], size=(n,))
num_iterations = 10
count_within_interval = 0

ests = [
LinearDML(discrete_outcome=discrete_outcome, discrete_treatment=discrete_treatment),
CausalForestDML(discrete_outcome=discrete_outcome, discrete_treatment=discrete_treatment),
LinearDRLearner(discrete_outcome=discrete_outcome)
]
for _ in range(num_iterations):

for est in ests:
W = np.random.uniform(-1, 1, size=(n, 1))
D = np.random.binomial(1, .5 + .1 * W[:, 0], size=(n,))
Y = np.random.binomial(1, .5 + true_ate * D + .1 * W[:, 0], size=(n,))

if isinstance(est, CausalForestDML):
est.fit(Y, D, X=W)
ate = est.ate(X=W)
ate_lb, ate_ub = est.ate_interval(X=W)
ests = [
LinearDML(discrete_outcome=discrete_outcome, discrete_treatment=discrete_treatment),
CausalForestDML(discrete_outcome=discrete_outcome, discrete_treatment=discrete_treatment),
LinearDRLearner(discrete_outcome=discrete_outcome)
]

else:
est.fit(Y, D, W=W)
ate = est.ate()
ate_lb, ate_ub = est.ate_interval()
for est in ests:

if isinstance(est, LinearDRLearner):
est.summary(T=1)
else:
est.summary()
if isinstance(est, CausalForestDML):
est.fit(Y, D, X=W)
ate_lb, ate_ub = est.ate_interval(X=W)

proportion_in_interval = ((ate_lb < true_ate) & (true_ate < ate_ub)).mean()
np.testing.assert_array_less(0.50, proportion_in_interval)
else:
est.fit(Y, D, W=W)
ate_lb, ate_ub = est.ate_interval()

if ate_lb <= true_ate <= ate_ub:
count_within_interval += 1

assert count_within_interval >= 8, f"True ATE falls within the interval bounds only {count_within_interval} times out of {num_iterations}"

# accuracy test, DML
def test_accuracy_iv(self):
Expand Down
Loading