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

Refactor tests to share data generation code #531

Merged
merged 3 commits into from
Jun 15, 2022

Conversation

markgoodhead
Copy link
Contributor

Small PR to address #530

@codecov-commenter
Copy link

codecov-commenter commented Jun 11, 2022

Codecov Report

Merging #531 (8d4a7dd) into main (91903c8) will decrease coverage by 0.05%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #531      +/-   ##
==========================================
- Coverage   86.84%   86.78%   -0.06%     
==========================================
  Files          32       32              
  Lines        2622     2611      -11     
==========================================
- Hits         2277     2266      -11     
  Misses        345      345              
Impacted Files Coverage Δ
bambi/tests/test_built_models.py 99.00% <100.00%> (-0.04%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 91903c8...8d4a7dd. Read the comment docs.

Copy link
Collaborator

@aloctavodia aloctavodia left a comment

Choose a reason for hiding this comment

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

LGTM!

@tomicapretto
Copy link
Collaborator

Thanks for all the amazing work @markgoodhead !! One addition, I think that @canyon289 was actually saying we could have something like

@pytest.mark.parametrize(
"family",
[
"gaussian",
"negativebinomial",
"bernoulli",
"poisson",
"gamma",
"vonmises",
"wald",
],
)
def test_automatic_priors(family):
"""Test that automatic priors work correctly"""
obs = pd.DataFrame([0], columns=["x"])
Model("x ~ 0", obs, family=family)

correct me if i'm wrong

Something like the following...

@pytest.mark.parametrize("method", ["nuts_numpyro", "nuts_blackjax"]) 
def test_logistic_regression_alternative_samplers(logistic_regression_data, method):
    model = Model("y ~ x", logistic_regression_data, family="bernoulli")
    model.fit(method=method, chain_method="vectorized")

On top of that, I would decrease tune and draws to something like 50 so it doesn't take too much time.

@canyon289
Copy link
Collaborator

Thanks for all the amazing work @markgoodhead !! One addition, I think that @canyon289 was actually saying we could have something like

@pytest.mark.parametrize(
"family",
[
"gaussian",
"negativebinomial",
"bernoulli",
"poisson",
"gamma",
"vonmises",
"wald",
],
)
def test_automatic_priors(family):
"""Test that automatic priors work correctly"""
obs = pd.DataFrame([0], columns=["x"])
Model("x ~ 0", obs, family=family)

correct me if i'm wrong

Something like the following...

@pytest.mark.parametrize("method", ["nuts_numpyro", "nuts_blackjax"]) 
def test_logistic_regression_alternative_samplers(logistic_regression_data, method):
    model = Model("y ~ x", logistic_regression_data, family="bernoulli")
    model.fit(method=method, chain_method="vectorized")

On top of that, I would decrease tune and draws to something like 50 so it doesn't take too much time.

This is what I'm saying :)



@pytest.fixture(scope="module")
def linear_regression_data():
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is great too!

y = pd.Series(np.random.choice(["a", "b"], 50), dtype="category")
data = pd.DataFrame({"y": y, "x": np.random.normal(size=50)})
model = Model("y ~ x", data, family="bernoulli")
def test_logistic_regression_numpyro(logistic_regression_data):
Copy link
Collaborator

Choose a reason for hiding this comment

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

These next couple could be parametrized so now theres only one test. We're really squeezing code lines out now but I hope its a good learning experience!

@markgoodhead
Copy link
Contributor Author

Comments addressed 👍

@aloctavodia aloctavodia merged commit 425b7b8 into bambinos:main Jun 15, 2022
@aloctavodia
Copy link
Collaborator

Thank you, @markgoodhead, this is great!

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