Skip to content

[BUG] An exposure triangle passed as sample_weight gives ultimate_ one column per development age, without an error #1615

Open

Description

@scks1

Are you on the latest chainladder version?

  • Yes, this bug occurs on the latest version.

Describe the bug in words

BornhuetterFerguson, Benktander, CapeCod and ExpectedLoss expect sample_weight with one development column, such as premium.latest_diagonal. If a user passes the full exposure triangle instead, fit runs, and ultimate_ and ibnr_ come back with one column per development age: (1, 1, 10, 10) on raa instead of (1, 1, 10, 1). No error or warning is raised. Summing ibnr_ then counts each origin once per column, so the raa total is 83,931.06 instead of 32,229.96.

When exposure changes with age the first column is also different, because it uses the exposure at the first age instead of the latest one. In a four-origin monthly example the BF ultimates in column 0 were 46.9, 54.72, 64.2, 77.36 with the full triangle against 46.9, 65.76, 78.86, 85.96 with its latest diagonal. CapeCod on that triangle raises ValueError: operands could not be broadcast together with shapes (1,1,22,4) (4,4), which does not point to the cause. On raa, where the exposure is the same at every age, CapeCod still changes column 0: the 1990 ultimate is 18,785.62 with the full triangle and 21,605.83 with the latest diagonal. predict(X, sample_weight=<full triangle>) behaves like fit.

MethodBase.validate_weight (base.py L214–229) compares only shape[:-1], so it never looks at the development axis. #1416 rewrites this function to raise when the first three axes do not broadcast; it still compares shape[:-1], so this case would pass it as well.

How can the bug be reproduced?

import numpy as np
import chainladder as cl

raa = cl.load_sample("raa")
premium = raa.latest_diagonal * 0 + 20000.0
premium_tri = raa * 0 + 20000.0
for w in (premium, premium_tri):
    m = cl.BornhuetterFerguson(apriori=0.6).fit(raa, sample_weight=w)
    print(w.shape, m.ultimate_.shape, round(float(np.nansum(m.ibnr_.values)), 2))

On main ee2c24d (pandas 2.3.3, numpy 2.3.3):

(1, 1, 10, 1) (1, 1, 10, 1) 32229.96
(1, 1, 10, 10) (1, 1, 10, 10) 83931.06

What is the expected behavior?

import pytest
with pytest.raises(ValueError):
    cl.BornhuetterFerguson(apriori=0.6).fit(raa, sample_weight=premium_tri)

Suggested fix: in validate_weight, raise ValueError("sample_weight must have a single development column; pass e.g. premium.latest_diagonal") when sample_weight.shape[-1] != 1. This would sit alongside the change in #1416. DisposalRate and VotingChainladder call the same function with ultimates. With the check added, the methods, adjustments and workflow test suites pass unchanged (363 passed, as on main).

Would you be willing to contribute this ticket?

  • Yes, absolutely!
  • Yes, but I would like some help.
  • No.

(This issue was written with Árbol, an AI assistant, under my direction.)

Activity

  1. henrydingliu commented on Nov 19, 2026

    @henrydingliu
    Member

    lol, i'm actually working on tweaking disposalrate to take a full triangle as sample weight for the paid to paid method for friedland chapter 16 (p 381).

    i'm good with the fix. i can retweak disposalrate afterwards.

  2. updated Priority Medium, Scope Codebase and Effort Low on Nov 19, 2026
  3. added this to the v0.11.0 milestone on Nov 19, 2026
  4. scks1 commented on Nov 19, 2026

    @scks1
    ContributorAuthor

    Thanks. A plain shape[-1] != 1 check in validate_weight would block the full-triangle weight you're adding to DisposalRate. DisposalRate.fit and DisposalRate.transform call MethodBase().validate_weight directly at disposal.py L239 and L308. A keyword such as validate_weight(X, sample_weight, single_column=True) would let DisposalRate pass single_column=False while the methods keep the check.

    VotingChainladder goes through the same check. MethodBase.fit calls validate_weight at base.py L80, and VotingChainladder.predict calls it at voting.py L358. With the full premium triangle, its fit stops today with an error that blames TriangleSelector. With the check in place, the BF estimator inside it would raise first and name the weight.

    (1, 1, 10, 1) ultimate_ (1, 1, 10, 1)
    (1, 1, 10, 10) ValueError: Estimators returning ultimate_ of different shapes,likely due to a mis-specified TriangleSelector transformer in the pipeline
    
    Code
    import chainladder as cl
    
    raa = cl.load_sample("raa")
    premium = raa.latest_diagonal * 0 + 20000.0
    premium_tri = raa * 0 + 20000.0
    estimators = [("bf", cl.BornhuetterFerguson(apriori=0.6)), ("cl", cl.Chainladder())]
    for w in (premium, premium_tri):
        try:
            m = cl.VotingChainladder(estimators=estimators).fit(raa, sample_weight=w)
            print(w.shape, "ultimate_", m.ultimate_.shape)
        except ValueError as e:
            print(w.shape, "ValueError:", e)

    Would you rather fold the check into #1416, or leave it open for a new contributor? It comes to a few lines and one test.

    (This comment was written with Árbol, an AI assistant, under my direction.)

  5. henrydingliu commented on Nov 19, 2026

    @henrydingliu
    Member

    let's address this now. a 10x10 ultimate is a glaring bug.

  6. scks1 commented on Nov 19, 2026

    @scks1
    ContributorAuthor

    Sounds good. I can open the PR now if you want me to take it. It would add a single_column keyword to validate_weight, have DisposalRate pass False, and add one test that covers BF and VotingChainladder. Or would you rather leave it for a new contributor, given the Great First Contribution label?

    (This comment was written with Árbol, an AI assistant, under my direction.)

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

    Great First Contribution! 🌱Beginner friendly tickets with narrow scope and huge impact. Perfect to get your feet wet!

    Type

    No type

    Fields

    Priority

    Medium

    Scope

    Codebase

    Effort

    Low

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions