pymc-labs / pymc-marketing

Bayesian marketing toolbox in PyMC. Media Mix (MMM), customer lifetime value (CLV), buy-till-you-die (BTYD) models and more.
https://www.pymc-marketing.io/
Apache License 2.0
648 stars 175 forks source link

Can't import clv from pymc-marketing #695

Closed mengying-notion closed 2 months ago

mengying-notion commented 3 months ago

Hi I have a problem using the library as it keeps throwing the error of cannot import name 'logsumexp' from 'xarray_einstats.stats' The xarray version I used is 2023.12.0.

wd60622 commented 3 months ago

Hi @mengying-notion Can you provide the the full traceback and the versions of the packages? pymc, pymc-marketing, etc

mengying-notion commented 3 months ago

Yes this is the full info Successfully installed pymc-5.12.0 pymc-marketing-0.4.2 pytensor-2.19.0 xarray-einstats-0.7.0

wd60622 commented 3 months ago

Hi @mengying-notion, thanks How about the traceback of the error

mengying-notion commented 3 months ago

This is the full error. Thank you so much @wd60622

 ImportError     
Traceback (most recent call last)
/tmp/ipykernel_12/118690087.py in <cell line: 12>()
     10 _hex_pks.kernel_execution.scope_watcher.mark_dirty_scope_items(args=_hex_types.MarkDirtyScopeItemsArgs.from_dict({**_hex_json.loads("{\"dirty_scope_items\":[\"clv\"]}")}), app_session_token=_hex_APP_SESSION_TOKEN, python_kernel_init_status=_hex_python_kernel_init_status, hex_timezone=_hex_kernel.variable_or_none("hex_timezone", scope_getter=lambda: globals()), interrupt_event=locals().get("_hex_interrupt_event"))
     11 
---> 12 from pymc_marketing import clv

~/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.9/lib/python3.9/site-packages/pymc_marketing/__init__.py in <module>
----> 1 from pymc_marketing import clv, mmm
      2 from pymc_marketing.version import __version__
      3 
      4 __all__ = ["clv", "mmm", "__version__"]

~/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.9/lib/python3.9/site-packages/pymc_marketing/clv/__init__.py in <module>
----> 1 from pymc_marketing.clv.models import (
      2     BetaGeoModel,
      3     GammaGammaModel,
      4     GammaGammaModelIndividual,
      5     ParetoNBDModel,

~/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.9/lib/python3.9/site-packages/pymc_marketing/clv/models/__init__.py in <module>
      5     GammaGammaModelIndividual,
      6 )
----> 7 from pymc_marketing.clv.models.pareto_nbd import ParetoNBDModel
      8 from pymc_marketing.clv.models.shifted_beta_geo import ShiftedBetaGeoModelIndividual
      9 

~/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.9/lib/python3.9/site-packages/pymc_marketing/clv/models/pareto_nbd.py in <module>
     15 from pytensor.tensor.elemwise import Elemwise
     16 from scipy.special import betaln, gammaln, hyp2f1
---> 17 from xarray_einstats.stats import logsumexp as xr_logsumexp
     18 
     19 from pymc_marketing.clv.distributions import ParetoNBD

ImportError: cannot import name 'logsumexp' from 'xarray_einstats.stats' (/home/hexuser/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.9/lib/python3.9/site-packages/xarray_einstats/stats.py)`
wd60622 commented 3 months ago

Might be good to upgrade the xarray version. Xarray-einstats seems to be the latest. Or try einstats below that 0.7.0 version

ColtAllen commented 3 months ago

Hey @mengying-notion,

I noticed in your error trace you're using Python 3.9, which is no longer supported. Try creating a new virtual environment with >=3.10 and let us know what happens.

wd60622 commented 3 months ago

Hi @mengying-notion Did this get resolved?