deephyper.ensemble.BaggingEnsembleClassifier#
- class deephyper.ensemble.BaggingEnsembleClassifier(model_dir, loss=<function mse>, size=5, verbose=True, ray_address='', num_cpus=1, num_gpus=None, selection='topk')[source]#
Bases:
BaggingEnsemble
Ensemble for classification 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 totopk
.
Methods
Compute metrics based on the provided data.
Fit the current algorithm to the provided data.
Load an ensemble from a save.
Load the members composing an ensemble.
Execute an inference of the ensemble for the provided data.
Save an ensemble.
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:
- 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