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 themodels_dictdictionary. The keys of bothmodels_dictandweights_dictmust 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 ofmodels_dictandweights_dictare not the same -
TypeError:
Raised ifmodels_dictis 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)