chainladder.VotingChainladder

chainladder.VotingChainladder#

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

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.

New 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.

Examples

>>> import numpy as np
>>> import chainladder as cl
>>> 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_)
                  2262
    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
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.

Methods

fit(X[, y, sample_weight])

Fit the estimators.

fit_transform(X[, y, sample_weight])

Fit and return predictions for VotingChainladder

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get the parameters of an estimator from the ensemble.

intersection(a, b)

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

predict(X[, sample_weight])

Predicts the voting chainladder ultimate on a new triangle X

set_backend(backend[, inplace, deep])

Converts triangle array_backend.

set_fit_request(*[, sample_weight])

Request metadata passed to the fit method.

set_output(*[, transform])

Set output container.

set_params(**params)

Set the parameters of an estimator from the ensemble.

set_predict_request(*[, sample_weight])

Request metadata passed to the predict method.

set_transform_request(*[, sample_weight])

Request metadata passed to the transform method.

to_json()

Serializes triangle object to json format

to_pickle(path[, protocol])

Serializes triangle object to pickle.

transform(X[, sample_weight])

Return predictions for VotingChainladder

fit_predict

pipe

validate_X

validate_weight