lightweight_mmm
lightweight_mmm copied to clipboard
Error while running plot_media_channel.... function
Hi, I am running "simple_end_to_end_demo" notebook on a GCP instance. All of the code runs fine except that I get the following error when running the code. Quick google search says numba needs to be turned off - I am not sure because all other plot functions are working fine. Any advice? Thanks.
plot.plot_media_channel_posteriors(media_mix_model=mmm)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
TypeError: expected dtype object, got 'numpy.dtype[float64]'
The above exception was the direct cause of the following exception:
SystemError Traceback (most recent call last)
<ipython-input-55-4b8328576e48> in <module>
----> 1 plot.plot_media_channel_posteriors(media_mix_model=mmm)
/opt/conda/lib/python3.7/site-packages/lightweight_mmm/plot.py in plot_media_channel_posteriors(media_mix_model, channel_names, quantiles, fig_size)
708 media_channel_posteriors[:, channel_i],
709 quantiles=quantiles,
--> 710 ax=channel_axis)
711 axis_label = f"media channel {channel_names[channel_i]}"
712 channel_axis.set_xlabel(axis_label)
/opt/conda/lib/python3.7/site-packages/arviz/plots/kdeplot.py in plot_kde(values, values2, cumulative, rug, label, bw, adaptive, circular, quantiles, rotated, contour, fill_last, figsize, textsize, plot_kwargs, fill_kwargs, rug_kwargs, contour_kwargs, contourf_kwargs, pcolormesh_kwargs, is_circular, ax, legend, backend, backend_kwargs, show, return_glyph, **kwargs)
248 bw = "experimental"
249
--> 250 grid, density = kde(values, circular, bw=bw, adaptive=adaptive, cumulative=cumulative)
251 lower, upper = grid[0], grid[-1]
252
/opt/conda/lib/python3.7/site-packages/arviz/stats/density_utils.py in kde(x, circular, **kwargs)
529 kde_fun = _kde_linear
530
--> 531 return kde_fun(x, **kwargs)
532
533
/opt/conda/lib/python3.7/site-packages/arviz/stats/density_utils.py in _kde_linear(x, bw, adaptive, extend, bound_correction, extend_fct, bw_fct, bw_return, custom_lims, cumulative, grid_len, **kwargs)
625 x_min, x_max, x_std, extend_fct, grid_len, custom_lims, extend, bound_correction
626 )
--> 627 grid_counts, _, grid_edges = histogram(x, grid_len, (grid_min, grid_max))
628
629 # Bandwidth estimation
/opt/conda/lib/python3.7/site-packages/arviz/utils.py in __call__(self, *args, **kwargs)
181 """Call the jitted function or normal, depending on flag."""
182 if Numba.numba_flag:
--> 183 return self.numba_fn(*args, **kwargs)
184 else:
185 return self.function(*args, **kwargs)
SystemError: CPUDispatcher(<function histogram at 0x7f66dc4f9a70>) returned a result with an error set
Hello @chsheth ! Looks like a problem with the arviz library. What version of arviz are you currently using and what python version?
On the GCP instance, Python is 3.7.8 and arviz is 0.11.2.
Hi @pabloduque0 -- not sure if you had any other suggestions but I was getting this error today on colab while running the end_to_end_demo_with_multiple notebook --
ImportError: cannot import name '_png' from 'matplotlib' (/usr/local/lib/python3.7/dist-packages/matplotlib/__init__.py)
Any suggestions? Thanks.
Hello @chsheth !
I am unable to reproduce your error on a GCP instance with python 3.7 and the same arviz version.
Could you try pip install --upgrade git+https://github.com/google/lightweight_mmm.git
? Just in case some version got hanged or similar.
As per your other error, if its in colab could you please provide a reproducible colab for me to take a look?
Thanks!
Thank you @pabloduque0.
For GCP/arviz, I can email you the notebook, cannot add it here -- I do think it has to do with some versioning.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-9a43dbab01ab> in <module>
1 # Import the relevant modules of the library
----> 2 from lightweight_mmm import lightweight_mmm
3 from lightweight_mmm import optimize_media
4 from lightweight_mmm import plot
5 from lightweight_mmm import preprocessing
/opt/conda/lib/python3.7/site-packages/lightweight_mmm/lightweight_mmm.py in <module>
51 from lightweight_mmm import models
52 from lightweight_mmm import preprocessing
---> 53 from lightweight_mmm import utils
54
55 Prior = Union[
/opt/conda/lib/python3.7/site-packages/lightweight_mmm/utils.py in <module>
22 import jax.numpy as jnp
23 import numpy as np
---> 24 import pandas as pd
25 from scipy import interpolate
26 from scipy import optimize
/opt/conda/lib/python3.7/site-packages/pandas/__init__.py in <module>
140 from pandas.util._print_versions import show_versions
141
--> 142 from pandas.io.api import (
143 # excel
144 ExcelFile,
/opt/conda/lib/python3.7/site-packages/pandas/io/api.py in <module>
6
7 from pandas.io.clipboards import read_clipboard
----> 8 from pandas.io.excel import ExcelFile, ExcelWriter, read_excel
9 from pandas.io.feather_format import read_feather
10 from pandas.io.gbq import read_gbq
/opt/conda/lib/python3.7/site-packages/pandas/io/excel/__init__.py in <module>
----> 1 from pandas.io.excel._base import ExcelFile, ExcelWriter, read_excel
2 from pandas.io.excel._odswriter import _ODSWriter
3 from pandas.io.excel._openpyxl import _OpenpyxlWriter
4 from pandas.io.excel._util import register_writer
5 from pandas.io.excel._xlsxwriter import _XlsxWriter
/opt/conda/lib/python3.7/site-packages/pandas/io/excel/_base.py in <module>
30 get_writer,
31 )
---> 32 from pandas.io.parsers import TextParser
33
34 _read_excel_doc = (
/opt/conda/lib/python3.7/site-packages/pandas/io/parsers/__init__.py in <module>
----> 1 from pandas.io.parsers.readers import (
2 TextFileReader,
3 TextParser,
4 read_csv,
5 read_fwf,
/opt/conda/lib/python3.7/site-packages/pandas/io/parsers/readers.py in <module>
15 import pandas._libs.lib as lib
16 from pandas._libs.parsers import STR_NA_VALUES
---> 17 from pandas._typing import (
18 ArrayLike,
19 DtypeArg,
ImportError: cannot import name 'DtypeArg' from 'pandas._typing' (/opt/conda/lib/python3.7/site-packages/pandas/_typing.py)
For '_png' from 'matplotlib' error, I found on stackoverflow that I would need to downgrade matplotlib version
!python -m pip uninstall matplotlib
!pip install matplotlib==3.1.3
I ran the above before any plot functions and there were no errors.
Glad to hear the other error was solved.
Is the arviz error persisting or has that one been solved as well?
In the repro I dont need to see the data or your specific code, you can use mock data for providing the error as the error looks unrelated to your data. You can create a new notebook/colab.
Actually I dont know about arviz error, if it got fixed -- the code didnt get to that cell and errored out much earlier. I am running the demo notebooks from here on my GCP instance, so there is nothing that I cannot share... I was thinking of creating an environment, use requirements from here and then run -- maybe that might make the version issue (if there is one) go away.
If you can provide me the basic specifications of your instance I can try to re-create from my side.
Here are the details. Thanks for your help @pabloduque0
I am facing the same error while using this code on Google Colab: plot.plot_media_channel_posteriors(media_mix_model=mmm, channel_names=media_cols)
Getting the below error:
**AttributeError Traceback (most recent call last) in <cell line: 2>() 1 # posterior distributions of the media effects. ----> 2 plot.plot_media_channel_posteriors(media_mix_model=mmm, 3 channel_names=media_cols)
AttributeError: 'Figure' object has no attribute 'plot_media_channel_posteriors'**
I have already tried this as well but no resolve: !pip uninstall -y matplotlib !pip install matplotlib==3.1.3
This command: !pip install --upgrade git+https://github.com/google/lightweight_mmm.git is by default installing matplotlib 3.6.1 and giving below error:
\ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. bigframes 1.0.0 requires matplotlib>=3.7.1, but you have matplotlib 3.6.1 which is incompatible. Successfully installed matplotlib-3.6.1 WARNING: The following packages were previously imported in this runtime: [matplotlib,mpl_toolkits] You must restart the runtime in order to use newly installed versions.
So again did this: !python -m pip uninstall matplotlib !pip install matplotlib==3.7.1 and again used this code: plot.plot_media_channel_posteriors(media_mix_model=mmm, channel_names=media_cols) and got the same error below:
**AttributeError Traceback (most recent call last) in <cell line: 2>() 1 # posterior distributions of the media effects. ----> 2 plot.plot_media_channel_posteriors(media_mix_model=mmm, 3 channel_names=media_cols)
AttributeError: 'Figure' object has no attribute 'plot_media_channel_posteriors'**
Only thing different I have done is I have used: from prophet import Prophet in order to decompose weekly sales with ds and holidys data and added trend, season, holiday under extra features in control variables. Rest I am following steps under: https://github.com/google/lightweight_mmm#introduction
Please let me know if anyone able to resolve this.