peal.data.dataset_utils.parse_csv¶
- peal.data.dataset_utils.parse_csv(data_dir, config, mode, key_type='idx', set_negative_to_zero=True, delimiter=',', raw_data=None)[source]¶
Parse a csv label table into per-sample tensors and the keys of one split.
The first row is the header (a leading row with fewer than two fields, e.g. a sample count, is skipped). Every other row is converted to a float tensor; fields that are not valid floats become
-1.0. Three selection mechanisms follow, in order:If
config.confounding_factorshas two entries and a confounder probability orfull_confounder_configis set, rows are subsampled byprocess_confounder_data_controlled.Otherwise all rows are kept (rows with
has_mask != 1are dropped whenconfig.has_hints) and split either byconfig.splitfractions after a seeded shuffle, or, ifsplithas not exactly two entries, by asplitcolumn holding 0/1/2 for train/val/test.If
config.spray_label_fileis set, itsSprayLabelcolumn overwrites the confounder column; samples whose spray label is not 0 or 1 are dropped, and withconfig.spray_groups_balancedthe four (target, confounder) groups are truncated to the smallest group size.
- Parameters:
data_dir (
str) – Path of the csv file (ignored whenraw_datais given).config (
DataConfig) – Usesx_selection,confounding_factors,confounder_probability,full_confounder_config,has_hints,split,spray_label_fileandspray_groups_balanced.mode (
str) –"train","val"or"test"; any other value keeps all keys.key_type (
str, optional) –"idx"keys samples by row number;"name"keys them by the column namedconfig.x_selection(or column 0) and drops that and all preceding columns from the tensor and fromattributes.set_negative_to_zero (
bool, optional) – Clamp negative values to zero.delimiter (
str, optional) – Field separator.raw_data (
listofstr, optional) – Already-read lines to use instead of openingdata_dir.
- Returns: