ClassificationBaggedEnsemble class

Classification ensemble grown by resampling


ClassificationBaggedEnsemble combines a set of trained weak learner models and data on which these learners were trained. It can predict ensemble response for new data by aggregating predictions from its weak learners.


ens = fitensemble(tbl,ResponseVarName,'bag',nlearn,learners,'type','classification') creates a bagged classification ensemble. For syntax details, see the fitensemble reference page.

ens = fitensemble(tbl,formula,'bag',nlearn,learners,'type','classification') creates a bagged classification ensemble. For syntax details, see the fitensemble reference page.

ens = fitensemble(tbl,Y,'bag',nlearn,learners,'type','classification') creates a bagged classification ensemble. For syntax details, see the fitensemble reference page.

ens = fitensemble(X,Y,'bag',nlearn,learners,'type','classification') creates a bagged classification ensemble. For syntax details, see the fitensemble reference page.



List of categorical predictors. CategoricalPredictors is a numeric vector with indices from 1 to p, where p is the number of columns of X.


String describing how ens combines weak learner weights, either 'WeightedSum' or 'WeightedAverage'.


Expanded predictor names, stored as a cell array of strings.

If the model uses encoding for categorical variables, then ExpandedPredictorNames includes the names that describe the expanded variables. Otherwise, ExpandedPredictorNames is the same as PredictorNames.


Numeric array of fit information. The FitInfoDescription property describes the content of this array.


String describing the meaning of the FitInfo array.


Numeric scalar between 0 and 1. FResample is the fraction of training data fitensemble resampled at random for every weak learner when constructing the ensemble.


String describing the method that creates ens.


Parameters used in training ens.


Number of trained weak learners in ens, a scalar.


Cell array of names for the predictor variables, in the order in which they appear in X.


String describing the reason fitensemble stopped adding weak learners to the ensemble.


Logical value indicating if the ensemble was trained with replacement (true) or without replacement (false).


String with the name of the response variable Y.


Function handle for transforming scores, or string representing a built-in transformation function. 'none' means no transformation; equivalently, 'none' means @(x)x. For a list of built-in transformation functions and the syntax of custom transformation functions, see fitctree.

Add or change a ScoreTransform function using dot notation:

ens.ScoreTransform = 'function'


ens.ScoreTransform = @function


Trained learners, a cell array of compact classification models.


Numeric vector of trained weights for the weak learners in ens. TrainedWeights has T elements, where T is the number of weak learners in learners.


Logical matrix of size N-by-NumTrained, where N is the number of observations in the training data and NumTrained is the number of trained weak learners. UseObsForLearner(I,J) is true if observation I was used for training learner J, and is false otherwise.


Scaled weights, a vector with length n, the number of rows in X. The sum of the elements of W is 1.


Matrix of predictor values that trained the ensemble. Each column of X represents one variable, and each row represents one observation.


A categorical array, cell array of strings, character array, logical vector, or a numeric vector with the same number of rows as X. Each row of Y represents the classification of the corresponding row of X.


oobEdgeOut-of-bag classification edge
oobLossOut-of-bag classification error
oobMarginOut-of-bag classification margins
oobPredictPredict out-of-bag response of ensemble

Inherited Methods

compactCompact classification ensemble
crossvalCross validate ensemble
resubEdgeClassification edge by resubstitution
resubLossClassification error by resubstitution
resubMarginClassification margins by resubstitution
resubPredictPredict ensemble response by resubstitution
resumeResume training ensemble
compareHoldoutCompare accuracies of two classification models using new data
edgeClassification edge
lossClassification error
marginClassification margins
predictPredict classification
predictorImportanceEstimates of predictor importance
removeLearnersRemove members of compact classification ensemble

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects in the MATLAB® documentation.


Construct a bagged ensemble for the ionosphere data, and examine its resubstitution loss:

load ionosphere
rng(0,'twister') % for reproducibility
ens = fitensemble(X,Y,'bag',100,'Tree',...
L = resubLoss(ens)

L =

The ensemble does a perfect job classifying its training data.

Was this topic helpful?