Esta página aún no se ha traducido para esta versión. Puede ver la versión más reciente de esta página en inglés.


Paquete: classreg.learning.classif
Superclases: ClassificationEnsemble

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.


Create a bagged classification ensemble object using fitcensemble.



Categorical predictor indices, specified as a vector of positive integers. CategoricalPredictors contains index values corresponding to the columns of the predictor data that contain categorical predictors. If none of the predictors are categorical, then this property is empty ([]).


List of the elements in Y with duplicates removed. ClassNames can be a numeric vector, categorical vector, logical vector, character array, or cell array of character vectors. ClassNames has the same data type as the data in the argument Y. (The software treats string arrays as cell arrays of character vectors.)


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


Expanded predictor names, stored as a cell array of character vectors.

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.


Character vector describing the meaning of the FitInfo array.


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


Description of the cross-validation optimization of hyperparameters, stored as a BayesianOptimization object or a table of hyperparameters and associated values. Nonempty when the OptimizeHyperparameters name-value pair is nonempty at creation. Value depends on the setting of the HyperparameterOptimizationOptions name-value pair at creation:

  • 'bayesopt' (default) — Object of class BayesianOptimization

  • 'gridsearch' or 'randomsearch' — Table of hyperparameters used, observed objective function values (cross-validation loss), and rank of observations from lowest (best) to highest (worst)


Character vector 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.


Character vector describing the reason fitcensemble stopped adding weak learners to the ensemble.


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


Character vector with the name of the response variable Y.


Function handle for transforming scores, or character vector 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 character vectors, 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
oobPermutedPredictorImportancePredictor importance estimates by permutation of out-of-bag predictor observations for random forest of classification trees
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
edgeClassification edge
lossClassification error
marginClassification margins
predictPredict labels using ensemble of classification models
predictorImportanceEstimates of predictor importance
removeLearnersRemove members of compact classification ensemble

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects (MATLAB).


contraer todo

Load the ionosphere data set.

load ionosphere

Train a bagged ensemble of 100 classification trees using all measurements.

rng(1) % For reproducibility
Mdl = fitcensemble(X,Y,'Method','bag')
Mdl = 
             ResponseName: 'Y'
    CategoricalPredictors: []
               ClassNames: {'b'  'g'}
           ScoreTransform: 'none'
          NumObservations: 351
               NumTrained: 100
                   Method: 'Bag'
             LearnerNames: {'Tree'}
     ReasonForTermination: 'Terminated normally after completing the requested number of training cycles.'
                  FitInfo: []
       FitInfoDescription: 'None'
                FResample: 1
                  Replace: 1
         UseObsForLearner: [351x100 logical]

  Properties, Methods

Mdl is a ClassificationBaggedEnsemble model object.

Mdl.Trained is the property that stores a 100-by-1 cell vector of the trained classification trees (CompactClassificationTree model objects) that compose the ensemble.

Plot a graph of the first trained classification tree.


By default, fitcensemble grows deep decision trees for bagged ensembles.

Estimate the in-sample misclassification rate.

L = resubLoss(Mdl)
L = 0

L is 0, which indicates that Mdl is perfect at classifying the training data.


For a bagged ensemble of classification trees, the Trained property of ens stores a cell vector of ens.NumTrained CompactClassificationTree model objects. For a textual or graphical display of tree t in the cell vector, enter


Capacidades ampliadas

Introducido en R2011a