Skip to content

CapeCod.predict infers the fitted grain from key_labels: should that inference exist? #1274

Description

@ppcvote

Split out of #1265 at @henrydingliu's request. No bug here, this is the design question that issue kept running into.

There are two ways to say "fit by line of business, apply per company":

# A: the parameter
cl.CapeCod(groupby="LOB").fit(tri, sample_weight=prem)

# B: aggregate the training data and let predict() work out what happened
model = cl.CapeCod().fit(
    tri.groupby("LOB").sum(), sample_weight=prem.groupby("LOB").sum())
model.predict(tri, sample_weight=prem)

B works by diffing key_labels between sample_weight and apriori_ and regrouping if they differ (capecod.py:325). That inference is where the #1265 bug lived.

The two routes agree, once development is grouped consistently (clrd, comauto):

route apriori
A, Development() ungrouped 0.5602627308
A, Development(groupby="LOB") 0.5689995797
B 0.5689995797

One correction to what I wrote in #1265: I presented A and B as giving different aprioris. The difference is entirely the development grain, not the CapeCod grain.

So: with groupby available and giving the identical answer, does predict() need to infer the grain at all? As I see it:

  1. Leave it. It is the behaviour [BUG] CapeCod predict at different index grain #400 asked for and it works once CapeCod.predict discards the fitted apriori when the model was fit on exactly one fewer index level #1265 is fixed.
  2. Keep it, document that A and B are equivalent, and warn when the inference fires.
  3. Deprecate the inference in favour of groupby.

I lean 2. The inference is convenient, but it currently happens invisibly: a user who calls predict() on a 775-company triangle gets a 6-row apriori_ back and nothing says why. A warning turns a silent regrouping into a visible one.

I can implement whichever you prefer.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Scope

    None yet

    Effort

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions