deephyper.ensemble.BaseEnsemble#

class deephyper.ensemble.BaseEnsemble(model_dir, loss, size=5, verbose=True, ray_address='', num_cpus=1, num_gpus=None, batch_size=32)[source]#

Bases: ABC

Base class for ensembles, every new ensemble algorithms needs to extend this class.

Parameters:
  • model_dir (str) – Path to directory containing saved Keras models in .h5 format.

  • loss (callable) – a callable taking (y_true, y_pred) as input.

  • size (int, optional) – Number of unique models used in the ensemble. Defaults to 5.

  • verbose (bool, optional) – Verbose mode. Defaults to True.

  • ray_address (str, optional) – Address of the Ray cluster. If “auto” it will try to connect to an existing cluster. If “” it will start a local Ray cluster. Defaults to “”.

  • num_cpus (int, optional) – Number of CPUs allocated to load one model and predict. Defaults to 1.

  • num_gpus (int, optional) – Number of GPUs allocated to load one model and predict. Defaults to None.

  • batch_size (int, optional) – Batch size used batchify the inference of loaded models. Defaults to 32.

Methods

evaluate

Compute metrics based on the provided data.

fit

Fit the current algorithm to the provided data.

load

Load an ensemble from a save.

load_members_files

Load the members composing an ensemble.

predict

Execute an inference of the ensemble for the provided data.

save

Save an ensemble.

save_members_files

Save the list of file names of the members of the ensemble in a JSON file.

abstract evaluate(X, y, metrics=None)[source]#

Compute metrics based on the provided data.

Parameters:
  • X (array) – An array of input data.

  • y (array) – An array of true output data.

  • metrics (callable, optional) – A metric. Defaults to None.

abstract fit(X, y)[source]#

Fit the current algorithm to the provided data.

Parameters:
  • X (array) – The input data.

  • y (array) – The output data.

Returns:

The current fitted instance.

Return type:

BaseEnsemble

load(file: str) None[source]#

Load an ensemble from a save.

Parameters:

file (str) – Path to the save of the ensemble.

load_members_files(file: str = 'ensemble.json') None[source]#

Load the members composing an ensemble.

Parameters:

file (str, optional) – Path of JSON file containing the ensemble members. All members needs to be accessible in model_dir. Defaults to “ensemble.json”.

abstract predict(X)[source]#

Execute an inference of the ensemble for the provided data.

Parameters:

X (array) – An array of input data.

Returns:

The prediction.

Return type:

array

save(file: str = None) None[source]#

Save an ensemble.

Parameters:

file (str) – Path to the save of the ensemble.

save_members_files(file: str = 'ensemble.json') None[source]#

Save the list of file names of the members of the ensemble in a JSON file.

Parameters:

file (str, optional) – Path JSON file where the file names are saved. Defaults to “ensemble.json”.