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

"Fixes linear DRIV shape inconsistency" #920

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

ssemov
Copy link
Contributor

@ssemov ssemov commented Sep 10, 2024

Addresses the shape inconsistency in the linear DRIV implementation.

Changes:

  • I modified the effect_interval computation in LinearModelFinalInference class. This is where the inference method for LinearDRIV comes from.
  • I added the modification function - reshape_outcomewise_effects - to utilities. Given an effects matrix, it reshapes the second dimension to be consistent with d_y[0].

Related [issue](#687).

Testing:

  • TestDRIV --> OK
  • test_inference --> OK
  • test_statsmodels --> OK

@ssemov ssemov force-pushed the clean-fix-linear-driv branch from 13924b9 to c92104a Compare September 10, 2024 19:03
@kbattocchi
Copy link
Collaborator

Thanks for the contribution. Unfortunately, these changes are causing test failures in econml.tests.test_dml.TestDML.test_ignores_final_intercept, econml.tests.test_discrete_outcome.TestDiscreteOutcome.test_accuracy, and econml.tests.test_discrete_outcome.TestDiscreteOutcome.test_accuracy_iv.

Given that the shapes are as expected for other estimators (like LinearDML) using the same inference class, I think the best place to address the problem is probably somewhere in _dr.py, although maybe there is a way to address it in the inference class that doesn't break other classes that use it.

@ssemov
Copy link
Contributor Author

ssemov commented Sep 13, 2024

Thanks, @kbattocchi! yes, I think the fix I have touches too many things. I'll look into something more local in _dr.py.

@ssemov ssemov force-pushed the clean-fix-linear-driv branch from c92104a to b7b78b4 Compare September 25, 2024 16:12
@ssemov
Copy link
Contributor Author

ssemov commented Sep 25, 2024

@kbattocchi I made the change more local and fixed an edge case with the discrete outcome. The new version passes the tests I was failing before.

@ssemov
Copy link
Contributor Author

ssemov commented Oct 2, 2024 via email

@ssemov ssemov force-pushed the clean-fix-linear-driv branch from b7b78b4 to 5c5d476 Compare October 2, 2024 23:04
@ssemov
Copy link
Contributor Author

ssemov commented Oct 2, 2024

@kbattocchi Removed the redundant effect_interval method.

Copy link
Collaborator

@kbattocchi kbattocchi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for trying again, but I don't think StatsModelsInference is the right place for the change - see my comment.

Comment on lines 497 to 495
e_pred = reshape_outcomewise_effects(self._predict(XT), self._d_y)
e_stderr = reshape_outcomewise_effects(self._prediction_stderr(XT), self._d_y)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, the idea of StatsModelsInference compared to LinearModelFinalInference is just to allow setting the covariance estimation method for inference, not to affect any other aspect of the computation, so I think your previous change to that class would make more sense - perhaps with the additional check for () in your reshape_outcomewise_effects implementation changing the LinearModelFinalInference will no longer break other subclasses?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(And I think you'll find that without fixing the change in LinearModelFinalInference, other DRIV subclasses like SparseLinearDRIV still suffer from the same issue - please consider modifying line 457 of test_treatment_featurization to enable further tests on DRIV subclasses)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kbattocchi Thanks, Keith, for the help. It makes sense what you are saying, I will work on a fix.

econml/inference/_inference.py Outdated Show resolved Hide resolved
Signed-off-by: ssemov <ssemov@gmail.com>
@ssemov ssemov force-pushed the clean-fix-linear-driv branch from 5c5d476 to 7cc5ebc Compare October 13, 2024 22:13
@ssemov
Copy link
Contributor Author

ssemov commented Oct 13, 2024

Changes:

  • Moves the fix to LinearModelFinalInference
  • updates TestTreatmentFeaturization not to skip LinearDRIV and SparseLinearDRIV

Tests:

  • TestDML.test_ignores_final_intercept
  • TestDiscreteOutcome.test_accuracy
  • TestDiscreteOutcome.test_accuracy_iv
  • TestTreatmentFeaturization

Copy link
Collaborator

@kbattocchi kbattocchi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@kbattocchi kbattocchi merged commit e0271fd into py-why:main Oct 16, 2024
98 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants