JSONStorageHandler#

class JSONStorageHandler(path)[source]#

Storage handler for JSON files, with ending .json.

Loads and saves results in JSON format, as follows.

Each result is stored as a JSON record with the following keys:

  • model_id: The ID of the model.

  • validation_id: The ID of the validation run.

  • folds: A dictionary of fold results,

    where each key is a fold ID and the value is a dictionary of scores and dataframes.

The folds dictionary has the following structure, where ground_truth, predictions, and train_data are returned only if they were requested during benchmarking.

Keys are strings representing fold IDs.

```json {

“0”: {
“scores”: {

“accuracy”: 0.9, “f1_score”: 0.8

}, “ground_truth”: {

“column1”: [1, 0, 1], “column2”: [0.5, 0.3, 0.8]

}, “predictions”: {

“column1”: [1, 0, 0], “column2”: [0.6, 0.4, 0.7]

}, “train_data”: {

“column1”: [0, 1, 1], “column2”: [0.2, 0.9, 0.4]

}

}, “1”: {

}

}

Parameters:
pathstr or pathlib.Path

Path to the JSON results file. Must refer to a file with a .json extension, not a directory.

Methods

deserialize_result(row)

Deserialize a ResultObject from the JSON storage format.

is_applicable(path)

Return whether this handler supports the given results file path.

load()

Load benchmark results from the file at self.path.

save(results)

Save benchmark results to the JSON file at self.path.

serialize_result(result)

Serialize a ResultObject to the JSON storage format.

static serialize_result(result: ResultObject) dict[source]#

Serialize a ResultObject to the JSON storage format.

static deserialize_result(row: dict) ResultObject[source]#

Deserialize a ResultObject from the JSON storage format.

save(results: list[ResultObject])[source]#

Save benchmark results to the JSON file at self.path.

Parameters:
resultslist of ResultObject

Benchmark results to persist as a JSON array.

static is_applicable(path)[source]#

Return whether this handler supports the given results file path.

Parameters:
pathpathlib.Path or None

Path to the results file, or None for NullStorageHandler. Must refer to a file, not a directory, when not None.

Returns:
bool

True if this handler should be used for path.

load() list[ResultObject][source]#

Load benchmark results from the file at self.path.

Returns:
list of ResultObject

Loaded results. Returns an empty list if the file does not exist.