pymc-marketing icon indicating copy to clipboard operation
pymc-marketing copied to clipboard

v0 Streamlit MMM Explainer App

Open louismagowan opened this issue 1 year ago β€’ 22 comments

A Streamlit app to illustrate saturation, adstock and prior concepts in an intuitive, visual way to stakeholders and new MMMers

Description

I've added a v0 Streamlit app to allow people to visualise and understand important MMM concepts more easily. One page of the app address adstock and has interactive charts of Geometric, Delayed Geometric, Weibull CDF and Weibull PDF adstock, along with LaTex for the transformations and a bit of documentation/explanation. Another page does something similar, but for the most common MMM saturation functions. The entry page visualises common prior distributions used in MMM, allowing users to see how we can encode prior knowledge into our MMMs. A proof of concept deployment can be found here. We can very easily redeploy it using a pymc-marketing email when/if the PR is approved :)

Related Issue

  • [x] Closes #613
  • [ ] Related to #

Checklist

Modules affected

  • [ ] MMM
  • [ ] CLV

Type of change

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

πŸ“š Documentation preview πŸ“š: https://pymc-marketing--614.org.readthedocs.build/en/614/

louismagowan avatar Apr 04 '24 11:04 louismagowan

@iruar @carlosagostini @wd60622 @cetagostini

Lemme know what you guys think! 😁

louismagowan avatar Apr 04 '24 12:04 louismagowan

Seems like a pretty cool idea! How do you expect users to work with it? It seems like the repo would have to be cloned to used. Seems like this would have to be added into the python package (pymc_marketing) folder. Maybe a user could install pymc-marketing and kick this off from the commandline? How do you imagine this workflow?

williambdean avatar Apr 04 '24 15:04 williambdean

Hey @wd60622 ! Thanks for your comments - I actually don't think the users would need to install the package or clone the repo or anything! Streamlit support app deployments, so if you click on the link in the PR description you can see that the app is already live and deployed (or a POC anyway) 😁

I'd picture this more just being linked in the documentation and referred to a bit in the repository. I moved the code here because I'm keen to transfer it to open source pymc-marketing, but I don't mind so much where the code lives just so long as others can have access to it and the app.

louismagowan avatar Apr 04 '24 16:04 louismagowan

This looks great @louismagowan! Is there a link where we can check it out?

I agree with @wd60622 that being able to execute this after installation would be nice. Usually for this an executable .py file would be placed in a scripts folder.

twiecki avatar Apr 05 '24 04:04 twiecki

A proof of concept deployment can be found here. We can very easily redeploy it using a pymc-marketing email when/if the PR is approved :)

Here is the link @twiecki

williambdean avatar Apr 05 '24 05:04 williambdean

Oh I see! Yep so it can be run locally super easily too - it'd just be streamlit run Visualise_Priors.py and it would automatically open up in your browser (provided you've installed the dependencies / activated the MMM venv etc)

Happy to move the code around wherever it needs to go though.

One thing to be aware of, however, is that there are some rules you have to meet to deploy with Streamlit (e.g. the requirements.txt added in the folder when we already have an environment.yml). My current code satisfies those rules, but they might have an impact on where you want to move code etc

louismagowan avatar Apr 05 '24 08:04 louismagowan

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 91.62%. Comparing base (6e37d3b) to head (42a1315).

:exclamation: Current head 42a1315 differs from pull request most recent head 38cd448

Please upload reports for the commit 38cd448 to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #614      +/-   ##
==========================================
- Coverage   92.25%   91.62%   -0.63%     
==========================================
  Files          24       24              
  Lines        2414     2388      -26     
==========================================
- Hits         2227     2188      -39     
- Misses        187      200      +13     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Apr 05 '24 10:04 codecov[bot]

How feasible is it to deploy streamlit under the section of the current website? @twiecki Maybe under the same domain? i.e.https://www.pymc-marketing.io/en/stable/...

Maybe something like the "About PyMC-Labs" would work as well. Screenshot 2024-04-06 at 09 18 36

@louismagowan Is the deployment a manual process? Is it supported with a GitHub action? The easier to maintain, the better in my mind!

williambdean avatar Apr 06 '24 07:04 williambdean

Hey @wd60622 - it's a managed deployment by Streamlit, so super easy (but also slightly less control perhaps). Basically, you just need to specify a repo or a folder within a repo that contains your app code, a requirements.txt and maybe some config - Streamlit just takes that folder/repo and does all the hosting stuff for you. There's no CI/CD or anything, just if you need to make changes to the app you make them, commit and Streamlit updates the app. Nothing to maintain really πŸ˜„

Streamlit make it all super hands-off and easy!

If you want to make changes and test things, they recommend just running the app locally and making the changes vs the local app. Anything that works locally will work in the deployment

louismagowan avatar Apr 08 '24 09:04 louismagowan

Hey @wd60622 - it's a managed deployment by Streamlit, so super easy (but also slightly less control perhaps). Basically, you just need to specify a repo or a folder within a repo that contains your app code, a requirements.txt and maybe some config - Streamlit just takes that folder/repo and does all the hosting stuff for you. There's no CI/CD or anything, just if you need to make changes to the app you make them, commit and Streamlit updates the app. Nothing to maintain really πŸ˜„

Streamlit make it all super hands-off and easy!

Sure. I understand that. However, if we make changes to this files, does streamlit watch the repo? How does it know to redeploy. We'd want this to be the least hand-ons as possible and likely kickoff deployment from our side

williambdean avatar Apr 08 '24 10:04 williambdean

Streamlit watches the repo indeed! Any changes that are made to the repo are reflected in the app immediately and automatically ☺️

louismagowan avatar Apr 08 '24 10:04 louismagowan

Check out this pull request onΒ  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Great initiative! I feel it's a very cool tool to add our repo!

cc: @juanitorduz

cetagostini avatar Apr 15 '24 22:04 cetagostini

Hi! Apologies for the late reply, but we were focusing on the 0.5.0 release πŸ˜„. This PR is next on our review list... Please bare with us πŸ™

juanitorduz avatar Apr 23 '24 11:04 juanitorduz

pre-commit.ci autofix

cetagostini-wise avatar May 06 '24 07:05 cetagostini-wise

pre-commit.ci autofix

cetagostini avatar May 06 '24 07:05 cetagostini

Ok! This PR is next in my to-do πŸ™πŸ˜„

juanitorduz avatar May 06 '24 08:05 juanitorduz

pre-commit.ci autofix

cetagostini avatar May 09 '24 02:05 cetagostini

What if we had this as a separate project that would fix a certain pymc-marketing version as a dependency?

twiecki avatar May 10 '24 09:05 twiecki

What if we had this as a separate project that would fix a certain pymc-marketing version as a dependency?

I think it is worth waiting to merge https://github.com/pymc-labs/pymc-marketing/pull/632 as there will be many changes on the transformations API. That being said, after merging https://github.com/pymc-labs/pymc-marketing/pull/632 we can then use these new functions to feed the streamlit app and have it as an experimental contribution (it is on a different folder). Moving it to a different repo will probably delay making this accessible to the public because here we can reuse the linters and test suite. I agree it would be better to have it as a separate repo for the midterm. WDTY?

juanitorduz avatar May 13 '24 08:05 juanitorduz

What if we had this as a separate project that would fix a certain pymc-marketing version as a dependency?

I think it is worth waiting to merge #632 as there will be many changes on the transformations API. That being said, after merging #632 we can then use these new functions to feed the streamlit app and have it as an experimental contribution (it is on a different folder). Moving it to a different repo will probably delay making this accessible to the public because here we can reuse the linters and test suite. I agree it would be better to have it as a separate repo for the midterm. WDTY?

OK, I think we can incubate it here where it will also be easier to discover and see how that goes.

twiecki avatar May 13 '24 09:05 twiecki

Thanks for the comments and feedback team! All super useful and I agree with it. I was on holiday but will work on addressing the comments ASAP 😁

louismagowan avatar May 13 '24 10:05 louismagowan

@juanitorduz @cetagostini @wd60622 How do you guys think it looks now then?

Apologies for the multiple tags- you had all commented so I was unsure who was best ☺️

Also - FYI, I had to update the Python version of the app to avoid a dependency conflict. So I had to redeploy - the URL of the app is now here. I updated the link in my original message too.

louismagowan avatar May 17 '24 17:05 louismagowan

Great! I'll take a look at it on Tuesday morning (Monday is bank holiday in Berlin). Thanks for the updates! πŸ€œπŸ€›

Have a great weekend!

juanitorduz avatar May 17 '24 17:05 juanitorduz

Thanks @juanitorduz! 😁 That's great news - is someone else going to merge it then? I don't have the permissions to merge it I believe

FYI as well, I might redeploy it once it's merged into master - just so that then the deployment points to the main branch rather than my streamlit_explainer branch. The code will be unchanged

louismagowan avatar May 21 '24 10:05 louismagowan

This is a great addition, thanks @louismagowan!

twiecki avatar May 21 '24 10:05 twiecki

Amazing, thank you @twiecki 😁

louismagowan avatar May 21 '24 10:05 louismagowan