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

Plot Waterfall Components Decomposition #625

Closed

Conversation

cetagostini-wise
Copy link
Contributor

@cetagostini-wise cetagostini-wise commented Apr 11, 2024

Description

Related Issue

  • Closes #
  • Related to #

Checklist

Modules affected

  • MMM
  • CLV

Type of change

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

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

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Missing cell.

Co-Authored-By: Carlos Trujillo <[email protected]>
Comment on lines 1305 to 1315
dataframe["seasonal"] = (
dataframe["sin_order_1"]
+ dataframe["sin_order_2"]
+ dataframe["cos_order_1"]
+ dataframe["cos_order_2"]
)
dataframe.drop(
["sin_order_1", "sin_order_2", "cos_order_1", "cos_order_2"],
axis=1,
inplace=True,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should have a function that extract the seasonal components by looping over "cos_order_" and "sin_order_" over all components defined by yearnly_seasonality (https://github.com/pymc-labs/pymc-marketing/blob/main/pymc_marketing/mmm/delayed_saturated_mmm.py#L54)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, sounds good. Should we created in this same PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

I did the following and looks enough:

        if getattr(self, "yearly_seasonality", None):
            contributions_fourier_over_time = pd.DataFrame(
                az.extract(
                    self.fit_result,
                    var_names=["fourier_contributions"],
                    combined=True,
                )
                .mean("sample")
                .to_dataframe()
                .squeeze()
                .unstack()
                .sum(axis=1),
                columns=["yearly_seasonality"],
            )

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah, you can do it on this PR

cetagostini-wise and others added 3 commits April 12, 2024 00:13
Co-Authored-By: Carlos Trujillo <[email protected]>
Co-Authored-By: Carlos Trujillo <[email protected]>
@ColtAllen
Copy link
Collaborator

I like this plot a lot! Is it possible to flip it around so that the most impactful component is shown first on the X-axis? In visualization theory, our eyes start from the top-left and scan to the right, much like reading a book. If doable, it's best to orient by importance in the same manner.

@juanitorduz
Copy link
Collaborator

@cetagostini-wise I have seen you have a conflict with the mmm example notebook. Git with notebooks is a nightmare so here is a tip: If you want to rebase and keep the changes in your branch then you run:

git rebase --strategy-option theirs main 

If you want to keep the changes from main so that you can update the notebook yourself, then run

git rebase --strategy-option ours main 

I hope it helps :)

Copy link
Contributor

@wd60622 wd60622 left a comment

Choose a reason for hiding this comment

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

some questions and comments

@@ -1274,6 +1276,112 @@ def plot_channel_contribution_share_hdi(
def graphviz(self, **kwargs):
return pm.model_to_graphviz(self.model, **kwargs)

def plot_waterfall_components_decomposition(
self, original_scale: bool = True, figsize: Tuple = (14, 7), **kwargs
Copy link
Contributor

Choose a reason for hiding this comment

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

can we pass an optional ax like in the other plots

pymc_marketing/mmm/base.py Outdated Show resolved Hide resolved
pymc_marketing/mmm/base.py Outdated Show resolved Hide resolved
pymc_marketing/mmm/base.py Show resolved Hide resolved
cetagostini-wise and others added 2 commits April 15, 2024 20:54
Co-Authored-By: Carlos Trujillo <[email protected]>
Co-Authored-By: Carlos Trujillo <[email protected]>
@cetagostini
Copy link
Contributor

@cetagostini-wise I have seen you have a conflict with the mmm example notebook. Git with notebooks is a nightmare so here is a tip: If you want to rebase and keep the changes in your branch then you run:

As discussed can we do it in another branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants