MLReserving
A machine learning-based probabilistic reserving model for (longitudinal data) insurance claims.
Installation
pip install mlreserving
Usage
"""
Simple example using the RAA dataset with MLReserving
"""
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from mlreserving import MLReserving
from sklearn.ensemble import ExtraTreesRegressor, RandomForestRegressor
from sklearn.linear_model import RidgeCV
# Load the dataset
url = "https://raw.githubusercontent.com/Techtonique/datasets/refs/heads/main/tabular/triangle/raa.csv"
df = pd.read_csv(url)
print(df.head())
print(df.tail())
models = [RidgeCV(), ExtraTreesRegressor(), RandomForestRegressor()]
# Try both factor and non-factor approaches
for use_factors in [False, True]:
print(f"\n{'='*50}")
print(f"Using {'factors' if use_factors else 'log transformations'}")
print(f"{'='*50}\n")
for mdl in models:
# Initialize the model with prediction intervals
model = MLReserving(model=mdl,
level=80, # 80% confidence level
use_factors=use_factors, # Use categorical encoding
random_state=42
)
# Fit the model
model.fit(df, origin_col="origin", development_col="development", value_col="values")
# Make predictions with intervals
result = model.predict()
ibnr = model.get_ibnr()
print("\nMean predictions:")
print(result.mean)
print("\nIBNR per origin year (mean):")
print(ibnr.mean)
print("\nLower bound (95%):")
print(result.lower)
print("\nIBNR per origin year (lower):")
print(ibnr.lower)
print("\nUpper bound (95%):")
print(result.upper)
print("\nIBNR per origin year (upper):")
print(ibnr.upper)
print("\n Summary:")
print(model.get_summary())
# Display results
print("\nMean predictions:")
result.mean.plot()
plt.title(f'Mean Predictions - {mdl.__class__.__name__} ({use_factors and "Factors" or "Log"})')
plt.show()
print("\nLower bound (95%):")
result.lower.plot()
plt.title(f'Lower Bound - {mdl.__class__.__name__} ({use_factors and "Factors" or "Log"})')
plt.show()
print("\nUpper bound (95%):")
result.upper.plot()
plt.title(f'Upper Bound - {mdl.__class__.__name__} ({use_factors and "Factors" or "Log"})')
plt.show()
# Plot IBNR
plt.figure(figsize=(10, 6))
plt.plot(ibnr.mean.index, ibnr.mean.values, 'b-', label='Mean IBNR')
plt.fill_between(ibnr.mean.index,
ibnr.lower.values,
ibnr.upper.values,
alpha=0.2,
label='95% Confidence Interval')
plt.title(f'IBNR per Origin Year - {mdl.__class__.__name__} ({use_factors and "Factors" or "Log"})')
plt.xlabel('Origin Year')
plt.ylabel('IBNR')
plt.legend()
plt.grid(True)
plt.show()
Features
- Machine learning based reserving model
- Support for prediction intervals
- Flexible model selection
- Handles both continuous and categorical features
License
BSD Clause Clear License
Metadata
Release files for mlreserving 0.5.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mlreserving-0.5.2.tar.gz | 17.2 kB | Without provenance | Details for mlreserving-0.5.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mlreserving-0.5.2-py3-none-any.whl | Python 3 | none | any | Details for mlreserving-0.5.2-py3-none-any.whl |
Total release size: 33.2 kB
Release files / mlreserving-0.5.2.tar.gz
| Download URL | mlreserving-0.5.2.tar.gz |
|---|---|
| Size | 17.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9370d23aea8e9e0e6d56a5146ef59c935f174e570fd1fabb1de4f22f0681bfd9
|
|
BLAKE2b-256 checksum How to use checksums |
fbfff73ec18e0a93f4a8e1787b16f7b85952f91701e33f5f2425471d8a747161
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / mlreserving-0.5.2-py3-none-any.whl
| Download URL | mlreserving-0.5.2-py3-none-any.whl |
|---|---|
| Size | 16.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
93194aa234ad02bbc72cfc1272b2bb33923b0a5519b64348cc1fdf060bb27439
|
|
BLAKE2b-256 checksum How to use checksums |
f11706a9fa60eac4dbb70d6c257095aba449cd96db5ed0e49c0577493d939012
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for mlreserving 0.5.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.