deephyper.ensemble.BaggingEnsembleRegressor#

class deephyper.ensemble.BaggingEnsembleRegressor(model_dir, loss=<function mse>, size=5, verbose=True, ray_address='', num_cpus=1, num_gpus=None, selection='topk')[source]#

Bases: BaggingEnsemble

Ensemble for regression based on uniform averaging of the predictions of each members.

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.

  • selection (str, optional) – Selection strategy to build the ensemble. Value in ["topk"]. Default to topk.

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.

evaluate(X, y, metrics=None)#

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.

fit(X, y)#

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#

Load an ensemble from a save.

Parameters:

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

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

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”.

predict(X) ndarray#

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#

Save an ensemble.

Parameters:

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

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

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”.