GLM Model Classes¶
Direct GLM model access outside of Polars expressions.
Common Interface¶
from polars_statistics import Logistic, Poisson, NegativeBinomial, Tweedie, Probit, Cloglog
model = Logistic(with_intercept=True)
model.fit(X, y)
# Properties
model.coefficients # np.ndarray
model.intercept # float or None
model.deviance # float
model.null_deviance # float
model.aic # float
model.bic # float
# Predict
predictions = model.predict(X_new)
probs = model.predict_proba(X_new) # For classification models
Logistic¶
Logistic regression for binary classification.
from polars_statistics import Logistic
model = Logistic(
lambda_: float = 0.0, # L2 regularization
with_intercept: bool = True,
)
model.fit(X, y) # y: binary (0/1)
predictions = model.predict(X_new) # Class predictions
probabilities = model.predict_proba(X_new) # Probability estimates
Poisson¶
Poisson regression for count data.
from polars_statistics import Poisson
model = Poisson(
lambda_: float = 0.0,
with_intercept: bool = True,
)
model.fit(X, y) # y: non-negative counts
NegativeBinomial¶
Negative Binomial regression for overdispersed count data.
from polars_statistics import NegativeBinomial
model = NegativeBinomial(
theta: float | None = None, # Dispersion; None = estimate
estimate_theta: bool = True,
lambda_: float = 0.0,
with_intercept: bool = True,
)
model.fit(X, y)
# Additional property
model.theta # Estimated dispersion parameter
Tweedie¶
Tweedie GLM for flexible variance structures.
from polars_statistics import Tweedie
model = Tweedie(
var_power: float = 1.5,
lambda_: float = 0.0,
with_intercept: bool = True,
)
model.fit(X, y)
Probit¶
Probit regression for binary classification.
from polars_statistics import Probit
model = Probit(
lambda_: float = 0.0,
with_intercept: bool = True,
)
model.fit(X, y) # y: binary (0/1)
Cloglog¶
Complementary log-log regression for binary classification.
from polars_statistics import Cloglog
model = Cloglog(
lambda_: float = 0.0,
with_intercept: bool = True,
)
model.fit(X, y) # y: binary (0/1)
Class Summary¶
| Class | Parameters |
|---|---|
Logistic |
lambda_, with_intercept |
Poisson |
lambda_, with_intercept |
NegativeBinomial |
theta, estimate_theta, lambda_, with_intercept |
Tweedie |
var_power, lambda_, with_intercept |
Probit |
lambda_, with_intercept |
Cloglog |
lambda_, with_intercept |