Model-agnostic Probabilistic Machine Learning Reserving
Project description
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mlreserving-0.3.2.tar.gz
(9.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mlreserving-0.3.2.tar.gz.
File metadata
- Download URL: mlreserving-0.3.2.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
474726236b8ea1b7844ac62982d00fae7c426f2e2abe064c97fb3d2da272f6e6
|
|
| MD5 |
8b07c4ad8d41ffc61fd53bd8ae114390
|
|
| BLAKE2b-256 |
fe53eccd754520895ca30474ed666bed2fba9b62370773af8479b594920d37a1
|
File details
Details for the file mlreserving-0.3.2-py3-none-any.whl.
File metadata
- Download URL: mlreserving-0.3.2-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75711d4e9ac26586871da62031d6e20b66ed3b7b5fb08c06c11306732a5eec98
|
|
| MD5 |
104c96e55ae379bf68cdef775e65fc41
|
|
| BLAKE2b-256 |
ed6035aeffa0f510bb3ab0e67c520fa961feb7e8a42d443020907da24967cb18
|