peal.data.datasets.SymbolicDataset¶
- class peal.data.datasets.SymbolicDataset[source]¶
Bases:
PealDatasetTabular (symbolic) dataset read from
<dataset_path>/data.csv.Every row becomes a float tensor in
data[key]; by default the last column is the target and all others are inputs, unlesstask_configselects columns viax_selection/y_selection. A pandas copy of the table is kept indf(used byDiCEExplainer). The config’stabular_preprocessinglist may contain"minmax_-1_1", which scales continuous columns (more than 10 unique values, excluding targets andconfounding_factors) to[-1, 1].- Parameters:
mode (
str) – Split to load:"train","val","test"or"all".config (
DataConfig) – Data config; usesdataset_path,set_negative_to_zero,output_size,confounding_factorsandtabular_preprocessing.transform (
callable, optional) – Stored but not applied to the tensors. Defaults toToTensor().task_config (
TaskConfig, optional) – Column selection andoutput_channels.**kwargs – Ignored.
- Variables:
Methods
Stop returning
has_confounder.Clear the
hints_enabledflag.Stop returning the sample index.
Return
has_confounderin dict mode (second confounding factor).Set the
hints_enabledflag (tabular data has no hints to return).Also return the sample index from
__getitem__.Render bar-chart collages of factual vs.
Write samples as a CSV next to
output_dir.Attributes
task_config.output_channelswhen targets are selected, else config.- __init__(mode, config, transform=torchvision.transforms.ToTensor, task_config=None, **kwargs)[source]¶
Parse
data.csv, build the dataframe and apply tabular preprocessing.
- property output_size¶
task_config.output_channelswhen targets are selected, else config.
- generate_contrastive_collage(x_list, x_counterfactual_list, y_target_list, y_source_list, y_list, y_target_start_confidence_list, y_target_end_confidence_list, base_path, start_idx=0, y_original_teacher_list=None, y_counterfactual_teacher_list=None, feedback_list=None, **kwargs)[source]¶
Render bar-chart collages of factual vs. counterfactual feature vectors.
For every pair a figure with three bar charts (original, counterfactual, difference) over the feature names is written to
<base_path>/<zero-padded index>_collage.png.- Parameters:
x_list (
listoftorch.Tensor) – Factual and counterfactual feature vectors.x_counterfactual_list (
listoftorch.Tensor) – Factual and counterfactual feature vectors.y_target_list (
list) – Target class, predicted source class and ground truth per pair.y_source_list (
list) – Target class, predicted source class and ground truth per pair.y_list (
list) – Target class, predicted source class and ground truth per pair.y_target_start_confidence_list (
list) – Target-class confidence before and after the edit.y_target_end_confidence_list (
list) – Target-class confidence before and after the edit.base_path (
str) – Output directory, created if missing.start_idx (
int, optional) – Offset added to the running index in the filenames.y_original_teacher_list – Accepted for API compatibility; not drawn for tabular data.
y_counterfactual_teacher_list – Accepted for API compatibility; not drawn for tabular data.
feedback_list – Accepted for API compatibility; not drawn for tabular data.
**kwargs – Ignored.
- Returns:
(attribution_list, collage_paths)where attributions are|cf - x|tensors and paths are the written PNG files.- Return type:
- serialize_dataset(output_dir, x_list, y_list, sample_names=None, hint_list=[], classifier=None)[source]¶
Write samples as a CSV next to
output_dir.The file
<output_dir>.csvgets one row per sample with the feature columns (task_config.x_selectionor all but the last attribute) followed by the target column(s). Nothing is written for an emptyx_list.- Parameters:
output_dir (
str) – Directory that is created; the CSV is namedoutput_dir + ".csv".x_list (
listoftorch.Tensor) – Feature vectors.y_list (
list) – Scalar targets.sample_names – Accepted for API compatibility; unused for tabular data.
hint_list – Accepted for API compatibility; unused for tabular data.
classifier – Accepted for API compatibility; unused for tabular data.