BiomedSciAI / causallib

A Python package for modular causal inference analysis and model evaluations
Apache License 2.0
728 stars 97 forks source link

`PropensityFeatureStandardization` deepcopy fix #35

Closed ehudkr closed 2 years ago

ehudkr commented 2 years ago

@mmdanziger: Seems like because the _feature_functions were calculated based on self in __init__ and then stored in an attribute they became effectively un-deepcopy-able. What was happening was that the deepcopied version would run fit on the fresh learner but then when it came to calculated the feature_functions it would use the old learner which had not been fit and was stored in the _feature_functions attribute.

The root of the problem is having _feature_functions as an attribute at all. It's a light function and only calculated once per predict so the added value of caching is dubious and creates cache invalidation problems. This required removing the attribute and replacing it with a lookup function.