Skip to content

Commit

Permalink
Merge branch 'main' into cum_trans_util
Browse files Browse the repository at this point in the history
  • Loading branch information
ColtAllen authored Oct 1, 2024
2 parents 3b3704e + 0587643 commit 16b5b31
Show file tree
Hide file tree
Showing 23 changed files with 2,361 additions and 1,862 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
- --exclude=docs/
- --exclude=scripts/
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.4
rev: v0.6.8
hooks:
- id: ruff
types_or: [python, pyi, jupyter]
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">

![PyMC-Marketing Logo](https://github.com/pymc-labs/pymc-marketing/blob/main/docs/source/_static/marketing-logo-light.jpg)
![PyMC-Marketing Logo](docs/source/_static/marketing-logo-light.jpg)

</div>

Expand All @@ -27,10 +27,10 @@ Unlock the power of **Marketing Mix Modeling (MMM)** and **Customer Lifetime Val
This repository is supported by [PyMC Labs](https://www.pymc-labs.com).

<center>
<img src="https://github.com/pymc-labs/pymc-marketing/blob/main/docs/source/_static/labs-logo-light.png" width="50%" />
<img src="docs/source/_static/labs-logo-light.png" width="50%" />
</center>

For businesses looking to integrate PyMC-Marketing into their operational framework, [PyMC Labs](https://www.pymc-labs.com) offers expert consulting and training. Our team is proficient in state-of-the-art Bayesian modeling techniques, with a focus on Marketing Mix Models (MMMs) and Customer Lifetime Value (CLV). For more information see [here](#-schedule-a-free-consultation-for-mmm--clv-strategy).
For businesses looking to integrate PyMC-Marketing into their operational framework, [PyMC Labs](https://www.pymc-labs.com) offers expert consulting and training. Our team is proficient in state-of-the-art Bayesian modeling techniques, with a focus on Marketing Mix Models (MMMs) and Customer Lifetime Value (CLV). For more information see [here](README.md#-schedule-a-free-consultation-for-mmm--clv-strategy).

Explore these topics further by watching our video on [Bayesian Marketing Mix Models: State of the Art](https://www.youtube.com/watch?v=xVx91prC81g).

Expand All @@ -54,7 +54,7 @@ For a comprehensive installation guide, refer to the [official PyMC installation

### Docker

We provide a `Dockerfile` to build a Docker image for PyMC-Marketing so that is accessible from a Jupyter Notebook. See [here](/scripts/docker/README.md) for more details.
We provide a `Dockerfile` to build a Docker image for PyMC-Marketing so that is accessible from a Jupyter Notebook. See [here](scripts/docker/README.md) for more details.

## In-depth Bayesian Marketing Mix Modeling (MMM) in PyMC

Expand Down Expand Up @@ -111,12 +111,12 @@ mmm.fit(X,y)
mmm.plot_components_contributions();
```

![](https://github.com/pymc-labs/pymc-marketing/blob/main/docs/source/_static/mmm_plot_components_contributions.png)
![](docs/source/_static/mmm_plot_components_contributions.png)

Once the model is fitted, we can further optimize our budget allocation as we are including diminishing returns and carry-over effects in our model.

<center>
<img src="/docs/source/_static/mmm_plot_plot_channel_contributions_grid.png" width="80%" />
<img src="docs/source/_static/mmm_plot_plot_channel_contributions_grid.png" width="80%" />
</center>

Explore a hands-on [simulated example](https://pymc-marketing.readthedocs.io/en/stable/notebooks/mmm/mmm_example.html) for more insights into MMM with PyMC-Marketing.
Expand Down Expand Up @@ -166,19 +166,19 @@ beta_geo_model.fit()

Once fitted, we can use the model to predict the number of future purchases for known customers, the probability that they are still alive, and get various visualizations plotted.

![](https://github.com/pymc-labs/pymc-marketing/blob/main/docs/source/_static/expected_purchases.png)
![](docs/source/_static/expected_purchases.png)

See the Examples section for more on this.

## Why PyMC-Marketing vs other solutions?

PyMC-Marketing is and will always be free for commercial use, licensed under [Apache 2.0](LICENSE). Developed by core developers behind the popular PyMC package and marketing experts, it provides state-of-the-art measurements and analytics for marketing teams.

Due to its open-source nature and active contributor base, new features are constantly added. Are you missing a feature or want to contribute? Fork our repository and submit a pull request. If you have any questions, feel free to [open an issue](https://github.com/your-repo/issues).
Due to its open-source nature and active contributor base, new features are constantly added. Are you missing a feature or want to contribute? Fork our repository and submit a pull request. If you have any questions, feel free to [open an issue](https://github.com/pymc-labs/pymc-marketing/issues).

### Thanks to our contributors!

[![https://github.com/pymc-devs/pymc/graphs/contributors](https://contrib.rocks/image?repo=pymc-labs/pymc-marketing)](https://github.com/pymc-labs/pymc-marketing/graphs/contributors)
[![https://github.com/pymc-labs/pymc-marketing/graphs/contributors](https://contrib.rocks/image?repo=pymc-labs/pymc-marketing)](https://github.com/pymc-labs/pymc-marketing/graphs/contributors)


## Marketing AI Assistant: MMM-GPT with PyMC-Marketing
Expand Down
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
project = "pymc-marketing"
author = "PyMC Labs"
copyright = f"2022, {author}"
html_title = "Open Source Marketing Analytics Solution"

# The master toctree document.
master_doc = "index"
Expand Down
160 changes: 160 additions & 0 deletions docs/source/contributing/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Contributing

PyMC-Marketing welcomes contributions from interested individuals or groups. These guidelines are provided to give potential contributors information to make their contribution compliant with the conventions of the PyMC-Marketing project, and maximize the probability of such contributions to be merged as quickly and efficiently as possible. Contributors need not be experts, but should be interested in the project, willing to learn, and share knowledge.

There are 4 main ways of contributing to the PyMC-Marketing project (in ascending order of difficulty or scope):

1. Submitting issues related to bugs or desired enhancements.
2. Contributing or improving the documentation (docs) or examples.
3. Fixing outstanding issues (bugs) with the existing codebase. They range from low-level software bugs to higher-level design problems.
4. Adding new or improved functionality to the existing codebase.

Items 2-4 require setting up a local development environment, see [Local development steps](#Contributing-code-via-pull-requests) for more information.

## Opening issues
We appreciate being notified of problems with the existing PyMC-Marketing code. We prefer that issues be filed the on [Github Issue Tracker](https://github.com/pymc-labs/pymc-marketing/issues), rather than on social media or by direct email to the developers.

Please verify that your issue is not being currently addressed by other issues or pull requests by using the GitHub search tool to look for key words in the project issue tracker.

## Contributing code via pull requests

While issue reporting is valuable, we strongly encourage users who are inclined to do so to submit patches for new or existing issues via pull requests. This is particularly the case for simple fixes, such as typos or tweaks to documentation, which do not require a heavy investment of time and attention.

Contributors are also encouraged to contribute new code to enhance PyMC-Marketing's functionality, via pull requests.

The preferred workflow for contributing to PyMC-Marketing is to fork the GitHub repository, clone it to your local machine, and develop on a feature branch.

For more instructions see the [Pull request checklist](#pull-request-checklist)

## Local development steps

1. If you have not already done so, fork the [project repository](https://github.com/pymc-labs/pymc-marketing) by clicking on the 'Fork' button near the top right of the main repository page. This creates a copy of the code under your GitHub user account.

1. Clone your fork of the `pymc-marketing` repo from your GitHub account to your local disk, and add the base repository as a remote:

```bash
git clone [email protected]:<your GitHub handle>/pymc-marketing.git
cd pymc-marketing
git remote add upstream [email protected]:pymc-labs/pymc-marketing.git
```

Alternatively, if you use the [GitHub CLI](https://cli.github.com/), then the required command is just

```bash
gh repo fork pymc-labs/pymc-marketing
```


1. Create a feature branch (e.g. `my-feature`) to hold your development changes:

```bash
git checkout -b my-feature
```

Always use a feature branch. It's good practice to never routinely work on the `main` branch of any repository.
1. Create a dedicated development environment from the file present in the repo:
```bash
conda env create -f environment.yml
```
This will create an environment called `pymc-marketing-dev`. Activate the environment.
```bash
conda activate pymc-marketing-dev
```
Install the package (in editable mode) and its development dependencies:
```bash
make init
```
Set [pre-commit hooks](https://pre-commit.com/). First install pre-commit package (either `pip install pre-commit`, see the package's installation instructions). Alternatively you can run `make check_lint` which will install the `pre-commit` package. Then run this to set up the git hook scripts:

```bash
pre-commit install
```

1. You can then work on your changes locally, in your feature branch. Add changed files using `git add` and then `git commit` files:

```bash
git add modified_files
git commit -m "Message summarizing commit changes"
```

to record your changes locally.
After committing, it is a good idea to sync with the base repository in case there have been any changes:

```bash
git fetch upstream
git rebase upstream/main
```

Then push the changes to your GitHub account with:

```bash
git push -u origin my-feature
```

1. [Optionally] Build the docs locally. If you have changed any of the documentation, you can build it locally to check that it looks as expected.

```bash
make html
```

To delete all intermediate files and cached content and build the docs from scratch, run `make cleandocs` before `make html`

1. Before you submit a Pull request, follow the [Pull request checklist](#pull-request-checklist).

1. Finally, to submit a pull request, go to the GitHub web page of your fork of the PyMC-Marketing repo. Click the 'Pull request' button to send your changes to the project's maintainers for review. This will send an email to the committers.
## Pull request checklist
We recommend that your contribution complies with the following guidelines before you submit a pull request:
- If your pull request addresses an issue, please use the pull request title to describe the issue and mention the issue number in the pull request description. This will make sure a link back to the original issue is created.
- All public methods must have informative docstrings with sample usage when appropriate.
- To indicate a work in progress please mark the PR as `draft`. Drafts may be useful to (1) indicate you are working on something to avoid duplicated work, (2) request broad review of functionality or API, or (3) seek collaborators.
- All other tests pass when everything is rebuilt from scratch.
- When adding additional functionality, either edit an existing example, or create a new example (typically in the form of a Jupyter Notebook) in the `pymc-marketing/docs/source/mmm` or `pymc-marketing/docs/source/clv` folders. Have a look at other examples for reference. Examples should demonstrate why the new functionality is useful in practice.
- Documentation and high-coverage tests are necessary for enhancements to be accepted.
- Documentation follows [NumPy style guide](https://numpydoc.readthedocs.io/en/latest/format.html)
- Run any of the pre-existing examples in `pymc-marketing/docs/source/*` that contain analyses that would be affected by your changes to ensure that nothing breaks. This is a useful opportunity to not only check your work for bugs that might not be revealed by unit test, but also to show how your contribution improves PyMC-Marketing for end users.
- Your code passes linting tests. Run the line below to check linting errors:
```bash
make check_lint
```
- If you want to fix linting errors automatically, run
```bash
make lint
```
- To run tests:
```bash
make test
```
- To check code style:
```bash
make check_format
```
- To fix code style automatically:
```bash
make format
```
16 changes: 16 additions & 0 deletions docs/source/getting_started/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Getting Started

:::{toctree}
:caption: Installation
:maxdepth: 1

installation/index
:::

:::{toctree}
:caption: Quickstart
:maxdepth: 1

quickstart/clv/index
quickstart/mmm/index
:::
43 changes: 43 additions & 0 deletions docs/source/getting_started/installation/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## Installing PyMC-Marketing

PyMC-Marketing requires **Python 3.10 or greater**.

Install and activate an environment (e.g. `marketing_env`) with the `pymc-marketing` package from [conda-forge](https://conda-forge.org). It may look something like the following:

```bash
conda create -c conda-forge -n marketing_env pymc-marketing
conda activate marketing_env
```

You can also install the development version of PyMC-Marketing with:

```bash
pip install git+https://github.com/pymc-labs/pymc-marketing.git
```

Next, we you can create a new Jupyter notebook with either JupyterLab or VS Code.

### JupyterLab Notebook

After installing the `pymc-marketing` package (see above), run the following with `marketing_env` activated:

```bash
conda install -c conda-forge jupyterlab
jupyter lab
```

### VS Code Notebook

After installing the `pymc-marketing` package (see above), run the following with `marketing_env` activated:

```bash
conda install -c conda-forge ipykernel
```

Start VS Code and ensure that the "Jupyter" extension is installed. Press Ctrl + Shift + P and type "Python: Select Interpreter". Ensure that `marketing_env` is selected. Press Ctrl + Shift + P and type "Create: New Jupyter Notebook".

## Installation for developers

If you are a developer of pymc-marketing, or want to start contributing, [refer to the contributing guide](https://github.com/pymc-labs/pymc-marketing/blob/main/CONTRIBUTING.md) to get started.

See the official [PyMC installation guide](https://www.pymc.io/projects/docs/en/latest/installation.html) if more detail is needed.
22 changes: 22 additions & 0 deletions docs/source/getting_started/quickstart/clv/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# CLV Quickstart

We can choose from a variety of models, depending on the type of data and business nature. Let us look into a simple example with the Beta-Geo/NBD model for non-contractual continuous data.

```python
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from pymc_marketing import clv

data_url = "https://raw.githubusercontent.com/pymc-labs/pymc-marketing/main/data/clv_quickstart.csv"
data = pd.read_csv(data_url)
data["customer_id"] = data.index

beta_geo_model = clv.BetaGeoModel(data=data)

beta_geo_model.fit()
```

Once fitted, we can use the model to predict the number of future purchases for known customers, the probability that they are still alive, and get various visualizations plotted.

See the {ref}`howto` section for more on this.
31 changes: 31 additions & 0 deletions docs/source/getting_started/quickstart/mmm/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# MMM Quickstart

```python
import pandas as pd

from pymc_marketing.mmm import (
GeometricAdstock,
LogisticSaturation,
MMM,
)

data_url = "https://raw.githubusercontent.com/pymc-labs/pymc-marketing/main/data/mmm_example.csv"
data = pd.read_csv(data_url, parse_dates=["date_week"])

mmm = MMM(
adstock=GeometricAdstock(l_max=8),
saturation=LogisticSaturation(),
date_column="date_week",
channel_columns=["x1", "x2"],
control_columns=[
"event_1",
"event_2",
"t",
],
yearly_seasonality=2,
)
```

Once the model is fitted, we can further optimize our budget allocation as we are including diminishing returns and carry-over effects in our model.

Explore a hands-on [simulated example](https://pymc-marketing.readthedocs.io/en/stable/notebooks/mmm/mmm_example.html) for more insights into MMM with PyMC-Marketing.
3 changes: 3 additions & 0 deletions docs/source/guide/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Guide

Are you looking for introductory material on Marketing Mix Models or Customer Lifetime Value?
This section provides a guide to the concepts and techniques used in PyMC-Marketing.

:::{toctree}
:caption: Benefits of PyMC-Marketing
:maxdepth: 1
Expand Down
Loading

0 comments on commit 16b5b31

Please sign in to comment.