zepid.superlearner.estimators.GLMSL

class zepid.superlearner.estimators.GLMSL(family, verbose=False)

Generalized Linear Model for use with SuperLearner. This function is a wrapper function for the statsmodels GLM class. This is because the GLM implementation in statsmodels is not natively compatible with the sklearn / SuperLearner class. Compatible with all options available in the statsmodels families.

Parameters:
  • family (statsmodels.families.family) – Family to use for the model. All statsmodels supported families are also supported
  • verbose (bool, optional) –

Examples

Setup the environment and data set

>>> import statsmodels.api as sm
>>> from zepid import load_sample_data
>>> from zepid.superlearner import GLMSL
>>> df = load_sample_data(False).dropna()
>>> X = np.asarray(df[['art', 'male', 'age0']])
>>> y = np.asarray(df['dead'])

GLMSL example (logit model)

>>> f = sm.families.family.Binomial()
>>> glm = GLMSL(family=f)
>>> glm.fit(X, y)

Methods

fit(X, y) Estimate the GLM
predict(X) Predict using the fitted GLM.
fit(X, y)

Estimate the GLM

Parameters:
  • X (numpy.array) – Training data
  • y (numpy.array) – Target values
Returns:

Return type:

None

get_params(deep=True)

For sklearn.base.clone() compatibility

predict(X)

Predict using the fitted GLM.

Parameters:X (numpy.array) – Samples following the same pattern as the X array input into the fit() statement.
Returns:
Return type:Returns predicted values from the GLM
set_params(**parameters)

For sklearn.base.clone() compatibility