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

mock MMM posterior with prior #582

Closed
wants to merge 30 commits into from
Closed

Conversation

wd60622
Copy link
Contributor

@wd60622 wd60622 commented Mar 10, 2024

Description

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

@wd60622
Copy link
Contributor Author

wd60622 commented Mar 10, 2024

I have only two tests failing on my side because the values are now in different scale.

However, the tests run much faster 🎉 ~22mins -> 17mins -> 11mins
I am cutting down your coffee breaks 😉 @juanitorduz

@wd60622 wd60622 requested a review from ricardoV94 March 14, 2024 18:56
@wd60622 wd60622 marked this pull request as ready for review March 14, 2024 18:57
@wd60622
Copy link
Contributor Author

wd60622 commented Mar 14, 2024

I've mock the posterior with a prior

I've removed the two tests that were based on a "good" fit based on the input y:

  • the predictions are all positive
  • all within interval
    I don't know if they were the best tests to begin with and I don't think these tests would make sense for the prior predictive

If there are any alternative suggestions, let me know. Would love to hear your thoughts @ricardoV94

Working on the actually fit tests that will be marked as slow. Are there any criteria that sticks out in your mind to test?

Copy link

codecov bot commented Mar 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.11%. Comparing base (7be19f6) to head (d8c49ce).

Current head d8c49ce differs from pull request most recent head 90ff335

Please upload reports for the commit 90ff335 to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #582      +/-   ##
==========================================
- Coverage   92.57%   91.11%   -1.47%     
==========================================
  Files          24       21       -3     
  Lines        2520     2172     -348     
==========================================
- Hits         2333     1979     -354     
- Misses        187      193       +6     

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

Comment on lines -713 to -814
# Original scale constraint
assert np.all(posterior_predictive_mean >= 0)

# Domain kept close
lower, upper = np.quantile(a=posterior_predictive_mean, q=[0.025, 0.975], axis=0)
assert lower < toy_y.mean() < upper
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense for these tests not to work with the changes? They seem like rather useful checks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Commented this above. I will add these to the tests from the actual fit.
Using the normal likelihood doesn't guarantee the prior will meet these constraints. They were geared toward a fit model. Not a prior predictive

@wd60622
Copy link
Contributor Author

wd60622 commented Mar 21, 2024

Ran git pull and made a messy history. Sorry

I've added some slow tests to the MMM test suite that build of what was already existing but some additional checks like parameters being close to actuals

Let me know what you think of the quality of these tests! @juanitorduz

@ricardoV94
Copy link
Contributor

Ran git pull and made a messy history. Sorry

Probably you wanted git pull --rebase

@wd60622
Copy link
Contributor Author

wd60622 commented Mar 21, 2024

Ran git pull and made a messy history. Sorry

Probably you wanted git pull --rebase

Fine if we just squash? Or shall I retry?

@ricardoV94
Copy link
Contributor

Don't retry :D

@wd60622
Copy link
Contributor Author

wd60622 commented Mar 22, 2024

Only 1 test failing when trying to recover the original parameters. Trying to toy around with it as I think the scaling of the variables of X might be messing up the recovery.

Maybe we can save this for future issue with the speed gain from the non-slow tests

Wonder if you have any thoughts @juanitorduz . Any suggestions would be helpful

@wd60622
Copy link
Contributor Author

wd60622 commented Mar 24, 2024

Test issue might be solved here @juanitorduz

@wd60622 wd60622 requested a review from juanitorduz April 1, 2024 19:45
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.

Nice! I just left minor comments :) Can you please resolve the small conflicts with the main branch so that we can merge this one? :)

@wd60622
Copy link
Contributor Author

wd60622 commented Apr 8, 2024

The test, test_distribution_customer_churn_time , is now failing. Would you know anything about this @ricardoV94 ? Maybe @ColtAllen

@ricardoV94
Copy link
Contributor

The test, test_distribution_customer_churn_time , is now failing. Would you know anything about this @ricardoV94 ? Maybe @ColtAllen

No idea why, seems like a meaningful failure. Better to open an issue about it

@juanitorduz
Copy link
Collaborator

The test, test_distribution_customer_churn_time , is now failing. Would you know anything about this @ricardoV94 ? Maybe @ColtAllen

No idea why, seems like a meaningful failure. Better to open an issue about it

It is open: #620

I checked and seems related to a pymc 5.12 -> 5.13 change (I tested locally and it started failing after the release)

@ricardoV94
Copy link
Contributor

The test, test_distribution_customer_churn_time , is now failing. Would you know anything about this @ricardoV94 ? Maybe @ColtAllen

No idea why, seems like a meaningful failure. Better to open an issue about it

It is open: #620

I checked and seems related to a pymc 5.12 -> 5.13 change (I tested locally and it started failing after the release)

You confirmed it passes on main with PyMC 5.12, and fails with 5.13? To rule out changes in the codebase here as well

Copy link
Contributor Author

@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.

For context

Comment on lines +884 to +893
def random_mask(df: pd.DataFrame, mask_value: float = 0.0) -> pd.DataFrame:
shape = df.shape

mask = rng.choice([0, 1], size=shape, p=[0.75, 0.25])
return df.mul(mask)


@pytest.fixture(scope="module")
def masked_toy_X(toy_X) -> pd.DataFrame:
return toy_X.set_index("date").pipe(random_mask).reset_index()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The rational here is that since all of the toy_X columns are pretty much white noise, the generated y is also pretty much a white noise and the model doesn't fit well

Here there are some clear stops in toy_X making the y notably depend on the covariates

tests/mmm/test_delayed_saturated_mmm.py Outdated Show resolved Hide resolved
@wd60622
Copy link
Contributor Author

wd60622 commented Jun 5, 2024

Closing as #632 introduces the mock_fit in the test suite. However, I've create #721 to follow up with some of the efforts here

@wd60622 wd60622 closed this Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mock posterior with prior for MMM tests Migrate MMM plotting tests to test_base
4 participants