Skip to content

Commit

Permalink
prep 0.8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jbogaardt committed Mar 27, 2021
1 parent a8734d9 commit f56c839
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 14 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ Available Estimators
+------------------------------+------------------+-------------------------+-----------------------+-----------------------+
| `DevelopmentML`_ | | | | |
+------------------------------+------------------+-------------------------+-----------------------+-----------------------+
| `BarnettZehnwirth`_ | | | | |
+------------------------------+------------------+-------------------------+-----------------------+-----------------------+

Documentation
-------------
Expand Down Expand Up @@ -91,6 +93,7 @@ code documentation.
.. _CaseOutstanding: https://chainladder-python.readthedocs.io/en/latest/modules/development.html#caseoutstanding
.. _TweedieGLM: https://chainladder-python.readthedocs.io/en/latest/modules/development.html#tweedieglm
.. _DevelopmentML: https://chainladder-python.readthedocs.io/en/latest/modules/development.html#developmentml
.. _BarnettZehnwirth: https://chainladder-python.readthedocs.io/en/latest/modules/development.html#barnettzehnwirth
.. _Documentation: https://chainladder-python.readthedocs.io/en/latest/

Getting Started Tutorials
Expand Down
18 changes: 12 additions & 6 deletions chainladder/core/triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,21 +331,23 @@ def dev_to_val(self, inplace=False):
else:
return self.copy()
is_cumulative = self.is_cumulative
if self.is_ultimate:
if self.is_full:
if is_cumulative:
obj = self.cum_to_incr(inplace=inplace)
else:
obj = self.copy()
ultimate = obj.iloc[..., -1:]
obj = obj.iloc[..., :-1]
if self.is_ultimate:
ultimate = obj.iloc[..., -1:]
obj = obj.iloc[..., :-1]
else:
obj = self
obj = obj._val_dev(1, inplace)
ddims = obj.valuation[obj.valuation <= obj.valuation_date]
obj.ddims = ddims.drop_duplicates().sort_values()
if self.is_ultimate:
ultimate.ddims = pd.DatetimeIndex(ultimate.valuation[0:1])
obj = concat((obj, ultimate), -1)
if self.is_full:
if self.is_ultimate:
ultimate.ddims = pd.DatetimeIndex(ultimate.valuation[0:1])
obj = concat((obj, ultimate), -1)
if is_cumulative:
obj = obj.incr_to_cum(inplace=inplace)
return obj
Expand Down Expand Up @@ -427,6 +429,10 @@ def grain(self, grain="", trailing=False, inplace=False):
)
if valid["M"].index(ograin_new) > valid["M"].index(dgrain_new):
raise ValueError("Origin grain must be coarser than development grain")
if self.is_full and not self.is_ultimate and not self.is_val_tri:
warnings.warn('Triangle includes extraneous development lags')
else:
d_limit = None
obj = self.dev_to_val()
if ograin_new != ograin_old:
if trailing:
Expand Down
2 changes: 1 addition & 1 deletion chainladder/development/barnzehn.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def fit(self, X, y=None, sample_weight=None):
response = X.columns[0] if not self.response else self.response
self.model_ = DevelopmentML(Pipeline(steps=[
('design_matrix', PatsyFormula(self.formula)),
('model', LinearRegression(fit_intercept=True))]),
('model', LinearRegression(fit_intercept=False))]),
y_ml=response, fit_incrementals=False).fit(tri)
resid = tri - self.model_.triangle_ml_[
self.model_.triangle_ml_.valuation <= tri.valuation_date]
Expand Down
5 changes: 3 additions & 2 deletions chainladder/development/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,9 @@ def fit(self, X, y=None, sample_weight=None):
self.sigma_ = self._param_property(X, params, 1)
self.std_err_ = self._param_property(X, params, 2)

resid = -X.iloc[..., :-1]*self.ldf_.values+X.iloc[..., 1:].values
std = xp.sqrt((1/w)*(self.sigma_**2).values)
resid = -X.iloc[..., :-1] * self.ldf_.values + X.iloc[..., 1:].values

std = xp.sqrt((1/num_to_nan(w))*(self.sigma_**2).values)
resid = resid/std
self.std_residuals_ = resid[resid.valuation < X.valuation_date]
return self
Expand Down
3 changes: 2 additions & 1 deletion chainladder/development/learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ def transform(self, X):
X_ml = self._prep_X_ml(X)
y_ml=self.estimator_ml.predict(X_ml)
triangle_ml = self._get_triangle_ml(X_ml, y_ml)
X_new.ldf_ = triangle_ml.incr_to_cum().link_ratio
backend = "cupy" if X.array_backend == "cupy" else "numpy"
X_new.ldf_ = triangle_ml.incr_to_cum().link_ratio.set_backend(backend)
X_new.ldf_.valuation_date = pd.to_datetime(ULT_VAL)
X_new._set_slicers()
return X_new
4 changes: 3 additions & 1 deletion chainladder/development/outstanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def fit(self, X, y=None, sample_weight=None):
self : object
Returns the instance itself.
"""
backend = "cupy" if X.array_backend == "cupy" else "numpy"
self.X_ = X.copy()
paid_tri = self.X_[self.paid_to_incurred[0]]
incurred_tri = self.X_[self.paid_to_incurred[1]]
Expand Down Expand Up @@ -104,7 +105,8 @@ def fit(self, X, y=None, sample_weight=None):
dev.ddims = self.X_.link_ratio.ddims
dev.is_pattern=True
dev.is_cumulative=True
self.ldf_ = dev.cum_to_incr()

self.ldf_ = dev.cum_to_incr().set_backend(backend)
return self

@property
Expand Down
2 changes: 1 addition & 1 deletion chainladder/methods/mack.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def _mack_recursion(self, est, X=None):
extend = X.ldf_.shape[-1] - X.shape[-1] + 1
ldf = X.ldf_.values[..., : len(X.ddims) - 1]
tail = X.cdf_.values[..., -extend : -extend + 1]
ldf = X.ldf_.get_array_module().concatenate((ldf, tail), -1)
ldf = xp.array(X.ldf_.get_array_module().concatenate((ldf, tail), -1))
# Recursive Mack Formula
for i in range(t1_t.shape[-1]):
t1 = t1_t[..., i : i + 1] ** 2
Expand Down
4 changes: 2 additions & 2 deletions chainladder/utils/weighted_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

class WeightedRegression(BaseEstimator):
""" Helper class that fits a system of regression equations
simultaneously on a multi-dimensional array. Look into
SUR as a replacement.
as a closed-form solution. This greatly speeds up
the implementation of the Mack stochastic properties.
"""

def __init__(self, axis=None, thru_orig=False, xp=None):
Expand Down

0 comments on commit f56c839

Please sign in to comment.