Skip to content

ModelStacking

ModelStacking

The function creates a logistic regression model using a stacking scheme.

Parameters:

  • models_dict: dict
    A dictionary with LogitModel instances.
  • x_data: pd.DataFrame
    A pandas DataFrame with explanatory variables.
  • y_data: pd.Series
    A pandas Series with discrete dependent variable.
  • penalty: Optional[str], default = None
    A regularization for Logistic Regression model. It can be either 'None', 'l1', or 'l2'.
  • alpha: float, default = 0.5
    A float variable for the regularization.
  • fit_intercept: bool, default = True
    A boolean variable whether to fit intercept in the Logistic Regression or not.
  • logprob: bool
    An indicator to calculate the logarithm of probabilities.

Returns:

  • model: LogisticRegression
    A LogisticRegression model from the sklearn package.

Exceptions:

  • ValueError:
    Raised if the length of x_data and y_data must be identical
    Raised if the penalty is not in [None, l1, l2]

  • TypeError:
    Raised if models_dict is not a dictionary
    Raised if x_data is not a pandas DataFrame object
    Raised if y_data is not a pandas DataFrame object

Example:

from combat.combat import ModelStacking

# Sample input data
models_dict = {1: model1 # LogitModel instance
              , 2: model2 # LogitModel instance
              , 3: model3 # LogitModel instance
              }
x_data = your_data
y_data = your_labels

# Create a stacked logistic regression model
stacked_model = ModelStacking(models_dict, x_data, y_data, penalty='l1', alpha=0.5, fit_intercept=True, logprob=False)
print("Stacked model:", stacked_model)