# aglm — Accurate Generalized Linear Model (Python)
Python port of the R package `aglm` by
Kenji Kondo, Kazuhisa Takahashi, and Hikari Banno.
> **Original paper (Hachemeister Prize 2021):**
> Fujita, Tanaka, Kondo & Iwasawa (2020).
> *AGLM: A Hybrid Modeling Method of GLM and Data Science Techniques.*
> Actuarial Colloquium Paris 2020.
>
institutdesactuaires.com
---
## What is AGLM?
AGLM is a **regularised GLM** (elastic-net) that automatically enriches the
feature space before fitting, enabling non-linear and interaction effects while
remaining fully interpretable. It is particularly popular in actuarial modelling
where explainability is a regulatory requirement.
The feature-engineering pipeline adds three types of auxiliary columns:
| Type | Variable kind | Description |
|------|--------------|-------------|
| **U-dummy** | Unordered categorical | Standard one-hot encoding (reference-cell) |
| **O-dummy** | Numeric / ordered categorical | Piecewise-linear ramp (`"C"`) or step (`"J"`) basis |
| **L-variable** | Numeric | Absolute-value spline: `\|x − knot_k\|` — better extrapolation |
These are assembled into an augmented design matrix `X̃` which is passed to
scikit-learn's elastic-net backend (Gaussian / Binomial / Poisson families).
---
## Installation
```bash
pip install -e . # editable install from source
# or
pip install aglm # once published to PyPI
```
**Dependencies:** `numpy`, `pandas`, `scikit-learn`, `matplotlib`
---
## Quick-start
```python
import pandas as pd
import numpy as np
from aglm import cv_aglm, plot_aglm
# --- 1. Prepare data -------------------------------------------------------
df = pd.read_csv("motor_claims.csv")
X = df[["age", "vehicle_age", "region", "bonus_malus"]]
y = df["claim_frequency"].values
# --- 2. Fit — lambda chosen by 10-fold CV (LASSO default) ------------------
model = cv_aglm(X, y, alpha=1.0, nfolds=10, family="poisson")
print(model)
# Accur …