question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Settle on the API for hierarchical models

See original GitHub issue
# 1) class option
model = LinearTrend() + FourierSeasonality()
model = HierarchicalLinearTrend(group='subject') + FourierSeasonality()
model = GroupedLinearTrend(group='subject') + FourierSeasonality()

# 2) metaclass option
model = LinearTrend() + FourierSeasonality()
model = Hierarchical(LinearTrend(), on='subject') + FourierSeasonality()
model = Distinct(LinearTrend(), on='subject') + FourierSeasonality()

# 3) seperate hierarchy object 1
partial_subject = Share(type='partially_shared', on='subject')
distinct_subject = Share(type='distinct', on='subject')

model = LinearTrend() + FourierSeasonality()
model = LinearTrend().share(partial_subject) + FourierSeasonality()
model = LinearTrend().share(distinct_subject) + FourierSeasonality()

# 4) seperate hierarchy object 2
shared_subject = Share(type='shared')  # default
partial_subject = Share(type='partially_shared', on='subject')
distinct_subject = Share(type='distinct', on='subject')

model = LinearTrend(share=shared_subject) + FourierSeasonality(share=shared_subject)
model = LinearTrend(share=partial_subject) + FourierSeasonality()
model = LinearTrend(share=distinct_subject) + FourierSeasonality()

# 5) keyword option
model = LinearTrend(shared='full') + FourierSeasonality()  #  shared='full' is default
model = LinearTrend(group='subject', shared='partial') + FourierSeasonality()
model = LinearTrend(group='subject', shared='none') + FourierSeasonality()

# Cannibalism in this option
model = Constant(range=(0, None), shared='none') + LinearTrend(shared='full') + ((FourierSeasonality(perios=365) + FourierSeasonality(period=7)) * Constant(range=[-1, 1], group='subject', shared='none'))
model = LinearTrend() + (FourierSeasonality(perios=365) * Constant(range=[-1, 1], group='subject', shared='none')) + FourierSeasonality(period=7)

# 6) keyword option
model = LinearTrend() + FourierSeasonality()
model = LinearTrend(partially_shared_on='subject') + FourierSeasonality()
model = LinearTrend(distinct_on='subject') + FourierSeasonality()

# 7) bitwise or Operator option
model = LinearTrend()                                         # single estimation for all subjects
model = (LinearTrend() | 'subject') + FourierSeasonality()    # hierarchical estimation
model = (LinearTrend() || ('subject') + FourierSeasonality()  # independent estimation

#return day well spent

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MBrounscommented, May 13, 2020

Now here’s a fun grammar problem. What does it now mean if we do model.groupby("product_id")

I agree that that probably shouldn’t be allowed. I wonder if it’s even worth setting this on the entire model, I expect in most cases that you shrink on some parameters but not on others.

That’s mainly because the groups can get verbose in practice (check out the three categories and the id) so re-use is appreciated.

True and that’s indeed one of the major pros of option 4. That said though, you can also get that behaviour with **kwargs like this:

product_categories = {
    "type": "shrinkage",
    "groups": ["prod_category_i", "prod_category_ii"]
}

product_group = {
    "type": "distinct",
    "groups": "product_id"
}

model = (
    Constant(**product_group)
    LinearTrend(**product_categories) + 
    FourierSeasonality(**product_categories)
)

What do you mean with the combination with switchpoints? Variance is a good point. didn’t really think about how that fits in the API yet at all.

0reactions
koaningcommented, May 20, 2020

What does it mean if pooling is partial, complete or None?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Finally! Bayesian Hierarchical Modelling at Scale
In this blog post, I want to draw your attention to the somewhat dusty Bayesian Hierarchical Modelling. Modern techniques and frameworks ...
Read more >
Why hierarchical models are awesome, tricky, and Bayesian
Hierarchical models are underappreciated. Hierarchies exist in many data sets and modeling them appropriately adds a boat load of statistical ...
Read more >
Hierarchical modelling in Python with statsmodels
I have a dataset with random effects at different hierarchies and now I want to analyze how they influence my target variable. Somehow...
Read more >
Using Bayesian Hierarchical Models in PyMC3 to Infer the ...
In this post, we look at how to use PyMC3 to infer the disease parameters for COVID-19. PyMC3 is a popular probabilistic programming ......
Read more >
Reduce forecasting bias with hierarchical aggregation | Vertex ...
For detailed instructions on how to configure hierarchical forecasting when training your forecasting model using the API, see Train a forecast model.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found