attribench.result.MaxSensitivityResult

class attribench.result.MaxSensitivityResult(method_names, num_samples)[source]

Bases: GroupedMetricResult

Represents results from running the Max-Sensitivity metric.

Parameters:
method_namesList[str]

Names of attribution methods tested by Max-Sensitivity.

num_samplesint

Number of samples on which Max-Sensitivity was run.

Methods

add

Add a batch to the result (abstract method).

get_df

Retrieves a dataframe from the result.

load

Load a result from an HDF5 file or a directory of CSV files.

save

Save the result to an HDF5 file or a nested directory of CSV files.

abstract add(batch_result)

Add a batch to the result (abstract method).

get_df(methods=None)[source]

Retrieves a dataframe from the result. The dataframe contains a row for each method and a column for each sample. Each value is the Max-Sensitivity for the given method on the given sample.

Parameters:
methodsOptional[List[str]], optional

the methods to include. If None, includes all methods. Defaults to None.

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:

MetricResult

save(path, format)

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.

Return type:

None