Skip to content

Conversation

williambdean
Copy link
Contributor

@williambdean williambdean commented Jan 11, 2024

Description

Redo of the support for new mmm data

This brings in the feedback about

  • having the include_last_observations for all predict methods with X_pred
  • Support for original scale of target with the original_scale keyword that can be passed to all predict methods

Related Issue

Checklist

Modules affected

  • MMM
  • CLV

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

📚 Documentation preview 📚: https://pymc-marketing--482.org.readthedocs.build/en/482/

@williambdean williambdean changed the title run pre-commit Support New MMM Data Jan 11, 2024
@williambdean
Copy link
Contributor Author

williambdean commented Jan 11, 2024

Introducing the new predict_posterior call on mmm model

Screenshot 2024-01-11 at 20 41 28

**This is just an arbitrary fit with mmm-example.csv with last 10 weeks (rows) held out

@juanitorduz juanitorduz self-requested a review January 11, 2024 21:28
Copy link

codecov bot commented Jan 11, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (49e1e80) 90.83% compared to head (bd44767) 91.12%.
Report is 5 commits behind head on main.

Files Patch % Lines
pymc_marketing/mmm/delayed_saturated_mmm.py 95.12% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #482      +/-   ##
==========================================
+ Coverage   90.83%   91.12%   +0.29%     
==========================================
  Files          21       21              
  Lines        1974     2018      +44     
==========================================
+ Hits         1793     1839      +46     
+ Misses        181      179       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

with self.model: # sample with new input data
post_pred = pm.sample_posterior_predictive(self.idata, **kwargs)
if extend_idata:
self.idata.extend(post_pred) # type: ignore
Copy link
Contributor

@ricardoV94 ricardoV94 Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to define join otherwise calling this method twice will ignore the second run

See pymc-devs/pymc-extras#249

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This applies to prior and fit as well, but maybe it's a good time as any to fix it as it's a pretty serious one.

I had a PR on this but haven't come back to it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. This is in the method override. Shall I add to the model_builder method as well?

Copy link
Contributor

@ricardoV94 ricardoV94 Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. Feel free to reuse as much as you can from the PR of the pymc-experimental ModelBuilder (thinking about tests as well). Just add the author as a co-author or mention in the commit if you do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I will dive into it more later

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just added a check that the idata will be the first sample from two method calls to keep it simple. Hope that's what you expected

Copy link
Contributor

@ricardoV94 ricardoV94 Jan 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think fit is still overriding whatever was there before. Example sample_prior_predictive -> fit removes sample_prior_predictive (if I read the code correctly)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need to be done in this PR, just mentioning here for the related issue #459

Copy link
Collaborator

@juanitorduz juanitorduz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks super nice! Thanks! I just added some comments about the docs and other minor things.

@juanitorduz
Copy link
Collaborator

@wd60622 After we merge this one, we need to add (or create) an example to the docs (let's create an issue). This one will be a game-changer feature 🚀

@williambdean
Copy link
Contributor Author

Thank you guys for the review! I will have some time tomorrow to make some changes

@williambdean
Copy link
Contributor Author

I've made edits based on all the comments @juanitorduz and @ricardoV94
Thank you for the feedback

Copy link
Collaborator

@juanitorduz juanitorduz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is amazing @wd60622 ! From my side, I just wanna push this out and get feedback. My sleep deprivation (👶 ) might make me miss some details so if @ricardoV94 is happy I suggest we merge and release 0.4 🚀

@ricardoV94 ricardoV94 changed the title Support New MMM Data Handle new data correctly in MMM posterior predictive methods Jan 18, 2024
@ricardoV94 ricardoV94 added bug Something isn't working MMM labels Jan 18, 2024
@ricardoV94 ricardoV94 added the enhancement New feature or request label Jan 18, 2024
@ricardoV94 ricardoV94 changed the title Handle new data correctly in MMM posterior predictive methods Handle new data correctly and extend functionality of MMM posterior predictive methods Jan 18, 2024
@williambdean
Copy link
Contributor Author

williambdean commented Jan 18, 2024

Hi @ricardoV94. Thanks for the feedback. I just went through all of it and made some changes.

For the xarray tests, I changed to used check for the second sampling result and am using xr.testing module now for more robust checks.

@juanitorduz
Copy link
Collaborator

LGTM 🚀 ! Let's wait for @ricardoV94 's feedback :)

@ricardoV94
Copy link
Contributor

@wd60622 everything looks kosher, but there is still this open discussion: #482 (comment)

Given how all sampling/fitting methods require x/y anyway I changed my mind and I don't think the _reset_data call is needed after all? The less magic probably the better

@williambdean
Copy link
Contributor Author

@wd60622 everything looks kosher, but there is still this open discussion: #482 (comment)

Given how all sampling/fitting methods require x/y anyway I changed my mind and I don't think the _reset_data call is needed after all? The less magic probably the better|

Perfect. I've changed that back so that the data will not be reset

@juanitorduz
Copy link
Collaborator

Are we ready to merge? 🤞

@williambdean
Copy link
Contributor Author

Are we ready to merge? 🤞

Had the affected tests passing locally. They seem to be waiting to start on GitHub 😢

@juanitorduz
Copy link
Collaborator

juanitorduz commented Jan 25, 2024

It's green! 💚. I think we just need @ricardoV94 's last approval :)

@ricardoV94 ricardoV94 merged commit bc71f15 into pymc-labs:main Jan 25, 2024
@ricardoV94
Copy link
Contributor

Merged, any notebooks that need updating?

@juanitorduz
Copy link
Collaborator

Merged, any notebooks that need updating?

I ran the notebook in my first review and it worked perfectly. I can check tomorrow (@wd60622 do we need an update?).

@williambdean williambdean deleted the support-new-data-redo branch January 25, 2024 22:18
@williambdean
Copy link
Contributor Author

Firstly, thank you both for the reviews!

Merged, any notebooks that need updating?

I ran the notebook in my first review and it worked perfectly. I can check tomorrow (@wd60622 do we need an update?).

I haven't touched the notebooks. I would like to add an example in docstring / notebook with #494
I will check get to that on the weekend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request MMM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

scaling control vars
3 participants