Skip to content

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 the ModelStacking function.
  • logprob: bool
    An indicator to calculate the logarithm of probabilities.

Returns:

  • pred: pd.Series
    A predicted PD for a client using x_data and the stacking model.

Exceptions:

  • TypeError:
    Raised if models_dict is not a dictionary
    Raised if x_data is not a pandas DataFrame object
    Raised if the model parameter is not a Logistic Regression object
    Raised if logprob is 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)