Experiments

class survivors.experiments.grid.Experiments(folds=5, except_stop=False, dataset_name='NONE_NAME', mode='CV', bins_sch='')
Class receives methods, metrics and grids,

produces cross-validation experiments, stores table of results : name, params, time, metrics (by sample and mean)

Attributes

methodslist
Must have predicting methods according to metrics:

IBS - survival func IAUC - cumulative hazard func CI - occurred time CI_CENS - occurred time

methods_gridlist

Each grid is dictionary: key - param name, values - list

metricslist

Each metric is string, which must be in METRIC_DICT

is_tableboolean

Flag of calculation ending

foldsint

Quantity of cross-validate folds.

except_stopbool

Mode of ending because of exception. True - stop experiments with current method False - continue experiments

dataset_namestr

Unique name of current dataset (used for saving)

Methods

add_method : append method and its grid set_metrics : check and set list of metric name run : start experiments with data X, y get_agg_results : choose for each method aggregated params by metric and aggreg save : export table as xlsx

survivors.experiments.grid.generate_sample(X, y, folds, mode='CV')

Generate cross-validate samples with StratifiedKFold.

Parameters

XPandas dataframe

Contain input features of events.

ystructured array

Contain censuring flag and time of events.

foldsint

Quantity of cross-validate folds.

modestr

Validation scenario.

Yields

X_trainPandas dataframe

Contain input features of train sample.

y_trainarray-like

Contain censuring flag and time of train sample.

X_testPandas dataframe

Contain input features of test sample.

y_testarray-like

Contain censuring flag and time of test sample.

binsarray-like

Points of timeline.

survivors.experiments.grid.get_fit_eval_func(method, X, y, folds, metrics_names=['CI'], mode='CV', dir_path=None)

Return function, which on sample X, y apply cross-validation and calculate metrics for each fold.

Parameters

methodclass

Must have methods for fitting, predicting time, hazard and survival func

XPandas dataframe

Contain input features of events.

ystructured array

Contain censuring flag and time of events.

foldsint

Quantity of cross-validate folds.

metrics_namesTYPE, optional

DESCRIPTION. The default is [‘CI’].

modestr

Validation scenario.

dir_pathstr

Path to cache directory (for loading pretrained models).

Returns

functions

Recieve hyperparameters and return list of metrics arrays. Allow to use in ParameterGrid.

survivors.experiments.grid.get_name_file(method, params, mode, fold)

Creating a name to cache the model without considering variables independent for reproducibility.

survivors.experiments.grid.prepare_sample(X, y, train_index, test_index)

Constructing a set of bins on target variables and clipping