VotingChainladder#

class chainladder.VotingChainladder(estimators, *, weights=None, default_weighting=None, n_jobs=None, verbose=False)[source]#

Prediction voting chainladder method for unfitted estimators.

A voting chainladder is an ensemble meta-estimator that fits several base chainladder methods, each on the whole triangle. Then it combines the individual predictions based on a matrix of weights to form a final prediction.

Read more in the User Guide.

Added in version 0.8.0.

Parameters:
estimators: list of (str, estimator) tuples

Invoking the fit method on the VotingChainladder will fit clones of those original estimators that will be stored in the class attribute self.estimators_. An estimator can be set to 'drop' using set_params.

weights: array callable or dict, default=None

array: Numpy array of shape (index, columns, origin, n_estimators). Minimum shape required is (origin, n_estimators). Lower dimensional weight arrays will have missing dimensions repeated to match the shape of the triangle. list: List of weights where each weight is a list of length n_estimators. dict: A dictionary where the origin is mapped to a weighting tuple. Missing origin periods will be given default_weighting. callable: A callable that returns weighting tuples. None uses default_weighting.

default_weighting: tuple of shape (n_estimators, ), default=None

Default weighting to use where a weight was not provided or if weights is None. None uses a typle of all ones which is equivalent to averaging the predictions of the estimators.

n_jobs: int, default=None

The number of jobs to run in parallel for fit. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. for more details.

verbose: bool, default=False

If True, the time elapsed while fitting will be printed as it is completed.

Attributes:
estimators_: list of chainladder estimators

The collection of fitted sub-estimators as defined in estimators that are not ‘drop’.

named_estimators_: Bunch

Attribute to access any fitted sub-estimators by name.

Examples

An actuary reserving the RAA excess casualty book leans on the development-based Chainladder method for the mature accident years but shifts toward the more stable exposure-based methods in the recent, least developed years. The weights matrix has one row per accident year and one column per estimator, phasing the blend from Chainladder to BornhuetterFerguson and CapeCod.

import numpy as np

raa = cl.load_sample('RAA')
cl_ult = cl.Chainladder().fit(raa).ultimate_  # Chainladder Ultimate
apriori = cl_ult * 0 + (float(cl_ult.sum()) / 10)  # Mean Chainladder Ultimate
bcl = cl.Chainladder()
bf = cl.BornhuetterFerguson()
cc = cl.CapeCod()
estimators = [('bcl', bcl), ('bf', bf), ('cc', cc)]
weights = np.array([[0.6, 0.2, 0.2]] * 4 + [[0, 0.5, 0.5]] * 3 + [[0, 0, 1]] * 3)
vot = cl.VotingChainladder(estimators=estimators, weights=weights)
vot.fit(raa, sample_weight=apriori)
print(vot.ultimate_)
              2261
1981  18834.000000
1982  16875.500226
1983  24058.534810
1984  28542.580970
1985  28236.843134
1986  19905.317262
1987  18947.245455
1988  23106.943030
1989  20004.502125
1990  21605.832631

Building on the example above and reusing its estimators, raa and apriori, the actuary can instead blend all three methods in every accident year. Omitting weights applies default_weighting to each accident year; here Chainladder receives half of the total weight.

blended = cl.VotingChainladder(
    estimators=estimators, default_weighting=(2, 1, 1)
)
blended.fit(raa, sample_weight=apriori)
print(blended.ultimate_)
              2261
1981  18834.000000
1982  16879.886803
1983  24052.325782
1984  28502.440672
1985  28581.789739
1986  19703.210223
1987  18348.274023
1988  23483.819232
1989  17908.906366
1990  19849.185129
fit(X, y=None, sample_weight=None)[source]#

Fit the estimators.

Parameters:
XTriangle

Loss data to which the voting will be applied.

yNone

Ignored

sample_weightTriangle, default=None

Exposure to be used in the calculation. Required if any of the estimators are exposure based.

Returns:
selfobject

Fitted estimator.

fit_transform(X, y=None, sample_weight=None)[source]#

Fit and return predictions for VotingChainladder

Parameters:
XTriangle

Loss data to which the model will be applied.

yNone

Ignored

sample_weightTriangle, default=None

Exposure to be used in the calculation. Required if any of the estimators are exposure based.

Returns:
X_new: Triangle

Loss data with VotingChainladder ultimate applied

predict(X, sample_weight=None)[source]#

Predicts the voting chainladder ultimate on a new triangle X

Predicts the ultimate for each of the estimators and combines them into a single ultimate based on the weights given.

Parameters:
XTriangle

Loss data to which the model will be applied.

sample_weightTriangle, default=None

Exposure to be used in the calculation. Required if any of the estimators are exposure based.

Returns:
X_new: Triangle

Loss data with VotingChainladder ultimate applied

transform(X, sample_weight=None)[source]#

Return predictions for VotingChainladder

Parameters:
XTriangle

Loss data to which the model will be applied.

sample_weightTriangle, default=None

Exposure to be used in the calculation. Required if any of the estimators are exposure based.

Returns:
X_new: Triangle

Loss data with VotingChainladder ultimate applied

Inherited Methods

VotingChainladder.fit_predict

VotingChainladder.get_metadata_routing

Get metadata routing of this object.

VotingChainladder.get_params

Get the parameters of an estimator from the ensemble.

VotingChainladder.intersection

Given two Triangles with mismatched indices, this method aligns their indices

VotingChainladder.pipe

Apply func(self, *args, **kwargs).

VotingChainladder.set_backend

Converts triangle array_backend.

VotingChainladder.set_output

Set output container.

VotingChainladder.set_params

Set the parameters of an estimator from the ensemble.

VotingChainladder.to_json

Serializes triangle object to json format

VotingChainladder.to_pickle

Serializes triangle object to pickle.

VotingChainladder.validate_X

VotingChainladder.validate_weight