deephyper.ensemble.EnsemblePredictor#
- class deephyper.ensemble.EnsemblePredictor(predictors: Sequence[Predictor | PredictorLoader], aggregator: Aggregator, weights: Sequence[float] = None, evaluator: str | Dict = None)[source]#
Bases:
PredictorA predictor that is itself an ensemble of multiple predictors.
- Parameters:
predictors (Sequence[Predictor | PredictorLoader]) – the list of predictors to put in the ensemble. The sequence can be composed of
Predictor(i.e., the model is already loaded in memory) orPredictorLoaderto perform the loading remotely and in parallel. In the later case, the.load()function is called for each inference.aggregator (Aggregator) – the aggregation function to fuse the predictions of the predictors into one prediction.
weights (Sequence[float], optional) – the weights of the predictors in the aggregation. Defaults to
None.evaluator (str | Dict, optional) – The parallel strategy to compute predictions from the list of predictions. If it is a
strit must be a possiblemethodofEvaluator.create(..., method=...). If it is adictit must have two keysmethodandmethod_kwargssuch asEvaluator.create(...). Defaults toNonewhich is equivalent toevaluator="serial"for serial evaluations.
- Raises:
ValueError – when the type of the
evaluatorargument is notstrordict.
Methods
Initialize an evaluator for the ensemble.
Compute the prediction of the ensemble.
Compute the predictions of a list of predictors.
- init_evaluator()[source]#
Initialize an evaluator for the ensemble.
- Returns:
An evaluator instance.
- Return type:
- predict(X: ndarray)[source]#
Compute the prediction of the ensemble.
- Parameters:
X (np.ndarray) – the input query for the prediction.
- Returns:
the target prediction.
- Return type:
np.ndarray
- predictions_from_predictors(X: ndarray, predictors: Sequence[Predictor | PredictorLoader])[source]#
Compute the predictions of a list of predictors.
- Parameters:
X (np.ndarray) – the input query for the predictions.
predictors (Sequence[Predictor]) – the list of predictors to compute the predictions.
- Returns:
the sequence of predictions in the same order that the list of predictors.
- Return type:
List[np.ndarray]