attribench.result.MinimalSubsetResult
- class attribench.result.MinimalSubsetResult(method_names, maskers, mode, num_samples)[source]
Bases:
MetricResultRepresents results from running the MinimalSubset metric.
- Parameters:
- method_namesList[str]
Names of attribution methods tested by MinimalSubset.
- maskersList[str]
Names of maskers used by MinimalSubset.
- modestr
Indicates if Minimal Subset Deletion or Minimal Subset Insertion was used. Options: “deletion”, “insertion”
- num_samplesint
Number of samples on which MinimalSubset was run.
Methods
Adds a BatchResult to the result object.
Retrieves a dataframe from the result for the given masker.
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, methods=None)[source]
Retrieves a dataframe from the result for the given masker. The dataframe contains a row for each method and a column for each sample. Each value is the MinimalSubset for the given method on the given sample.
- Parameters:
- maskerstr
The masker to include.
- methodsOptional[List[str]], optional
The methods to include. If None, includes all methods. Defaults to None.
- 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.