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

fit(X, y[, offset, test_idx])

Fit logistic regression model.

get_llf(X, y, params[, offset])

Get log-likelihood at fitted parameters.

predict(X, params[, offset])

Predict probabilities using fitted model.

Attributes

LogisticRegression.maxiter: int = 100
LogisticRegression.optimizer: str = 'BFGS'
LogisticRegression.skip_stats: bool = False
LogisticRegression.tol: float = 1e-06

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:

dict

Returns:

Dictionary containing:

  • coef: Parameter estimates

  • llf: Log-likelihood at fitted parameters

  • se: Standard errors (None if skip_stats=True)

  • stat: Test statistics (None if skip_stats=True)

  • pval: P-values (None if skip_stats=True)

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.

Parameters:
  • X (Array) – Design matrix of shape (n_samples, n_features).

  • y (Array) – Response vector of shape (n_samples,).

  • params (Array) – Parameter estimates.

  • offset (Array | None (default: None)) – Offset term to include in the model.

Return type:

float

Returns:

float Log-likelihood value.

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.