Skip to main content

actuarialnam

The Actuarial Neural Additive Model (ANAM): an interpretable deep learning model for general insurance pricing, written in PyTorch.

from actuarialnam import ANAM   # pip install actuarialnam

Like a GAM, the model adds up one shape function per rating factor, plus a few selected pairwise interactions:

g(mu) = bias + f_1(x_1) + ... + f_p(x_p) + sum of selected f_jk(x_j, x_k) + offset

Each shape function is a small neural network, so it learns its shape from the data, yet every term can still be plotted and read on its own. On top of this additive structure the package adds the requirements of a pricing model:

  • Sparsity: a three-stage selection procedure keeps only the material main effects and interactions.
  • Smoothness: a roughness penalty keeps continuous effects from overfitting.
  • Monotonicity: a factor such as a bonus-malus score can be forced to only increase (or decrease), using lattice subnetworks that guarantee it everywhere, not just on the training data.
  • Exposure: an offset column, exactly as in a Poisson GLM.

It supports Poisson, gamma and Gaussian responses. This is the reference implementation of the model in Laub, Pho & Wong (2026).

Install

pip install actuarialnam

or, for the development version:

pip install "actuarialnam @ git+https://github.com/Pat-Laub/anam.git"

It needs Python 3.12 or newer.

Quickstart

The model takes the raw data frame. Continuous and categorical columns are read from the dtypes, and the standardising and encoding are stored in the model, so predict and the plots work in the original units.

from actuarialnam import ANAM

model = ANAM(
    distribution="poisson",         # log link and Poisson loss
    exposure="expo",                # log(expo) is added as an offset
    monotone={"bm": "increasing"},  # bonus-malus effect can only increase
    smoothness=1e-3,                # roughness penalty on continuous effects
)

# By default, fit() selects the main effects and interactions, then fits them.
model.fit(X_train, y_train, X_val=X_val, y_val=y_val,
          epochs=300, batch_size=5000, lr=0.01, patience=40, random_state=2000)

model.features_, model.interactions_   # the selected terms
model.predict(X_test)                  # expected claim counts, exposure included

Choosing the terms yourself

Rather than trusting the automatic cutoffs, you can look at the rankings and then decide:

model.rank_main_effects(X_train, y_train, X_val=X_val, y_val=y_val, random_state=2000)
model.plot_main_effect_importance()

model.rank_interactions(X_train, y_train, X_val=X_val, y_val=y_val,
                        n_main=7, random_state=2000)
model.plot_interaction_importance()

model.choose(n_main=7, n_interactions=6)
model.fit(X_train, y_train, X_val=X_val, y_val=y_val,
          epochs=300, batch_size=5000, lr=0.01, patience=40, random_state=2000)
  • rank_main_effects trains an ensemble of small main-effect models and scores each factor by how much its shape function varies over the data.
  • rank_interactions scores each pair of kept main effects by how much it improves the validation loss.
  • choose fixes the cutoffs, and fit then trains the chosen terms with the smoothness and monotonicity constraints.

Reading the model

Each shape function is a contribution to the linear predictor. Under a log link, exp(f_j) is a multiplier on the expected claim count.

model.plot_effects(["ageph", "bm", "power"])   # several main effects
model.plot_effect("fuel")                      # a categorical factor, one bar per level
model.plot_effect("long", "lat")               # an interaction surface
grid, values = model.effect("bm")              # the numbers behind a plot
model.predict_components(X_test)               # each term's contribution, per policy
model.importance()                             # variance of each term over the data

Saving and loading keeps the preprocessing:

model.save("model.pt")
model = ANAM.load("model.pt")

Categories not seen in training get zero effect.

Development

git clone https://github.com/Pat-Laub/anam.git
cd anam
uv run pytest

Citation

@article{laub2026anam,
  title   = {An interpretable deep learning model for general insurance pricing},
  author  = {Laub, Patrick J. and Pho, Tu and Wong, Bernard},
  journal = {Insurance: Mathematics and Economics},
  year    = {2026},
  pages   = {103270},
  doi     = {10.1016/j.insmatheco.2026.103270},
}

License

MIT

Metadata

Release files for actuarialnam 0.3.0

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

Source distribution (sdist)

Source distribution for actuarialnam 0.3.0
File Size Uploaded Provenance Actions
actuarialnam-0.3.0.tar.gz 56.3 kB Without provenance Details for actuarialnam-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 103.8 kB

Release files / actuarialnam-0.3.0.tar.gz

Download URL actuarialnam-0.3.0.tar.gz
Size 56.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c9dc903b7f019ced939ab718aa08a16ecc158dd56e87f33a2fea0081e1796d8a
BLAKE2b-256 checksum
How to use checksums
f564e3633837ba505dd5e3d12b729a62f9ff5492b002b7a86b762aee07fba0d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / actuarialnam-0.3.0-py3-none-any.whl

Download URL actuarialnam-0.3.0-py3-none-any.whl
Size 47.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dcff6676e5e36cfafcab1c8d29451c28639d26a4438b898c500ea685a0c874be
BLAKE2b-256 checksum
How to use checksums
6b234391f20ff921d6c0118dbca14073d6bbf218eb551ff31dcdce0b4eff8b57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for actuarialnam 0.3.0

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.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files No provenance

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