-
Notifications
You must be signed in to change notification settings - Fork 71
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
Error when NaN in middle of triangle #164
Comments
Is this a good starting point for a reproducible example? import chainladder as cl
import numpy as np
raa = cl.load_sample('raa')
raa.iat[..., 3, :] = np.nan # Zero out third origin
cl.Development().fit(raa).ldf_ I works on master branch, so may not be a great starting point. Let me know. |
yes, this works correctly on latest master branch - so I'm not sure. AttributeError: 'Triangle' object has no attribute 'iat' I'm struggling to make some easy-to-replicate code, but when I drop the origin from the data before loading:
|
I've recently changed the development index starting point for development patterns (
>>> import chainladder as cl
>>> raa = cl.load_sample('raa')
>>> print(raa.link_ratio.ddims)
[ 12 24 36 48 60 72 84 96 108] Under older, but recent versions of the library, this would produce: [ 24 36 48 60 72 84 96 108 120] Why was this changed? For The new approach makes triangle arithmetic more intuitive, and ideally less error prone. For example, I can create chainladder ultimates easily without using the import chainladder as cl
raa = cl.load_sample('raa')
dev = cl.TailConstant().fit(cl.Development().fit_transform(raa))
ultimate = (raa * dev.cdf_.iloc[..., :-1]).latest_diagonal Under the old approach, I'd have to have extra lines of code to deal with development indexing. It's entirely possible that some area of the code is missed under the test suite and is still expecting the old method. I hope this helps get a reproducible example up and running. |
sounds like a meaningful improvement you're working on, thanks! Now, this is the closest I can get to replicating my workflow using sample data: import os
import chainladder as cl
origin = "origin"
development = "development"
columns = ["values"]
index = None
cumulative = True
df = pd.read_csv(os.path.join(cl.__path__[0], 'utils', 'data', 'raa.csv'))
# df.loc[df.origin==1987, 'values'] = [100000, 0, 0, 100000]
df = df.loc[~df.origin.isin([1981,1984])].copy()
start_date = pd.Period('2018-06')
df.origin = df.origin -1980 + start_date
df.origin = df.origin.astype(str)
df.development = df.development -1980 + start_date
df.development = df.development.astype(str)
raa = cl.Triangle(
df,
origin=origin,
development=development,
index=index,
columns=columns,
cumulative=cumulative)
raa_inc = cl.Chainladder().fit(raa)
raa.link_ratio.ddims
raa_inc.ldf_
raa_inc.cdf_ I do see the difference in shape of link ratio, but annoyingly the error isn't being replicated, as this produces same result for 0.8.4 and *0.8.5 Adding the last two lines of your example, these both throw errors due to the missing row of data dev = cl.TailConstant().fit(cl.Development().fit_transform(raa))
ultimate = (raa * dev.cdf_.iloc[..., :-1]).latest_diagonal This gives NaNs... raa.iat[...,2,1:7] = 0
dev = cl.TailConstant().fit(cl.Development().fit_transform(raa))
ultimate = (raa * dev.cdf_.iloc[..., :-1]).latest_diagonal This gives a different result for dp.latest_diagonal - works in 0.8.5 but NaN in 0.8.4 raa.iat[...,2,1:7] = 0
dev = cl.TailConstant().fit(cl.Development().fit_transform(raa))
dp =raa * dev.cdf_.iloc[..., :9]
dp.latest_diagonal |
Thanks for the additional info, it appears I changed the When multiplying two triangles together with different valuation dates, the library will assign the later valuation date to the resultant triangle. This is done so as to not censor resultant data beyond the valuation date of the earlier triangle. |
I think something goes wrong if an origin row is dropped from the claims data.
i.e. in a triangle, you have a single row filled with NaN.
ldf's go a bit funny.
Not sure where the bug is but something changed in the last couple of months and this has appeared.
I'll keep digging.
The text was updated successfully, but these errors were encountered: