pyuoi.utils

Utility functions for the pyuoi package.

Scoring Utilities

pyuoi.utils.AIC(ll, n_features)[source]

Calculates the Akaike Information Criterion.

Parameters
  • ll (float) – The log-likelihood of the model.

  • n_features (int) – The number of features used in the model.

  • n_samples (int) – The number of samples in the dataset being tested.

Returns

AIC – Akaike Information Criterion

Return type

float

pyuoi.utils.AICc(ll, n_features, n_samples)[source]

Calculate the corrected Akaike Information Criterion. This criterion is useful in cases when the number of samples is small.

If the number of features is equal to the number of samples plus one, then the AIC is returned (the AICc is undefined in this case).

Parameters
  • ll (float) – The log-likelihood of the model.

  • n_features (int) – The number of features used in the model.

  • n_samples (int) – The number of samples in the dataset being tested.

Returns

AIC – Akaike Information Criterion

Return type

float

pyuoi.utils.BIC(ll, n_features, n_samples)[source]

Calculates the Bayesian Information Criterion.

Parameters
  • ll (float) – The log-likelihood of the model.

  • n_features (int) – The number of features used in the model.

  • n_samples (int) – The number of samples in the dataset being tested.

Returns

BIC – Bayesian Information Criterion

Return type

float

pyuoi.utils.log_likelihood_glm(model, y_true, y_pred)[source]

Calculates the log-likelihood of a generalized linear model given the true response variables and the “predicted” response variables. The “predicted” response variable varies by the specific generalized linear model under consideration.

Parameters
  • model (string) – The generalized linear model to calculate the log-likelihood for.

  • y_true (nd-array, shape (n_samples,)) – Array of true response values.

  • y_pred (nd-array, shape (n_samples,)) – Array of predicted response values (conditional mean).

Returns

ll – The log-likelihood.

Return type

float

Other Utilities

pyuoi.utils.sigmoid(x)[source]

Calculates the bernoulli distribution.

Parameters

x (ndarray) – Log-probabilities.

pyuoi.utils.softmax(y, axis=- 1)[source]

Calculates the softmax distribution.

Parameters

y (ndarray) – Log-probabilities.