Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Rahul Shrestha <rahulshrestha0101@gmail.com>
  • Loading branch information
rahulbshrestha committed Apr 21, 2024
1 parent 64585ea commit 47eee77
Showing 1 changed file with 0 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,54 +44,6 @@ def intervene(self, treatment_value, sample_size=100):

@mark.usefixtures("fixed_seed")
class TestCausalInferenceDiscoveryBook(object):
def test_dowhy_chapter_6(self):
# Instantiate the SCM
scm = GPSMemorySCM()

# Generate observational data
gps_obs, hippocampus_obs, memory_obs = scm.sample(600)

# Run an experiment
treatments = []
experiment_results = []

# Sample over various treatments
for treatment in np.arange(1, 21):
gps_hours, hippocampus, memory = scm.intervene(treatment_value=treatment, sample_size=30)
experiment_results.append(memory)
treatments.append(gps_hours)

# Naive model 1

lr_naive = LinearRegression()
lr_naive.fit(X=gps_obs.reshape(-1, 1), y=memory_obs)

# Experimental model

treatments_unpack = np.array(treatments).flatten()
results_unpack = np.array(experiment_results).flatten()

lr_experiment = LinearRegression()
lr_experiment.fit(X=treatments_unpack.reshape(-1, 1), y=results_unpack)

X_test = np.arange(1, 21).reshape(-1, 1)
preds_naive = lr_naive.predict(X_test)
preds_experiment = lr_experiment.predict(X_test)

# Get coefficients
print(f"Naive model:\n{lr_naive.coef_[0]}\n")
print(f"Experiemntal model:\n{lr_experiment.coef_[0]}")

# Model E(Z|X)
lr_zx = LinearRegression()
lr_zx.fit(X=gps_obs.reshape(-1, 1), y=hippocampus_obs)

# Model E(Y|X, Z)E(X)
lr_yxz = LinearRegression()
lr_yxz.fit(X=np.array([gps_obs, hippocampus_obs]).T, y=memory_obs)

# Compute the expected causal effect
lr_zx.coef_[0] * lr_yxz.coef_[1]

def test_dowhy_chapter_7(self):
# Instantiate the SCM
Expand Down

0 comments on commit 47eee77

Please sign in to comment.