New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ValueError: Normal distribution got invalid loc parameter. #124
Comments
thanks for the info here! can you share the values you're passing to the media_prior argument when you run mmm.fit()? |
This is the costs data being put into |
Update: I thought |
perfect, thank you! I see there are still a bunch of zeros here and that's probably what is causing the issue. The default prior for each channel is a half-normal distribution with mean zero and standard deviation equal to the values you're passing here, so when that value is zero the prior gets difficult to define. Changing to a small non-zero value should fix the issue. More generally though, media channels in an MMM should usually have non-zero costs, especially if you want to compute ROIs later in the process and perform channel optimization. |
With this data as the |
thanks for the update! This one is trickier; I think those values should be okay for the solver. Is there any chance that your reduced set of costs has a different number of channels now than your media_data_train, target_train, and extra_features_train? |
|
These look good to me. As far as I know, the |
Thank you! And yes, those dimensions look logically sound to me, so that doesn't seem to be the issue! One thing that I notice (not exactly what's causing your issue, but it may help) is that you have too many features in your model. Very roughly, you have 3x27 parameters for your media channels plus at least 67 more parameters for your extra features, and this is already 148 features (there are a few more internally like the seasonality components), for which you only have 126 target data points. You probably should reduce your number of features by a factor of like 5 or 10 in order to get good model convergence, and this might also (hopefully) help surface whatever issue is causing the invalid loc parameter here too. |
I was subsampling the rows down to that number -- I have around 1100 rows of data but figured that was too much to throw at this. If I include all ~1100 rows of data, should I still try to scale down the number of columns as well? We have a lot of media channels that we optimize our ads spend for, so ideally I'd be able to include all of those channels in this model. |
it's worth trying with the full dataset but you're probably right that it's too large. I'd try different combinations and see what works; it's usually best to start with just a few channels, get a working model, and then add more iteratively. |
I tried it with 126 rows of data, 4 media channel columns (ones we spend on often so no zero-cost), and 14 extra features (dummy-encoded [0,1] holiday features) and still got the same error. I'm not certain it's a data-sizing issue at this point :/ |
Yeah it sounds like something else is going wrong! I just pushed an update to the example Colabs that adds some data quality checks, can you run your dataset through those and see if anything comes up? |
|
Something is off with the scaler that I'm using....
Does this workflow look correct to you? |
If I remove the scaler from everything ( |
Interestingly when I increase the number of rows or features fed into the model, it ends up hitting another error when I don't scale the data prior to
|
For the scalers, since they're dividing by the mean, it sounds like you may have some channels with zero impressions? That would produce the NaNs when applying the scaler to the media data. |
Ok that makes sense mathematically. I will triple check the data I'm feeding into the model to make sure that there's no zero channels. Also quick sidenote, I'm using data that represents spend across channels instead of impressions across channel, and my |
Ok I now have this working on data representing spend across channel.
@michevan Somewhat related to this bug, I noticed switching from a dummy-encoded seasonality feature-space (one column for each week number and holiday with 0-1 indicator values) to the prophet-generated seasonality features (trend, holiday, season) helped to get the model to run. Do you have any recommendations on what format the extra features (notably for seasonality and holiday capture) should be in? |
I think those three points sound correct, yes! And for the extra features, I think it depends on the details of your data, but it's okay to pass either binary or continuous values to the extra features, so if you're finding more success with continuous features that sounds fine to me! |
Hi I am getting the same error and I've determined that the problem is the scaler specifically on the media_data. I have no extra_Features for now and have succeeded in training a model when scaling the costs and the target... But not on the media_data and Ive made sure that none of my media_data columns sum up to 0. (Although every column does have several 0s..) Do you know what else could be the problem? |
I figured it all out. Basically it came down to zero division for the scalers but my problem was not columns of zeros... i had 3d arrays (with sub geo data) and the division was occurring over another axis in which all the values were 0 (a certain country and media source combination was always returning 0). so this led to 0/0. simple solution is to fill the nans with 0 before feeding the scaled data to the training. |
What if you want to keep the zeroes? Some channels we launched later than others, example Facebook and TV we have spend for in most weeks, but a few weeks where we went dark fully, I do not want to remove these from the data source. What other ways are there around this? @google-admin |
Hi! I'm attempting to recreate the sample presented in PyData 2022 seen here with some of my own MMM data: https://github.com/takechanman1228/mmm_pydata_global_2022/blob/main/simple_end_to_end_demo_pydataglobal.ipynb
The below error is displayed:
I've checked for null values in my observation data, and none are present. In addition, I removed zero-cost channels from the data model after checking that a few had zero-cost after scaling and referred to the answer in #115 as such. I also tried scaling down the number of rows and the number of columns that are fed into the model, but none of those have helped get past this error. Please let me know what I can do to diagnose this model. Thanks in advance.
The text was updated successfully, but these errors were encountered: