Docs · Machine learning
pglm: Poisson generalized linear model.
Poisson regression with a log link fitted by Newton's method (iteratively reweighted least squares), the equivalent of Spark MLlib's GeneralizedLinearRegression with family poisson, link log and solver irls. Each iteration is one paged pass.
- Module
- ml_pglm
- Header
- clio_ml/poisson_glm.h
- Rows
- features, then count
What it does
The pass accumulates the weighted Hessian sum mu x x^T, the score sum (y - mu) x and the log-likelihood; the host solves the Newton step by Cholesky in double precision. A small ridge term is added to the Hessian diagonal. Bit-reproducible.
Rows
n_features feature columns followed by the count target. clio_ml.COLUMNS["pglm"] is 1.
Python
python
import numpy as np, clio_ml as cm
rng = np.random.default_rng(1)
X = rng.normal(scale=0.3, size=(4096, 7)).astype(np.float32)
y = rng.poisson(np.exp(0.5 * X[:, 0] + 0.2))
data = np.column_stack([X, y]).astype(np.float32)
r = cm.fit_pglm(data, iters=8)
print(r.coef[:7], "intercept", r.coef[7])
print(r.loglik[0], "->", r.loglik[-1])
print(cm.predict("pglm", r, data[0, :7])) # predicted mean countfit_pglm(X, **options).- Options (
PoissonGlmOptions):iters(8),ridge(1e-6, relative to N),threads(256). - Result
PoissonGlmResult:coef(n_featurescoefficients, then the intercept),loglik(meany*eta - mubefore each step),stats. predict("pglm", r, x)returns the predicted mean,exp(coef . x + intercept).
C++
cpp
struct PoissonGlmOptions {
u32 iters = 8;
float ridge = 1e-6f;
u32 threads = 256;
ClusterExchange cluster;
};
struct PoissonGlmResult {
std::vector<float> coef; // n_features coefficients, then intercept
std::vector<double> loglik;
VecStats stats;
};
PoissonGlmResult FitPoissonGlm(Dataset &ds, const PoissonGlmOptions &opt);
PoissonGlmResult FitPoissonGlmPlain(const float *data, u64 n_rows, u32 nf,
u64 elems_per_page, u32 nblocks,
const PoissonGlmOptions &opt);
PoissonGlmResult FitPoissonGlmReference(/* same arguments */);
float PoissonGlmPredict(const std::vector<float> &coef, const float *x); // meanThe ChiMod is module ml_pglm.
Related: linear regression, AFT survival regression.