SelectModels
SelectModels
The function filters models from a dictionary of LogitModel instances.
Parameters:
- models_dict:
dict
A dictionary with LogitModel instances. - meta_data:
pd.DataFrame
A pandas DataFrame with meta information of all models in the dictionary. - select_by:
str, {'gini_test', 'gini_train', 'auc_test', 'auc_train', 'Brier_test', 'Brier_train', 'F1_test', 'F1_train'}, default = 'gini_test'
A metric to filter by models. - cutoff:
float, default = 0.5
A cutoff value for theselect_bymetric.
Returns:
- new_models_dict:
dict
A dictionary with selected models.
Exceptions:
-
TypeError:
Raised ifmodels_dictparameter is not a dictionary.
Raised ifmeta_dataparameter is not a pandas DataFrame. -
ValueError:
Raised if theselect_byparameter is not in ['gini_test', 'gini_train', 'auc_test', 'auc_train', 'Brier_test', 'Brier_train', 'F1_test', 'F1_train'].
Raised if the lengths ofmeta_dataandmodels_dictare not identical.
Raised if thecutoffparameter is not a positive float from 0 to 1.
Example:
import pandas as pd
from combat.utilities import SelectModels
# Sample input data
models_dict = {1: model1 # LogitModel instance
, 2: model2 # LogitModel instance
, 3: model3 # LogitModel instance
}
meta_data = pd.DataFrame({
'gini_test': [0.6, 0.7, 0.8],
'auc_test': [0.7, 0.8, 0.9],
'Brier_test': [0.2, 0.1, 0.3],
'F1_test': [0.5, 0.6, 0.7]
})
select_by = 'gini_test'
cutoff = 0.6
# Select models
final_models = SelectModels(models_dict, meta_data, select_by, cutoff)