Quickstart¶
Five minutes to a working model.
All examples use numpy arrays; for real projects you can also use
pandas.DataFrame with named columns.
Gaussian GLM¶
A simple linear regression (ordinary least squares) is a special case of GLM:
import numpy as np
from aurora.models.glm import fit_glm
# Generate data
np.random.seed(42)
n = 200
X = np.random.randn(n, 3)
y = 1.5 + 0.8 * X[:, 0] - 1.2 * X[:, 1] + 0.3 * X[:, 2] + np.random.randn(n) * 0.5
# Fit a Gaussian GLM
result = fit_glm(X, y, family="gaussian")
# Inspect results
print(result.summary())
print(f"Deviance: {result.deviance_:.4f}")
print(f"AIC: {result.aic_:.4f}")
The family parameter defaults to "gaussian" so the call can be
shortened to:
result = fit_glm(X, y)
Poisson GLM¶
Count data with a log link (Poisson regression):
from aurora.models.glm import fit_glm
# Generate count data
np.random.seed(42)
n = 300
X = np.random.randn(n, 2)
lin_pred = 0.5 + 0.3 * X[:, 0] - 0.2 * X[:, 1]
mu = np.exp(lin_pred)
y = np.random.poisson(mu)
# Fit Poisson GLM
result = fit_glm(X, y, family="poisson")
print(f"Deviance: {result.deviance_:.4f}")
print(f"AIC: {result.aic_:.4f}")
# Predictions on new data
X_new = np.random.randn(5, 2)
y_pred = result.predict(X_new)
Basic GAM¶
Fit a smooth curve with automatic smoothing parameter selection:
from aurora.models.gam import fit_gam
# Generate data with a nonlinear trend
np.random.seed(42)
x = np.linspace(0, 2 * np.pi, 200)
y = np.sin(x) + 0.2 * np.random.randn(200)
# Fit GAM with automatic smoothing (GCV)
result = fit_gam(x, y, n_basis=15)
print(f"EDF: {result.edf:.2f}")
print(f"Lambda: {result.lambda_:.4f}")
# Predict at new points
x_new = np.linspace(0, 2 * np.pi, 50)
y_new = result.predict(x_new)
Result objects¶
Every fitting function returns a result object with a .summary() method:
Result type |
Key attributes |
Methods |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
# GLMResult example
result = fit_glm(X, y, family="gaussian")
print(result.summary()) # Formatted summary
print(result.coef_) # Coefficients (array)
print(result.intercept_) # Intercept (float or None)
print(result.deviance_) # Deviance
print(result.aic_) # AIC
print(result.bic_) # BIC
print(result.converged_) # Did IRLS converge?
# Predictions
y_pred = result.predict(X_new) # On response scale
y_link = result.predict(X_new, type="link") # On link scale
# Confidence intervals
mean, lower, upper = result.predict(X_new, interval="confidence", level=0.95)
Where to go next¶
Generalized Linear Models (GLM) – Full GLM tutorial with all families, links, and diagnostics
Generalized Additive Models (GAM) – GAM with splines, formula interface, and visualization
Generalized Additive Mixed Models (GAMM) – GAMM with random effects and covariance structures
Formula Syntax Reference – Complete formula syntax reference
Multi-Backend Support – GPU acceleration with PyTorch and JAX
Migration Guide – Migrating from statsmodels or R