Skip to content

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 the select_by metric.

Returns:

  • new_models_dict: dict
    A dictionary with selected models.

Exceptions:

  • TypeError:
    Raised if models_dict parameter is not a dictionary.
    Raised if meta_data parameter is not a pandas DataFrame.

  • ValueError:
    Raised if the select_by parameter is not in ['gini_test', 'gini_train', 'auc_test', 'auc_train', 'Brier_test', 'Brier_train', 'F1_test', 'F1_train'].
    Raised if the lengths of meta_data and models_dict are not identical.
    Raised if the cutoff parameter 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)