fair_seldonian.models package#

Submodules#

fair_seldonian.models.logistic_regression module#

fair_seldonian.models.logistic_regression.eval_ghat(
theta,
theta1,
X,
Y,
T,
seldonian_type,
config=SeldonianConfig(delta=0.05,
inequality=<Inequality.HOEFFDING_INEQUALITY: 2>,
constraint='TP(1) TP(0) - abs 0.25 TP(1) * -',
candidate_ratio=0.4,
optimizer='Powell',
max_iter=10000,
penalty=100.0),
)[source]#
Parameters:
Return type:

Bound

fair_seldonian.models.logistic_regression.f_hat(theta, theta1, X, Y)[source]#

Main objective function: negative log loss (higher is better).

Note that torch.nn.CrossEntropyLoss is the wrong tool here. It expects raw logits and applies log_softmax internally, so stacking the predicted probabilities into a two-column tensor and passing them to it computes -log softmax([1-p, p])_y - a different function, with a floor of 0.3133 for a perfect classifier and a ceiling near 1.31. That both mislabels any axis called “log loss” and compresses the range roughly tenfold, which destroys the resolution of small between-method differences.

Parameters:
  • theta (torch.Tensor | None) – The optimal theta values for the model

  • theta1 (torch.Tensor | None) – The additional optimal theta values for the model

  • X (np.ndarray) – The features of the dataset

  • Y (Array) – The true labels of the dataset

Returns:

The negative log loss

Return type:

torch.Tensor

fair_seldonian.models.logistic_regression.ghat(
theta,
theta1,
X,
Y,
T,
candidate_ratio,
seldonian_type,
config=SeldonianConfig(delta=0.05,
inequality=<Inequality.HOEFFDING_INEQUALITY: 2>,
constraint='TP(1) TP(0) - abs 0.25 TP(1) * -',
candidate_ratio=0.4,
optimizer='Powell',
max_iter=10000,
penalty=100.0),
)[source]#
Parameters:
Return type:

Bound

fair_seldonian.models.logistic_regression.predict(theta, theta1, X)[source]#

This is the predict function for Logistic Regression. Currently, it implements: 1 / (1 + e^-(X.theta + theta1))

Parameters:
  • theta (Tensor | None) – The optimal theta values for the model

  • theta1 (Tensor | None) – The additional optimal theta values for the model

  • X (ndarray) – The features of the dataset

Returns:

The probability value of label 1 of the complete dataset

Return type:

Tensor

fair_seldonian.models.logistic_regression.simple_logistic(X, Y)[source]#

Runs simple logistic regression.

Parameters:
  • X (np.ndarray) – The features of the dataset

  • Y (Array) – The true labels of the dataset

Returns:

The theta values (parameters) of the model

Return type:

tuple[torch.Tensor, torch.Tensor]

Module contents#