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

Add new customer_choice module #803

Merged
merged 268 commits into from
Dec 28, 2024
Merged

Add new customer_choice module #803

merged 268 commits into from
Dec 28, 2024

Conversation

drbenvincent
Copy link
Contributor

@drbenvincent drbenvincent commented Jul 3, 2024

This PR will add new functionality to pymc-marketing. Namely it will allow causal analysis of product incrementality/cannibalization.

In this initial PR we will focus on:
a) adding docs to introduce the idea behind incrementality/cannibalization analysis
b) in terms of modeling we will start with a multivariate interrupted time series model. This will include a notebook to illustrate its use, as well as docs in the guide section to convey the basic workings.

Later PR's will add additional modeling options, such as nested discrete choice models.

TODO

  • Finish "Introduction to product incrementality" docs page
  • Finish MV-ITS model explanation
  • Add tests
  • Finish how-to notebook demonstrating use
    • Add module code
    • Add Scenario 3 where we operate on product level data
    • Add scenario where market is not saturated + update relevant docs + tests
  • Add a QuickStart on the Getting Started docs page
    • add python code block for QuickStart
  • Rename module to consumer-choice. Update docs and imports and re-run notebooks etc.
  • Fix typo "isoluate" -> "isolate"
  • Update docs homepage and README.md

Known limitations

At the moment the MVITS model is very simple. It only has an intercept term, embodying the assumption that sales are relatively static over time. Clearly there are many ways to expand this model, so the proposal is that we get this in as a first attempt and stepwise add features over time. We can be lead by feature requests (if there are any), but this establishes an MVP which can be built upon.

Checklist

Modules affected

This PR will create a new module and will not affect the MMM or CLV modules.

Type of change

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

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

juanitorduz and others added 30 commits April 19, 2024 09:23
* notebook opening and imports

* model definition markdown

* Data Load Notebook section

* WIP model fitting section

* added notebook to docs directory

* notebook edits and graph code

* ppc section and nb cleanup

* demz sampling and WIP plotting

* WIP predictive plots

* WIP heatmap plots

* predictive plots

* WIP covariates and nbqa-ruff edits

* covariate section

* plot additions

* fig sizes

* remove model file
…book (#651)

* add spaces, increase indentation, and fix number order

* explicit with 6
* Creating plot waterfall

Co-Authored-By: Carlos Trujillo <[email protected]>

* requested changes

* pre-commit

---------

Co-authored-by: Carlos Trujillo <[email protected]>
Databricks should have a lower-case b.
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.4.1 → v0.4.2](astral-sh/ruff-pre-commit@v0.4.1...v0.4.2)
- [github.com/pre-commit/mirrors-mypy: v1.9.0 → v1.10.0](pre-commit/mirrors-mypy@v1.9.0...v1.10.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* support for negative values and dates (if used)

* fix terrible spelling

* test dates in coords

* cover numpy objects

* consolidate the tests
* add quickstartt to readme

* add pymc labs logo

* typos

* add community links

* fixes
* Add contributors to README

* small code style improvements
* Add time-varying prior functionality to DelayedSaturatedMMM

* resolve wd's comments

* resolve failing pre-commits

* add tvp_kwargs to model_config

* fix typo

* replace softplus

* resolve minor review comments

* Add option to supply `ax` to `plot_posterior_predictive`

* bugfix: time_index was not set correctly for OOS

If provided `X` to `_data_setter` was *not* the immediate sequence following the training set, the time_index would we wrong. With this fix, the `date["time_index"]` which gets set upon providing a new `X`, is inferred from the `self.date_column` column of provided `X` (by comparing it to same date column in the training data `self.X`).

* Clean up example notebook

* Make utility function `transform_1d_array`

* 'tvp_kwargs' -> 'intercept_tvp_kwargs'

* move `infer_time_index` into utils

* add tests for new utils

* small fixes (found in tests)

* add tests to cover all added cases

* fix ruff check

* update typehints

* resolve review comments

* refactor model logic for tv intercept

* address review comment for util test

* .

* fix documentation link

* change variable name

* fix hsgp_dims

* update time_varying_prior to be centered on 1

* review fixes

* fix broken test

* add final tests

* fix coverage issues

* Update tests/mmm/test_tvp.py

Co-authored-by: Will Dean <[email protected]>

* Update pymc_marketing/mmm/tvp.py

Co-authored-by: Will Dean <[email protected]>

* Update tests/mmm/test_tvp.py

Co-authored-by: Will Dean <[email protected]>

* Update tests/mmm/test_tvp.py

Co-authored-by: Will Dean <[email protected]>

* significant improvements to notebook

* fix heading

* update notebook to make it EVEN better

* update legend, add watermark

* fix intro

* fix broken test

* copy sweep with grammarly

---------

Co-authored-by: Will Dean <[email protected]>
* add tv intrecept to readme

* add to comparison table
* ignore non-implemented

* remove not implemented error from abstract classes

* simplify docstrings
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.4.3 → v0.4.4](astral-sh/ruff-pre-commit@v0.4.3...v0.4.4)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* feat(streamlit_explainer): Pushing files for Streamlit explainer app, to illustrate saturation, adstock and prior concepts in an intuitive, visual way to stakeholders and new MMMers

* chore(readme): Adding a readme for the app

* fix(env): Updating dependencies to include those needed for the Streamlit app

* Drop python 3.9 support (#615)

* drop python 3.9

* try python 3.12

* undo try python 3.12

* add lift tests check

* Add more content to the Gamma-Gamma Notebook  (#573)

* improve nb

* rm warnings and add link to lifetimes quickstart

* address comments

* feedback part 3

* remove warnings manually

* Add more content to the BG/NBD Notebook (#571)

* add more info to the notebook

* hide plots code

* fix plot y labels

* fix plot outputs and remove model build

* improve final note probability plots

* address comments

* use quickstart dataset

* feedback part 3

* remowe warnings manually

* feedback part 4

* Improve MMM Docs (#612)

* improve mmm docs init

* add more code examples to docstrings

* minor improvemeents

* typo

* better phrasing

* add thomas suggestion

* Fix `clv` plotting bugs and edits to Quickstart (#601)

* move fixtures to conftest

* docstrings and moved set_model_fit to conftest

* fixed pandas quickstart warnings

* revert to MockModel and add ParetoNBD support

* quickstart edit for issue 609

* notebook edit

* [pre-commit.ci] pre-commit autoupdate (#616)

* improve coords matching (#623)

* python 3.12 attempt (#618)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* refactor(saturation): Using pymc-marketing saturation functions rather than coding my own: Removing tanh, logistic and michaelis menten

* refactor(saturation): Remove Hill and Root saturations, as they aren't supported by pymc-marketing currently

* refactor(geometric_adstock): Removing custom adstock and using pymc-marketing adstock function to demo decay. Also updating latex to align with pymc-marketing, where decay factor is represented by alpha rather than beta

* refactor(delayed_adstock): Using pymc-marketing delayed geometric function rather than custom one

* fix(requirements): Adding pymc-marketing to Streamlit requirements for deployment

* Added Dev Container Folder

* refactor(weibull_cdf): Using pymc-marketing function for Weibull CDF

* fix(weibull_cdf): Fixing incorrect dataframe var name for CDF plotting df

* refactor(weibull_pdf): Using pymc-marketing function for WeibullPDF

* refactor(custom_functions): Removing adstock_saturation_functions.py file now that it is no longer required

* chore: Removing devcontainer created by Streamlit

* fix(requirements): Adding preliz to requirements

* refactor(prior_viz): Reworking the prior visualisation to use Preliz instead of custom function, as well as remove the tab-design. Prior distributions can now be specified programmatically.

* refactor(prior_functions.py): Deleting the draw_samples function and replacing it with a programmatic PreliZ function, such that the distribution object is returned when the user passes in the name of a distribution

* fix(requirements): Delete obsolete pymc requirement, which should fix deployment dependency conflicts

* chore(readme): Updating with guidelines on how to add additional distributions or transformation functions to the app

* refactor(plot_config): Moving height and width specifications into constants at top of Adstock and Saturation files, so the plot sizes are set programmatically

---------

Co-authored-by: Juan Orduz <[email protected]>
Co-authored-by: Colt Allen <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Carlos Trujillo <[email protected]>
@drbenvincent drbenvincent changed the title Add causal product incrementality analysis with multivariate interrupted time series models Add new customer_choice module Nov 19, 2024
@juanitorduz
Copy link
Collaborator

@drbenvincent what is the plan for this PR?

@drbenvincent
Copy link
Contributor Author

I think it's very close to done. Would appreciate a review on any of the 'packaging' aspects and docs etc

@juanitorduz
Copy link
Collaborator

I think it's very close to done. Would appreciate a review on any of the 'packaging' aspects and docs etc

@drbenvincent I will have the time to look into this one during this end-of-the-year break 🙏 . it would be great to have it merged by January for our next release ... let's see :)

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.

@wd60622 @drbenvincent I resolved the conflicts of #803 and my suggestion is to merge it as it is becasue I think this is in a good state and we can work on faster iterations in the next weeks before the release. WDYT? I do not want this to be forgotten and we can warn users this is experimental ? WDYT?

@juanitorduz
Copy link
Collaborator

I will create some issues for next iterations

@juanitorduz
Copy link
Collaborator

The pre-commit error will be fixed after we merge #1313

@juanitorduz juanitorduz merged commit 5f74b4d into main Dec 28, 2024
20 checks passed
@juanitorduz juanitorduz deleted the incrementality branch December 28, 2024 07:44
@juanitorduz
Copy link
Collaborator

great work @drbenvincent ! Let's keep working on iterations

@drbenvincent
Copy link
Contributor Author

Great stuff. Thanks for all the review comments. I'm happy to write a social media post when the next release comes out, explaining that this is a minimal viable product which is in line for some improvements.

I'm pretty much unable to do any work until Jan 6th though.

@juanitorduz
Copy link
Collaborator

Sure! No rush! I thing is actually to post about it even in mid or late January! Enjoy your time off !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
causal inference customer choice Related to customer choice module docs Improvements or additions to documentation enhancement New feature or request streamlit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.