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_weightrepresenting exposure time or population size.
Hardware Backend Support
| Backend | Primitives Used | Support |
|---|---|---|
| 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
| Parameter | Type | Default | Description |
|---|---|---|---|
alpha | float | 1.0 | Constant multiplying the L2 regularization penalty. Must be >= 0.0. |
fit_intercept | bool | True | Whether to add an unpenalized intercept to the linear predictor. |
max_iter | int | 100 | Maximum number of L-BFGS solver iterations. |
tol | float | 1e-4 | Stopping tolerance for the L-BFGS solver. |
device | str | None | None | Target compute device ("auto", "cpu", "cuda:0", "wgpu", "tpu:0"). Defaults to ochreml.get_default_device(). |
Attributes
| Attribute | Type | Description |
|---|---|---|
coef_ | ndarray of shape (n_features,) | Estimated coefficients for the linear predictor X @ w + b. |
intercept_ | float | Intercept added to the linear predictor. |
n_iter_ | int | Actual number of L-BFGS iterations used. |
n_features_in_ | int | Number of features seen during fit. |
device_ | str | Resolved hardware device string used by the estimator. |
Methods
| Method | Signature | Description |
|---|---|---|
fit | fit(X, y, sample_weight=None) -> self | Fit Poisson GLM on non-negative target counts/rates y. |
predict | predict(X) -> ndarray | Predict positive expected values exp(X @ coef_ + intercept_). |
score | score(X, y, sample_weight=None) -> float | Return the D^2 fraction of Poisson deviance explained. |
to | to(device: str) -> self | Move the estimator execution target to another hardware device. |
save / load | model.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]))