Skip to Content
OchreML
Linear, GLM & Linear SVM

PoissonRegressor

Generalized Linear Model with a Poisson distribution and log link for non-negative count and rate regression.

Overview

PoissonRegressor fits an L2-regularized Generalized Linear Model (GLM) with a Poisson target distribution and log link function, predicting strictly positive expectations y_hat = exp(X @ w + b). It is equivalent to TweedieRegressor(power=1.0, link="log") and minimizes L2-penalized Poisson deviance using hardware-accelerated L-BFGS.

Target values y must be non-negative (y >= 0).

When to Use

  • Modeling non-negative count data (event counts, clicks, insurance claim frequencies, incident arrivals) where variance scales proportionally with the mean.
  • Rate modeling when paired with sample_weight representing exposure time or population size.

Hardware Backend Support

BackendPrimitives UsedSupport
CPU (Rayon)Dense E1-E5, N2 (f64)Full (default fallback)
CUDA (cuda:0, cuda:all)cuBLAS FP64 matvec & L-BFGS gradients (E1-E5, N2)Full
wgpu (wgpu)WGSL compute shaders (E1-E5, N2)Full
TPU (tpu:0)OpenXLA PJRT (E1-E5, N2)Full

Import & Constructor

from ochreml.glm import PoissonRegressor
# also available via:
from ochreml.linear_model import PoissonRegressor
from ochreml import PoissonRegressor

model = PoissonRegressor(
    alpha: float = 1.0,
    fit_intercept: bool = True,
    max_iter: int = 100,
    tol: float = 1e-4,
    device: str | None = None,
)

Parameters

ParameterTypeDefaultDescription
alphafloat1.0Constant multiplying the L2 regularization penalty. Must be >= 0.0.
fit_interceptboolTrueWhether to add an unpenalized intercept to the linear predictor.
max_iterint100Maximum number of L-BFGS solver iterations.
tolfloat1e-4Stopping tolerance for the L-BFGS solver.
devicestr | NoneNoneTarget compute device ("auto", "cpu", "cuda:0", "wgpu", "tpu:0"). Defaults to ochreml.get_default_device().

Attributes

AttributeTypeDescription
coef_ndarray of shape (n_features,)Estimated coefficients for the linear predictor X @ w + b.
intercept_floatIntercept added to the linear predictor.
n_iter_intActual number of L-BFGS iterations used.
n_features_in_intNumber of features seen during fit.
device_strResolved hardware device string used by the estimator.

Methods

MethodSignatureDescription
fitfit(X, y, sample_weight=None) -> selfFit Poisson GLM on non-negative target counts/rates y.
predictpredict(X) -> ndarrayPredict positive expected values exp(X @ coef_ + intercept_).
scorescore(X, y, sample_weight=None) -> floatReturn the D^2 fraction of Poisson deviance explained.
toto(device: str) -> selfMove the estimator execution target to another hardware device.
save / loadmodel.save(path) / PoissonRegressor.load(path, device=None)Persist or restore the model in OchreML's binary .dit format.

Usage Example

import numpy as np
import ochreml
from ochreml.glm import PoissonRegressor

rng = np.random.default_rng(7)
X = rng.standard_normal((400, 3))
lam = np.exp(0.6 * X[:, 0] - 0.4 * X[:, 1] + 0.3 * X[:, 2] + 0.5)
y = rng.poisson(lam).astype(np.float64)

model = PoissonRegressor(alpha=0.1, max_iter=200, device="auto")
model.fit(X, y)

preds = model.predict(X[:5])
print(f"Poisson D^2 score: {model.score(X, y):.4f}, coef_: {model.coef_.round(3)}")

# Persist to .dit and reload
model.save("poisson_glm.dit")
loaded = ochreml.load("poisson_glm.dit", device="cpu")
assert np.allclose(preds, loaded.predict(X[:5]))

On this page