Template Class BaggingEnsemble¶
Defined in File BaggingEnsemble.h
Inheritance Relationships¶
Base Type¶
public genif::Learner< std::vector< ModelType >, std::vector< PredictionType > >
(Template Class Learner)
Class Documentation¶
-
template<typename
ModelType
, typenamePredictionType
>
classgenif
::
BaggingEnsemble
: public genif::Learner<std::vector<ModelType>, std::vector<PredictionType>>¶ Provides a generic Bagging ensemble, that randomly subsamples given datasets and outputs a vector of learned models and predictions.
- Template Parameters
ModelType
: The type of model, that the learner yields as result from callingfit
.PredictionType
: The type of prediction, that the learner yields as result from calling eitherfitPredict
andpredict
.
Public Functions
-
BaggingEnsemble
(const Learner<ModelType, PredictionType> &baseLearner, unsigned int nModels = 100, unsigned int sampleSize = 256, unsigned int workerCount = 1, int seed = -1)¶ Constructs a new instance of BaggingEnsemble.
- Parameters
baseLearner
: The base learner, which serves as a prototype for subsequent learning efforts.nModels
: The number of models to fit.sampleSize
: The number of observations to draw to fit each model.workerCount
: The number of workers, which should fit models in parallel.seed
: Seed to use for random number generation (-1 defaults to sysclock seed). Pass an integer for constant result across multiple runs.
-
Learner<std::vector<ModelType>, std::vector<PredictionType>> &
fit
(const MatrixX &dataset) override¶ Fit
nModels
using the supplied dataset.For fitting, this method takes a copy of the baseLearner property and calls fit using a previously drawn sample of dataset.
- Return
A reference to the current BaggingEnsemble instance. The fitted models may be retrieved by calling the
getModels()
function.- Parameters
dataset
: The dataset used to fit models.
-
std::vector<PredictionType>
predict
(const MatrixX &dataset) const override¶ Make predictions by using the set of models, which were previously learned with the
fit
method.Internally, this method calls the predict method of the given base learner and calls predict with every learned model and the supplied dataset.
- Return
A vector of predictions.
- Parameters
dataset
: The dataset to use for prediction.
-
std::vector<ModelType>
getModel
() const¶ Gathers the list of learned models, which were previously learned with the fit method.
- Return
A list of models.
-
unsigned int
getNumberOfModels
() const¶ Returns the number of models, which should be fitted in this ensemble.
- Return
As stated above.
-
unsigned int
getActualNumberOfModels
() const¶ Returns the number of models, which have been fitted in this ensemble.
- Return
As stated above.