lightweight_mmm
lightweight_mmm copied to clipboard
Have issues with plot.plot_media_channel_posteriors(media_mix_model=mmm)
I am running the dummy data for lightweight MMM, and when I run the code, below is the error message. I just started using lightweight MMM today. so everything should be the latest version.
plot.plot_media_channel_posteriors(media_mix_model=mmm)
TypingError Traceback (most recent call last) Cell In[39], line 1 ----> 1 plot.plot_media_channel_posteriors(media_mix_model=mmm)
File ~\AppData\Local\anaconda3\Lib\site-packages\lightweight_mmm\plot.py:818, in plot_media_channel_posteriors(media_mix_model, channel_names, quantiles, fig_size) 816 geo_axis.set_xlabel(axis_label) 817 else: --> 818 channel_axis = arviz.plot_kde( 819 media_channel_posteriors[:, channel_i], 820 quantiles=quantiles, 821 ax=channel_axis) 822 axis_label = f"media channel {channel_names[channel_i]}" 823 channel_axis.set_xlabel(axis_label)
File ~\AppData\Local\anaconda3\Lib\site-packages\arviz\plots\kdeplot.py:263, in plot_kde(values, values2, cumulative, rug, label, bw, adaptive, quantiles, rotated, contour, hdi_probs, 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) 260 if bw == "default": 261 bw = "taylor" if is_circular else "experimental" --> 263 grid, density = kde(values, is_circular, bw=bw, adaptive=adaptive, cumulative=cumulative) 264 lower, upper = grid[0], grid[-1] 266 density_q = density if cumulative else density.cumsum() / density.sum()
File ~\AppData\Local\anaconda3\Lib\site-packages\arviz\stats\density_utils.py:498, in kde(x, circular, **kwargs) 495 else: 496 kde_fun = _kde_linear --> 498 return kde_fun(x, **kwargs)
File ~\AppData\Local\anaconda3\Lib\site-packages\arviz\stats\density_utils.py:581, in _kde_linear(x, bw, adaptive, extend, bound_correction, extend_fct, bw_fct, bw_return, custom_lims, cumulative, grid_len, **kwargs) 577 # Determine grid 578 grid_min, grid_max, grid_len = _get_grid( 579 x_min, x_max, x_std, extend_fct, grid_len, custom_lims, extend, bound_correction 580 ) --> 581 grid_counts, _, grid_edges = histogram(x, grid_len, (grid_min, grid_max)) 583 # Bandwidth estimation 584 bw = bw_fct * _get_bw(x, bw, grid_counts, x_std, x_range)
File ~\AppData\Local\anaconda3\Lib\site-packages\arviz\utils.py:193, in maybe_numba_fn.call(self, *args, **kwargs) 191 """Call the jitted function or normal, depending on flag.""" 192 if Numba.numba_flag: --> 193 return self.numba_fn(*args, **kwargs) 194 else: 195 return self.function(*args, **kwargs)
File ~\AppData\Local\anaconda3\Lib\site-packages\numba\core\dispatcher.py:468, in _DispatcherBase._compile_for_args(self, *args, **kws) 464 msg = (f"{str(e).rstrip()} \n\nThis error may have been caused " 465 f"by the following argument(s):\n{args_str}\n") 466 e.patch_message(msg) --> 468 error_rewrite(e, 'typing') 469 except errors.UnsupportedError as e: 470 # Something unsupported is present in the user code, add help info 471 error_rewrite(e, 'unsupported_error')
File ~\AppData\Local\anaconda3\Lib\site-packages\numba\core\dispatcher.py:409, in _DispatcherBase._compile_for_args.
TypingError: Failed in nopython mode pipeline (step: nopython frontend) No implementation of function Function(<function histogram at 0x000001D07B65B7E0>) found for signature:
histogram(readonly buffer(float32, 1d, C), bins=int64, range=UniTuple(readonly buffer(float32, 0d, C) x 2))
There are 2 candidate implementations:
-
Of which 2 did not match due to: Overload in function 'np_histogram': File: numba\np\arraymath.py: Line 3895. With argument(s): '(readonly buffer(float32, 1d, C), bins=int64, range=UniTuple(readonly buffer(float32, 0d, C) x 2))': Rejected as the implementation raised a specific error: TypingError: Failed in nopython mode pipeline (step: nopython frontend) No implementation of function Function(<function linspace at 0x000001D07B5A6E80>) found for signature:
linspace(readonly buffer(float32, 0d, C), readonly buffer(float32, 0d, C), int64)
There are 2 candidate implementations: - Of which 2 did not match due to: Overload of function 'linspace': File: numba\np\arrayobj.py: Line 4638. With argument(s): '(readonly buffer(float32, 0d, C), readonly buffer(float32, 0d, C), int64)': No match.
During: resolving callee type: Function(<function linspace at 0x000001D07B5A6E80>) During: typing of call at C:\Users\dong.h.kang\AppData\Local\anaconda3\Lib\site-packages\numba\np\arraymath.py (3936)
File "....\AppData\Local\anaconda3\Lib\site-packages\numba\np\arraymath.py", line 3936:
def histogram_impl(a, bins=10, range=None):
bins_array = np.linspace(bin_min, bin_max, bins + 1)
^
raised from C:\Users\dong.h.kang\AppData\Local\anaconda3\Lib\site-packages\numba\core\typeinfer.py:1086
During: resolving callee type: Function(<function histogram at 0x000001D07B65B7E0>) During: typing of call at C:\Users\dong.h.kang\AppData\Local\anaconda3\Lib\site-packages\arviz\stats\density_utils.py (979)
File "....\AppData\Local\anaconda3\Lib\site-packages\arviz\stats\density_utils.py", line 979:
def histogram(data, bins, range_hist=None):
I just had this same issue due to the numba package which I think was installed when I installed scikit-lego earlier today.
What I did was uninstall lightweight_mmm, arviz, numpy, and numba. Then I reinstalled lightweight_mmm which automatically installed arviz and numpy for me.
Then I tried the plot again and it worked.
Hopefully this helps!
MMM, and when I run the code, below is the error message. I just started using lightweight MMM today. so everything should be the latest version.
plot.plot_media_channel_posteriors(media_mix_model=
Thank you very much Jonathan!
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)
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)
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.
I am facing the same issue with the following error message:
"TypingError Traceback (most recent call last) Cell In[20], line 3 1 import os 2 os.environ["ARVIZ_NO_NUMBA"] = "True" ----> 3 plot.plot_media_channel_posteriors(media_mix_model=mmm)
File ~\anaconda3\Lib\site-packages\lightweight_mmm\plot.py:817, in plot_media_channel_posteriors(media_mix_model, channel_names, quantiles, fig_size) 815 geo_axis.set_xlabel(axis_label) 816 else: --> 817 channel_axis = arviz.plot_kde( 818 media_channel_posteriors[:, channel_i], 819 quantiles=quantiles, 820 ax=channel_axis) 821 axis_label = f"media channel {channel_names[channel_i]}" 822 channel_axis.set_xlabel(axis_label)
File ~\anaconda3\Lib\site-packages\arviz\plots\kdeplot.py:262, in plot_kde(values, values2, cumulative, rug, label, bw, adaptive, quantiles, rotated, contour, hdi_probs, 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) 259 if bw == "default": 260 bw = "taylor" if is_circular else "experimental" --> 262 grid, density = kde(values, is_circular, bw=bw, adaptive=adaptive, cumulative=cumulative) 263 lower, upper = grid[0], grid[-1] 265 density_q = density if cumulative else density.cumsum() / density.sum()
File ~\anaconda3\Lib\site-packages\arviz\stats\density_utils.py:498, in kde(x, circular, **kwargs) 495 else: 496 kde_fun = _kde_linear --> 498 return kde_fun(x, **kwargs)
File ~\anaconda3\Lib\site-packages\arviz\stats\density_utils.py:581, in _kde_linear(x, bw, adaptive, extend, bound_correction, extend_fct, bw_fct, bw_return, custom_lims, cumulative, grid_len, **kwargs) 577 # Determine grid 578 grid_min, grid_max, grid_len = _get_grid( 579 x_min, x_max, x_std, extend_fct, grid_len, custom_lims, extend, bound_correction 580 ) --> 581 grid_counts, _, grid_edges = histogram(x, grid_len, (grid_min, grid_max)) 583 # Bandwidth estimation 584 bw = bw_fct * _get_bw(x, bw, grid_counts, x_std, x_range)
File ~\anaconda3\Lib\site-packages\arviz\utils.py:201, in maybe_numba_fn.call(self, *args, **kwargs) 199 """Call the jitted function or normal, depending on flag.""" 200 if Numba.numba_flag: --> 201 return self.numba_fn(*args, **kwargs) 202 else: 203 return self.function(*args, **kwargs)
File ~\anaconda3\Lib\site-packages\numba\core\dispatcher.py:468, in _DispatcherBase._compile_for_args(self, *args, **kws) 464 msg = (f"{str(e).rstrip()} \n\nThis error may have been caused " 465 f"by the following argument(s):\n{args_str}\n") 466 e.patch_message(msg) --> 468 error_rewrite(e, 'typing') 469 except errors.UnsupportedError as e: 470 # Something unsupported is present in the user code, add help info 471 error_rewrite(e, 'unsupported_error')
File ~\anaconda3\Lib\site-packages\numba\core\dispatcher.py:409, in _DispatcherBase._compile_for_args.
TypingError: Failed in nopython mode pipeline (step: nopython frontend) No implementation of function Function(<function histogram at 0x000001885F3402C0>) found for signature:
histogram(readonly buffer(float32, 1d, C), bins=int64, range=UniTuple(readonly buffer(float32, 0d, C) x 2))
There are 2 candidate implementations:
-
Of which 2 did not match due to: Overload in function 'np_histogram': File: numba\np\arraymath.py: Line 3907. With argument(s): '(readonly buffer(float32, 1d, C), bins=int64, range=UniTuple(readonly buffer(float32, 0d, C) x 2))': Rejected as the implementation raised a specific error: TypingError: Failed in nopython mode pipeline (step: nopython frontend) No implementation of function Function(<function linspace at 0x000001885F25D080>) found for signature:
linspace(readonly buffer(float32, 0d, C), readonly buffer(float32, 0d, C), int64)
There are 2 candidate implementations: - Of which 2 did not match due to: Overload of function 'linspace': File: numba\np\arrayobj.py: Line 4817. With argument(s): '(readonly buffer(float32, 0d, C), readonly buffer(float32, 0d, C), int64)': No match.
During: resolving callee type: Function(<function linspace at 0x000001885F25D080>) During: typing of call at C:\Users\Sirin\anaconda3\Lib\site-packages\numba\np\arraymath.py (3948)
File "..........\anaconda3\Lib\site-packages\numba\np\arraymath.py", line 3948:
def histogram_impl(a, bins=10, range=None):
bins_array = np.linspace(bin_min, bin_max, bins + 1)
^
raised from C:\Users\Sirin\anaconda3\Lib\site-packages\numba\core\typeinfer.py:1091
During: resolving callee type: Function(<function histogram at 0x000001885F3402C0>) During: typing of call at C:\Users\Sirin\anaconda3\Lib\site-packages\arviz\stats\density_utils.py (979)
File "..........\anaconda3\Lib\site-packages\arviz\stats\density_utils.py", line 979:
def histogram(data, bins, range_hist=None):
I am facing the same issue. Can anyone give a simple explanation with the code on how they bypass this problem?