Skip to content

PredictionBagging

PredictionAggregation

The function calculates the PD using an aggregation scheme. For each model in the ensemble, the corresponding weight is assigned.

Parameters:

  • models_dict: dict
    A dictionary with LogitModel instances.
  • weights_dict: dict
    A dictionary with weights for each model in the models_dict dictionary. The keys of both models_dict and weights_dict must be the same.
  • x_data: pd.DataFrame
    A pandas DataFrame with the explanatory variables to predict the PD.
  • logprob: bool, default = False
    An indicator of whether to calculate the logarithm of probabilities.

Output:

  • pred: pd.DataFrame
    A pandas DataFrame with clients' PDs.

Expcetions

  • ValueError:
    Raised if the keys of models_dict and weights_dict are not the same

  • TypeError:
    Raised if models_dict is not a dictionary

Example:

from combat.combat import PredictionAggregation
from combat.models import LogitModel

# Sample input data
models_dict = {1: model1 # LogitModel instance
              , 2: model2 # LogitModel instance
              , 3: model3 # LogitModel instance
              }
weights_dict = {1: 0.2, 2: 0.5, 3: 0.3}
x_data = your_data

# Calculate aggregated predictions
predictions = PredictionAggregation(models_dict, weights_dict, x_data, logprob=False)
print("Aggregated predictions:", predictions)