jamalsenouci / causalimpact

Python port of CausalImpact R library
Apache License 2.0
265 stars 63 forks source link

Cannot import CausalImpact because of NameError: #1

Closed BernFox closed 6 years ago

BernFox commented 7 years ago

When I import causalimpact, as such

import causalimpact

I get this error

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-707f1b214cc6> in <module>()
----> 1 import causalimpact

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/causalimpact-0.1-py2.7.egg/causalimpact/__init__.py in <module>()
      7 """
      8 
----> 9 from causalimpact.analysis import CausalImpact  # noqa
     10 from causalimpact.tests.test import run as test  # noqa

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/causalimpact-0.1-py2.7.egg/causalimpact/analysis.py in <module>()
      6 from causalimpact.misc import standardize_all_variables
      7 from causalimpact.model import construct_model
----> 8 from causalimpact.inferences import compile_posterior_inferences
      9 
     10 class CausalImpact(object):

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/causalimpact-0.1-py2.7.egg/causalimpact/inferences.py in <module>()
      1 from causalimpact.misc import unstandardize
      2 def compile_posterior_inferences(model, data_post, alpha=0.05,
----> 3                                  orig_std_params=identity):
      4 
      5     # Compute point predictions of counterfactual (in standardized space)

NameError: name 'identity' is not defined

I looked at the source code and found that identity is a default arg for compile_posterior_inferences, but identity doesn't exist. I looked elsewhere in the code to see if identity is referenced elsewhere to see if I could fix it myself, and found that theres this: orig_std_params = np.identity on line 243 of analysis.py, but np.identity is a function that returns the identity matrix. It it assigned to the variable orig_std_params without actually giving np.identity an argument. The orig_std_params variable is then reassigned to some other value. So I couldn't make sense of how to fix the code. Also, compile_na_inferences in inferences.py doesn't do anything, seems wrong because the function is used elsewhere in the package.

So I don't know how to use the package as such....

jamalsenouci commented 7 years ago

yeah, i only got halfway through this. There's still a lot of work to make it useable but I haven't had time to work on it for a while.

oostopitre commented 7 years ago

Is there a known workaround to getting this to work so that we can play with the existing functionality of the library?

jamalsenouci commented 7 years ago

Not really, the last I left it I was starting to use the new functionality for state space models in statsmodels, but that hasn't made its way into the stable release yet I don't think. Without the modelling part there's not much we can do with it. I might try and take a look to see how much work is needed to get something useable.

On 15 December 2016 at 23:35, Abi Komma notifications@github.com wrote:

Is there a known workaround to getting this to work so that we can play with the existing functionality of the library?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jamalsenouci/causalimpact/issues/1#issuecomment-267476329, or mute the thread https://github.com/notifications/unsubscribe-auth/AFLqDEbxdbu_4nwgYr7G-IHeKG19grPiks5rIc62gaJpZM4LG0Yr .

haydenliu commented 7 years ago

I got the same error, and tried to fix it, but gave up :)

pabloazurduy commented 7 years ago

Hi @jamalsenouci ¿Is this library still under development ? or it's an abandoned project? thanks! :)

kristomi commented 7 years ago

@haydenliu and @jamalsenouci: See this library https://github.com/tcassou/causal_impact. Maybe it has come further.

jamalsenouci commented 7 years ago

I picked up development on this, there is something that works at the moment but only works with maximum likelihood estimation and still needs a lot of testing

BernFox commented 7 years ago

Oh cool! Thanks for following up. I did however build my own solution to this kind of problem. Check it out: https://medium.com/refinery29-pe/seo-a-b-testing-with-predictive-analysis-68c399d231b5