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 ifcheck_sampleis not in [train,test] Raised ifmetricis not in [gini,auc,f1,brier] -
TypeError:
Raised ifmodels_dictis 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)