attribench.result.DeletionResult
- class attribench.result.DeletionResult(method_names, maskers, activation_fns, mode, num_samples, num_steps)[source]
Bases:
MetricResultRepresents results from running the Deletion metric.
- Parameters:
- method_namesList[str]
Names of attribution methods tested by Deletion.
- maskersList[str]
Names of maskers used by Deletion.
- activation_fnsList[str]
Names of activation functions used by Deletion.
- modestr
Indicates if Deletion-MoRF or Deletion-LeRF was used. Options: “morf”, “lerf”
- num_samplesint
Number of samples on which Deletion was run.
- num_stepsint
Number of steps used by Deletion.
Methods
Adds a BatchResult to the result object.
Retrieves a dataframe from the result for a given masker and activation function.
Load a result from an HDF5 file or a directory of CSV files.
Save the result to an HDF5 file or a nested directory of CSV files.
- add(batch_result)
Adds a BatchResult to the result object.
- Parameters:
- batch_resultBatchResult
BatchResult to add to the result object.
- get_df(masker, activation_fn, agg_fn='auc', methods=None, columns=None)[source]
Retrieves a dataframe from the result for a given masker and activation function. The dataframe contains a row for each sample and a column for each method. Each value is the AUC/AOC for the given method on the given sample.
- Parameters:
- maskerstr
The masker to use.
- activation_fnstr
The activation function to use.
- agg_fnstr
Either “auc” for AUC or “aoc” for AOC.
- methodsOptional[List[str]]
The methods to include. If None, includes all methods.
- columnsOptional[npt.NDArray]
The columns used in the AUC/AOC calculation. If None, uses all columns.
- Returns:
- Tuple[pd.DataFrame, bool]
dataframe containing results, and boolean indicating if higher is better.
- Return type:
Tuple[DataFrame,bool]
- classmethod load(path)
Load a result from an HDF5 file or a directory of CSV files. The format is inferred from the path: if the path is a directory, the result is loaded from a directory of CSV files, otherwise the result is loaded from an HDF5 file.
The specific subclass of MetricResult is inferred from the metadata stored in the file or directory, and the appropriate load method is called.
- Parameters:
- pathstr
Path to the file or directory.
- Returns:
- MetricResult
The loaded result.
- Return type:
- save(path, format='hdf5')[source]
Save the result to an HDF5 file or a nested directory of CSV files.
- Parameters:
- pathstr
Path to the file.
- formatstr
Format to save the result in. Options: hdf5, dir. If hdf5, the full result is stored in a single HDF5 file. If csv, the result is stored in a nested directory of CSV files.