Skip to content

WeightsBagging

ModelAggregation

The function calculates the weights of each model in the ensemble.

Parameters:

  • models_dict: dict
    Dictionary of LogitModel() instances.
  • metric: str, {'gini', 'auc', 'f1', 'brier'}
    Metric for calculating weighted average.
  • check_sample: str, {'test', 'train'}
    Sample to calculate metrics for averaging.

Returns:

  • weights_dict: dict
    A dictionary with weights for each model in the ensemble.

Exceptions:

  • ValueError:
    Raised if check_sample is not in [train, test] Raised if metric is not in [gini, auc, f1, brier]

  • TypeError:
    Raised if models_dict is not a dictionary

Example:

from combat.combat import ModelAggregation
from combat.models import LogitModel

# Sample input data
models_dict = {1: model1 # LogitModel instance
              , 2: model2 # LogitModel instance
              , 3: model3 # LogitModel instance
              }
metric = 'auc'
check_sample = 'test'

# Calculate weights for model aggregation
weights = ModelAggregation(models_dict, metric, check_sample)
print("Model weights:", weights)