Model Selection
pydts.model_selection.PenaltyGridSearch()
¤
Bases: BasePenaltyGridSearch
Source code in src/pydts/model_selection.py
TwoStagesFitter_type = 'CoxPHFitter'
instance-attribute
¤
global_auc = {}
instance-attribute
¤
global_bs = {}
instance-attribute
¤
integrated_auc = {}
instance-attribute
¤
integrated_bs = {}
instance-attribute
¤
l1_ratio = None
instance-attribute
¤
meta_models = {}
instance-attribute
¤
penalizers = []
instance-attribute
¤
seed = None
instance-attribute
¤
test_df = None
instance-attribute
¤
train_df = None
instance-attribute
¤
_get_model_fit_kwargs(penalizer, l1_ratio)
¤
Source code in src/pydts/model_selection.py
convert_results_dict_to_df(results_dict)
¤
This function converts a results dictionary to a pd.DataFrame format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
results_dict
|
one of the class attributes: global_auc, integrated_auc, global_bs, integrated_bs. |
required |
Returns:
Name | Type | Description |
---|---|---|
df |
DataFrame
|
Results in a pd.DataFrame format. |
Source code in src/pydts/model_selection.py
evaluate(train_df, test_df, l1_ratio, penalizers, metrics=['IBS', 'GBS', 'IAUC', 'GAUC'], seed=None, event_type_col='J', duration_col='X', pid_col='pid', twostages_fit_kwargs={})
¤
This function implements model estimation using train_df and evaluation of the metrics using test_df to all the possible combinations of penalizers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
train_df
|
DataFrame
|
training data for fitting the model. |
required |
test_df
|
DataFrame
|
testing data for evaluating the estimated model's performance. |
required |
l1_ratio
|
float
|
regularization ratio for the CoxPHFitter (see lifelines.fitters.coxph_fitter.CoxPHFitter documentation). |
required |
penalizers
|
list
|
penalizer options for each event (see lifelines.fitters.coxph_fitter.CoxPHFitter documentation). |
required |
metrics
|
(str, list)
|
Evaluation metrics. |
['IBS', 'GBS', 'IAUC', 'GAUC']
|
seed
|
int
|
pseudo random seed number for numpy.random.seed() |
None
|
event_type_col
|
str
|
The event type column name (must be a column in df), Right-censored sample (i) is indicated by event value 0, df.loc[i, event_type_col] = 0. |
'J'
|
duration_col
|
str
|
Last follow up time column name (must be a column in df). |
'X'
|
pid_col
|
str
|
Sample ID column name (must be a column in df). |
'pid'
|
twostages_fit_kwargs
|
dict
|
keyword arguments to pass to the TwoStagesFitter. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
output |
Tuple
|
Penalizers with best performance in terms of Global-AUC, if 'GAUC' is in metrics. |
Source code in src/pydts/model_selection.py
get_mixed_two_stages_fitter(penalizers_combination)
¤
This function creates a mixed TwoStagesFitter from the estimated meta models for a specific penalizers combination.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
penalizers_combination
|
list
|
List with length equals to the number of competing events. The penalizers value to each of the events. Each of the values must be one of the values that was previously passed to the evaluate() method. |
required |
Returns:
Name | Type | Description |
---|---|---|
mixed_two_stages |
TwoStagesFitter
|
TwoStagesFitter for the required penalty combination. |
Source code in src/pydts/model_selection.py
pydts.model_selection.PenaltyGridSearchExact()
¤
Bases: BasePenaltyGridSearch
Source code in src/pydts/model_selection.py
TwoStagesFitter_type = 'Exact'
instance-attribute
¤
global_auc = {}
instance-attribute
¤
global_bs = {}
instance-attribute
¤
integrated_auc = {}
instance-attribute
¤
integrated_bs = {}
instance-attribute
¤
l1_ratio = None
instance-attribute
¤
meta_models = {}
instance-attribute
¤
penalizers = []
instance-attribute
¤
seed = None
instance-attribute
¤
test_df = None
instance-attribute
¤
train_df = None
instance-attribute
¤
_get_model_fit_kwargs(penalizer, l1_ratio)
¤
Source code in src/pydts/model_selection.py
convert_results_dict_to_df(results_dict)
¤
This function converts a results dictionary to a pd.DataFrame format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
results_dict
|
one of the class attributes: global_auc, integrated_auc, global_bs, integrated_bs. |
required |
Returns:
Name | Type | Description |
---|---|---|
df |
DataFrame
|
Results in a pd.DataFrame format. |
Source code in src/pydts/model_selection.py
evaluate(train_df, test_df, l1_ratio, penalizers, metrics=['IBS', 'GBS', 'IAUC', 'GAUC'], seed=None, event_type_col='J', duration_col='X', pid_col='pid', twostages_fit_kwargs={})
¤
This function implements model estimation using train_df and evaluation of the metrics using test_df to all the possible combinations of penalizers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
train_df
|
DataFrame
|
training data for fitting the model. |
required |
test_df
|
DataFrame
|
testing data for evaluating the estimated model's performance. |
required |
l1_ratio
|
float
|
regularization ratio for the CoxPHFitter (see lifelines.fitters.coxph_fitter.CoxPHFitter documentation). |
required |
penalizers
|
list
|
penalizer options for each event (see lifelines.fitters.coxph_fitter.CoxPHFitter documentation). |
required |
metrics
|
(str, list)
|
Evaluation metrics. |
['IBS', 'GBS', 'IAUC', 'GAUC']
|
seed
|
int
|
pseudo random seed number for numpy.random.seed() |
None
|
event_type_col
|
str
|
The event type column name (must be a column in df), Right-censored sample (i) is indicated by event value 0, df.loc[i, event_type_col] = 0. |
'J'
|
duration_col
|
str
|
Last follow up time column name (must be a column in df). |
'X'
|
pid_col
|
str
|
Sample ID column name (must be a column in df). |
'pid'
|
twostages_fit_kwargs
|
dict
|
keyword arguments to pass to the TwoStagesFitter. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
output |
Tuple
|
Penalizers with best performance in terms of Global-AUC, if 'GAUC' is in metrics. |
Source code in src/pydts/model_selection.py
get_mixed_two_stages_fitter(penalizers_combination)
¤
This function creates a mixed TwoStagesFitter from the estimated meta models for a specific penalizers combination.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
penalizers_combination
|
list
|
List with length equals to the number of competing events. The penalizers value to each of the events. Each of the values must be one of the values that was previously passed to the evaluate() method. |
required |
Returns:
Name | Type | Description |
---|---|---|
mixed_two_stages |
TwoStagesFitter
|
TwoStagesFitter for the required penalty combination. |