PredictionStacking
PredictionStacking
The function calculates the final PD based on the models obtained with a stacking scheme.
Parameters:
- models_dict:
dict
A dictionary with LogitModel instances. - x_data:
pd.DataFrame
A pandas DataFrame with data of clients to calculate PD. - model:
ModelStacking
A Logistic Regression model obtained using theModelStackingfunction. - logprob:
bool
An indicator to calculate the logarithm of probabilities.
Returns:
- pred:
pd.Series
A predicted PD for a client usingx_dataand the stacking model.
Exceptions:
- TypeError:
Raised ifmodels_dictis not a dictionary
Raised ifx_datais not a pandas DataFrame object
Raised if themodelparameter is not a Logistic Regression object
Raised iflogprobis not logical
Example:
from combat.combat import PredictionStacking
import pandas as pd
# Sample input data
models_dict = {1: model1 # LogitModel instance
, 2: model2 # LogitModel instance
, 3: model3 # LogitModel instance
}
x_data = your_data
stacked_model = your_stacked_model
# Calculate the final PD using stacking
final_pd = PredictionStacking(models_dict, x_data, stacked_model, logprob=False)
print("Final PD:", final_pd)