delnx.models.LogisticRegression¶
- class delnx.models.LogisticRegression(maxiter=100, tol=1e-06, optimizer='BFGS', skip_stats=False)[source]¶
Logistic regression in JAX.
This class implements logistic regression for binary classification tasks with support for offset terms. Offsets are added to the linear predictor before applying the logistic function.
- Parameters:
maxiter (
int(default:100)) – Maximum number of iterations for optimization algorithms.tol (
float(default:1e-06)) – Convergence tolerance for optimization algorithms.optimizer (
str(default:'BFGS')) – Optimization method to use. Options are “BFGS” or “IRLS” (recommended).skip_stats (
bool(default:False)) – Whether to skip calculating test statistics.
Examples
>>> import jax.numpy as jnp >>> from delnx.models import LogisticRegression >>> X = jnp.array([[1.0, 0.5], [1.0, 1.5], [1.0, 2.5]]) # Design matrix with intercept >>> y = jnp.array([0.0, 0.0, 1.0]) # Binary outcome >>> model = LogisticRegression(optimizer="IRLS") >>> result = model.fit(X, y) >>> print(f"Coefficients: {result['coef']}")
Attributes table¶
Methods table¶
Attributes¶
Methods¶
- LogisticRegression.fit(X, y, offset=None, test_idx=-1)[source]¶
Fit logistic regression model.
- Parameters:
X (
Array) – Design matrix of shape (n_samples, n_features).y (
Array) – Binary response vector of shape (n_samples,).offset (
Array|None(default:None)) – Offset term to include in the model. If provided, overrides the offset set during class initialization.
- Return type:
- Returns:
Dictionary containing:
- LogisticRegression.get_llf(X, y, params, offset=None)¶
Get log-likelihood at fitted parameters.
This method converts the negative log-likelihood to a log-likelihood value, which is useful for model comparison and likelihood ratio tests.
- LogisticRegression.predict(X, params, offset=None)[source]¶
Predict probabilities using fitted model.
- Parameters:
X (
Array) – Design matrix of shape (n_samples, n_features).params (
Array) – Fitted parameter estimates.offset (
Array|None(default:None)) – Offset term to include in the prediction. If provided, overrides the offset set during class initialization.
- Return type:
Array- Returns:
jnp.ndarray Predicted probabilities of the positive class.