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

excluded _prior suffix from CLV models #1498

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

arthurmello
Copy link
Contributor

@arthurmello arthurmello commented Feb 13, 2025

Description

Removed the _prior suffix from parameters of CLV model config + adjacent files (tests, notebooks, etc.)

Related Issue

Checklist


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

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@github-actions github-actions bot added docs Improvements or additions to documentation CLV tests good second issue Bit more involved but still doable for newcomers maintenance major API breaking changes model config labels Feb 13, 2025
Copy link

codecov bot commented Feb 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.76%. Comparing base (b8b7b9d) to head (cd87a0a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1498      +/-   ##
==========================================
+ Coverage   92.75%   92.76%   +0.01%     
==========================================
  Files          52       52              
  Lines        6127     6138      +11     
==========================================
+ Hits         5683     5694      +11     
  Misses        444      444              

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

@wd60622 wd60622 requested a review from ColtAllen February 13, 2025 19:16
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.

Nice. Thanks for the PR @arthurmello

We should provide a deprecation for this. Likely in the clv/basic class. Maybe we can check for any model_config keys with "_prior" suffix then remove while having a warning

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.

Can we write a test to make sure that save / load is backwards compatible in this scenario

@arthurmello
Copy link
Contributor Author

Sure, do you mean a test that ensures that models saved with the old configuration can still be loaded?
Something like:

def test_backward_compatibility_with_old_config(self, mocker):
        old_model_config = {
            "alpha_prior": ...
            "r_prior": ...
        }
        model = CLVModelTest(model_config=old_model_config)

        mocker.patch("pymc.sample", mock_sample)
        model.fit(...)
        model.save("old_model_config_test")

        loaded_model = CLVModelTest.load("old_model_config_test")

        assert loaded_model.model_config == {
            "alpha": ...,
            "r": ...
        }

@wd60622
Copy link
Contributor

wd60622 commented Feb 14, 2025

Yeah, something like that. Dont need to sample. Just load and make sure that a method that uses the posterior still works

We have an issue if the built model has variables without the prefix and posterior samples do have the prefix.

We might have to rename the variables upon load as well

Comment on lines 238 to 243
def test_backward_compatibility_with_old_config(self):
old_model_config = {
"alpha_prior": Prior("Weibull", alpha=2, beta=10),
"r_prior": Prior("Weibull", alpha=2, beta=1),
}
model = CLVModelTest(model_config=old_model_config)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's test that there is a warning

}
model = CLVModelTest(model_config=old_model_config)
model.fit(tune=0, chains=2, draws=5)
model.save("old_model_config_test")
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't testing for loading from an old saved model. The idata.posterior will have the suffix. We want to check for that suffix in the posterior will not break using the model in the future

@wd60622
Copy link
Contributor

wd60622 commented Feb 16, 2025

pre-commit.ci autofix

@arthurmello arthurmello requested a review from wd60622 February 17, 2025 15:44
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.

Looks good to me. Thanks for the PR!

@ColtAllen Can you take a look as well

@wd60622 wd60622 added this to the 0.12.0 milestone Feb 20, 2025
@ColtAllen
Copy link
Collaborator

Looks good to me. Thanks for the PR!

@ColtAllen Can you take a look as well

I've started looking at this; will post my review tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLV docs Improvements or additions to documentation good second issue Bit more involved but still doable for newcomers maintenance major API breaking changes model config tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exclude prior suffix from CLV model config
3 participants