MCPcopy Create free account
hub / github.com/AIRMEC/HECTOR / prepare_datasets

Function prepare_datasets

train.py:265–302  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

263 writer.close()
264
265def prepare_datasets(args):
266
267 df = pd.read_csv(args.manifest)
268
269 n_bins = len(df['disc_label'].unique())
270 assert n_bins == args.n_bins, 'mismatch between the number of bins passed in args and classes in dataset'
271 bins_values = get_bins_time_value(df, n_bins, time_col_name='recurrence_years', label_time_col_name='disc_label')
272 assert len(bins_values)==n_bins
273 print(f'Read {args.manifest} dataset containing {len(df)} samples with {n_bins} bins of following values {bins_values}')
274
275 # NOTE: you may need to use the two lines below depending on how the category is listed in the csv file.
276 #df.stage = df.stage.apply(lambda x : 'III' if 'III' in x else ('II' if 'II' in x else 'I')).astype("category")
277 #df.stage = pd.Categorical(df['stage'], categories=['I', 'II', 'III'], ordered=True).codes
278 print(f'stage taxonomy used: {df.stage.unique()}')
279
280 try:
281 training_set = df[df["split"] == "training"]
282 validation_set = df[df["split"] == "validation"]
283 except:
284 raise Exception(
285 f"Could not find training and validation splits in {args.manifest}"
286 )
287
288 train_split = FeatureBagsDataset(df=training_set,
289 data_dir=args.data_dir,
290 input_feature_size=args.input_feature_size,
291 stage_class=len(training_set.stage.unique()))
292
293 val_split = FeatureBagsDataset(df=validation_set,
294 data_dir=args.data_dir,
295 input_feature_size=args.input_feature_size,
296 stage_class=len(validation_set.stage.unique()))
297
298 # To compute the Brier score (BS), you need a specific format of censorship and times.
299 _, train_BS = get_survival_data_for_BS(training_set, time_col_name='recurrence_years')
300 _, test_BS = get_survival_data_for_BS(validation_set, time_col_name='recurrence_years')
301
302 return train_split, val_split, train_BS, test_BS, bins_values, len(df.stage.unique())
303
304
305def main(args):

Callers 1

mainFunction · 0.85

Calls 3

get_bins_time_valueFunction · 0.85
FeatureBagsDatasetClass · 0.85
get_survival_data_for_BSFunction · 0.85

Tested by

no test coverage detected