Skip to main content

Interpretable Boosted Linear Models: GLM + XGBoost ensemble with SHAP-based interpretability

Project description

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.

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

pyiblm-2.0.2.tar.gz (367.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyiblm-2.0.2-py3-none-any.whl (179.6 kB view details)

Uploaded Python 3

File details

Details for the file pyiblm-2.0.2.tar.gz.

File metadata

  • Download URL: pyiblm-2.0.2.tar.gz
  • Upload date:
  • Size: 367.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for pyiblm-2.0.2.tar.gz
Algorithm Hash digest
SHA256 7b03c5ea8872a6ff25d6e793151ff8882c0369f98cee22b84e297a04cbbe7d27
MD5 a59f08cd75a3bc4eac9e164c0bda57a1
BLAKE2b-256 404bf3729aef8179d3a29bca88108b93d7e35d356c030a1727b60e4d92895606

See more details on using hashes here.

File details

Details for the file pyiblm-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: pyiblm-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 179.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for pyiblm-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ea20ac05cd64224a83db8f412736a6b0c0052ae19cb5d4859709baaa6daacf9d
MD5 d55a3d36c742f048423e3db213cf0592
BLAKE2b-256 45fb5b93edf298a739d8ae1773163472778a019dfb62769c3a6ca43a377ead53

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page