Skip to content
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

Media transformation class and different transformations based on subsets of channels #968

Merged

Conversation

wd60622
Copy link
Contributor

@wd60622 wd60622 commented Aug 23, 2024

Description

Allow for media transformation on subset of channels

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--968.org.readthedocs.build/en/968/

@wd60622 wd60622 added enhancement New feature or request MMM labels Aug 23, 2024
@wd60622 wd60622 added this to the 0.9.0 milestone Aug 23, 2024
@wd60622 wd60622 linked an issue Aug 23, 2024 that may be closed by this pull request
Copy link

codecov bot commented Aug 23, 2024

Codecov Report

Attention: Patch coverage is 89.04110% with 8 lines in your changes missing coverage. Please review.

Project coverage is 95.48%. Comparing base (cafa3f8) to head (46192b6).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pymc_marketing/mmm/media_transformation.py 88.23% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #968      +/-   ##
==========================================
- Coverage   95.62%   95.48%   -0.14%     
==========================================
  Files          36       37       +1     
  Lines        3517     3590      +73     
==========================================
+ Hits         3363     3428      +65     
- Misses        154      162       +8     

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

Comment on lines 43 to 44
MediaConfig,
MediaConfigs,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shall we have more different names? Just as "s" at the end is a typo-rick hehe. For example MediaConfig and MediaConfigList?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea 😆

]


Apply the media transformation to media data in PyMC model:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this configuration specification be used through the media_config parameter with the MMM model class? If so, could you provide an example here as well 🙏 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There isn't a media_config parameter at the moment. But we could make one 👀

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.

Wow! Super Cool! Just left some questions.

Comment on lines 208 to 211
MediaConfigs = list[MediaConfig]


def apply_media_transformation(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If these are wrapped in a class, then it should be pretty easy to make a consistent API with the apply method.

WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes!

else (self.saturation, self.adstock)
)

def __call__(self, x, dim):
Copy link
Contributor Author

@wd60622 wd60622 Aug 24, 2024

Choose a reason for hiding this comment

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

I use call here instead of an apply method used in individual transformations. WYDT?
As mentioned below, we can have

media_data = ...
online_media_transformation = MediaTransformation(adstock=..., saturation=..., ...)
offline_media_transformation = MediaTransformation(adstock=..., saturation=..., ...)
media_configs = [MediaConfig(media_transformation=online_media_transformation), MediaConfig(media_transformation=offline_media_transformation)]
# Wrapper around current MediaConfigs
comb_media_transformation = CombinedMediaTransformation(media_configs=media_configs)

# Make all three work the same
offline_media_transformation(media_data, dims="media")
online_media_transformation(media_data, dims="media")
comb_media_transformation(media_data, dims="media")

This would have have many conveniences

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice! 😎

@wd60622
Copy link
Contributor Author

wd60622 commented Aug 29, 2024

I've addressed all the feedback @juanitorduz except for the integration with MMM. That would require a handful of adjustments and discussion.

For instance,
is this a new parameter for initialization?

media_transformation = MediaTransformation(...)
mmm = MMM(media_transformation=media_transformation, ...)

media_transformation = MediaConfigList(...)
mmm = MMM(media_transformation=media_transformation, ...)

That has some implications:

  • what do we do with current parameters adstock, saturation, adstock_first? Deprecate?
  • How do we handle all of the model_config parameters? Should we store all of ModelTransformation / ModelConfigList there even though that is duplicated since there are stored in the individual transformations themselves
  • Various plotting functions need to be rewritten in order to support multiple adstocks / saturations etc
  • Budget optimizer will only conditionally work if single MediaTransformation

Definitely doable though

Do you want to do now or wait on this? Let me know how you imagine this being added in

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.

Yay! We should work on iterstions so let's merge this one and leave the MMM integration for another PR (can you please create an issue so that we keep track?)

@wd60622
Copy link
Contributor Author

wd60622 commented Aug 29, 2024

Yay! We should work on iterstions so let's merge this one and leave the MMM integration for another PR (can you please create an issue so that we keep track?)

Yes, will make some issues now.

Would you like me to increase the test coverage?

@juanitorduz
Copy link
Collaborator

@wd60622 from my side it looks ok! If you wanna test edge cases go for it.

@wd60622
Copy link
Contributor Author

wd60622 commented Aug 29, 2024

@wd60622 from my side it looks ok! If you wanna test edge cases go for it.

I will create an issue for it

@wd60622 wd60622 merged commit f2318ae into main Aug 29, 2024
11 of 12 checks passed
radiokosmos pushed a commit to radiokosmos/pymc-marketing that referenced this pull request Sep 3, 2024
twiecki pushed a commit that referenced this pull request Sep 10, 2024
twiecki pushed a commit that referenced this pull request Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request MMM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Different media transformations across different channels
2 participants