bbai.glm package

Module contents

class bbai.glm.LogisticRegression(fit_intercept=True, normalize=False, penalty='l2', active_classes='auto', C=None, tolerance=0.0001)

Bases: object

Implements logistic regression with regularizers fit so as to maximize performance on approximate leave-one-out cross-validation.

See https://arxiv.org/abs/2011.10218 for background on the approach.

Parameters
  • fit_intercept (bool, default=True) – Whether constant columns should be added to the feature matrix.

  • normalize (bool, default=False) – Whether to center and rescale the feature matrix columns.

  • penalty ({'l2'}, default='l2') –

    Regularization function to use

    • ’l2’ will use the function sum_i alpha |w_i|^2

  • C (float, default=None) – Inverse of regularization strength. If None, bbai will choose C so as to maximize performance on approximate leave-one-out cross-validation.

  • tolerance (float, default=0.0001) – The tolerance for the optimizer to use when deciding to stop the objective. With a lower value, the optimizer will be more stringent when deciding whether to stop searching.

Examples

>>> from sklearn.datasets import load_breast_cancer
>>> from bbai.glm import LogisticRegression
>>> X, y = load_breast_cancer(return_X_y=True)
>>> model = LogisticRegression(normalize=True).fit(X, y)
                # Defaults to use the regularizer l2 and finds the
                # hyperparameters that maximize performance on
                # approximate leave-one-out cross-validation.
>>> print(model.C_) # print out the hyperparameters
fit(X, y)

Fit the model to the training data.

get_params(deep=True)

Get parameters for this estimator.

predict(X)

Predict class labels for the given feature matrix.

predict_log_proba(X)

Predict class log probabilities for the given feature matrix.

predict_proba(X)

Predict class probabilities for the given feature matrix.

set_params(**parameters)

Set parameters for this estimator.

class bbai.glm.RidgeRegression(fit_intercept=True, normalize=False, penalty='l2', alpha=None, tolerance=0.0001)

Bases: object

Implements regularized regression with regularizers fit so as to maximize performance on leave-one-out cross-validation.

Parameters
  • fit_intercept (bool, default=True) – Whether a constant column should be added to the feature matrix.

  • normalize (bool, default=False) – Whether to center and rescale the feature matrix columns.

  • alpha (float, default=None) – Regularization strength. If None, bbai will choose alpha so as to maximize performance on leave-one-out cross-validation.

  • tolerance (float, default=0.0001) – The tolerance for the optimizer to use when deciding to stop the objective. With a lower value, the optimizer will be more stringent when deciding whether to stop searching.

Examples

>>> from sklearn.datasets import load_boston
>>> from bbai import RidgeRegression
>>> X, y = load_boston(return_X_y=True)
>>> model = RidgeRegression().fit(X, y)
                # Defaults to use the regularizer l2 and finds the
                # hyperparameters that maximize performance on
                # leave-one-out cross-validation.
>>> print(model.alpha_) # print out the hyperparameters
fit(X, y)

Fit the model to the training data.

get_params(deep=True)

Get parameters for this estimator.

predict(X)

Predict target values.

set_params(**parameters)

Set parameters for this estimator.

Stay up to date