Skip to main content

pyIBLM

Interpretable Boosted Linear Models

PyPI version Python versions License: MIT Downloads


Overview

pyIBLM implements Interpretable Boosted Linear Models — a hybrid modelling approach that combines the transparency of Generalized Linear Models (GLMs) with the predictive power of gradient boosting.

The model is a two-stage ensemble:

  1. A GLM is fitted on the training data, producing interpretable coefficient estimates.
  2. An XGBoost booster is trained on the GLM residuals, using the GLM's linear predictor as its base margin — learning only what the GLM could not capture.

Depending on the link function, the two components are combined as:

  • Multiplicative (log-link families: Poisson, Gamma, Tweedie): prediction = GLM prediction × Booster correction
  • Additive (identity-link families: Gaussian): prediction = GLM prediction + Booster correction

SHAP values decompose the booster correction back onto the original GLM feature scale, making the full model auditable and interpretable at the individual prediction level.

The package provides:

  • Fitting of IBLM models across Poisson, Quasi-Poisson, Gamma, Tweedie, and Gaussian families
  • SHAP-based explainability tools with beta coefficient visualisations
  • Model comparison via pinball scores and correction corridor plots
  • Bundled insurance pricing datasets (freMTPLmini, freMTPL2freq)

An equivalent R package is available on CRAN: 🔗 https://CRAN.R-project.org/package=IBLM


Installation

Install the released version from PyPI:

pip install pyiblm

To use load_freMTPL2freq() (downloads the full French MTPL dataset), install with the optional data dependency:

pip install "pyiblm[data]"

Quick start

import numpy as np
from iblm import (
    load_freMTPLmini,
    split_into_train_validate_test,
    IBLM,
    ExplainIBLM,
    get_pinball_scores,
)

# Load and prepare data
df = load_freMTPLmini()
df["LogExposure"] = np.log(df["Exposure"])
df = df.drop(columns=["Exposure"])

df_dict = split_into_train_validate_test(df, seed=9000)

# Fit model
model = IBLM()
model.fit(
    df_dict,
    response_var="ClaimNb",
    offset_var="LogExposure",
    family="poisson",
)

# Evaluate
scores = get_pinball_scores(df_dict["test"], model)
print(scores)

# Explain
ex = ExplainIBLM(model, df_dict["test"])
fig = ex.beta_corrected_scatter("DrivAge", color="VehPower")
fig.show()

Documentation

For full documentation on the R implementation (functions, methods and theoretical background):

🔗 https://ifoa-adswp.github.io/IBLM/


Contributing

Contributions are welcome. To report a bug or suggest a feature, please open an issue on GitHub:

🔗 https://github.com/IFoA-ADSWP/pyIBLM/issues


Citation

If you use pyIBLM in research or teaching, please cite it as:

Gawlowski, K. and Beard, P. (2026). pyIBLM: Interpretable Boosted Linear Models. Python package version 2.0.1.


Authors


License

This package is licensed under the MIT License. See the LICENSE file for full details.

Metadata

Release files for pyiblm 2.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyiblm 2.0.2
File Size Uploaded
pyiblm-2.0.2.tar.gz 367.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyiblm 2.0.2
File Interpreter ABI Platform
pyiblm-2.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 546.7 kB

Release files / pyiblm-2.0.2.tar.gz

Download URL pyiblm-2.0.2.tar.gz
Size 367.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7b03c5ea8872a6ff25d6e793151ff8882c0369f98cee22b84e297a04cbbe7d27
BLAKE2b-256 checksum
How to use checksums
404bf3729aef8179d3a29bca88108b93d7e35d356c030a1727b60e4d92895606
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release files / pyiblm-2.0.2-py3-none-any.whl

Download URL pyiblm-2.0.2-py3-none-any.whl
Size 179.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea20ac05cd64224a83db8f412736a6b0c0052ae19cb5d4859709baaa6daacf9d
BLAKE2b-256 checksum
How to use checksums
45fb5b93edf298a739d8ae1773163472778a019dfb62769c3a6ca43a377ead53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release history Release notifications | RSS feed

This release

2.0.2 This release

2 release files

2.0.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page