oobPredict
Predict out-of-bag labels and scores of bagged classification ensemble
Description
[
                specifies additional options using one or more name-value arguments. For example,
                you can specify the indices of the weak learners to use for calculating the
                predicted labels.labels,scores]
= oobPredict(ens,Name=Value)
Examples
Find the out-of-bag predictions and scores for the Fisher iris data. Find the scores with notable uncertainty in the resulting classifications.
Load the sample data set.
load fisheririsTrain an ensemble of bagged classification trees.
ens = fitcensemble(meas,species,'Method','Bag');
Find the out-of-bag predictions and scores.
[label,score] = oobPredict(ens);
Find the scores in the range (0.2,0.8). These scores have notable uncertainty in the resulting classifications.
unsure = ((score > .2) & (score < .8));
sum(sum(unsure))  % Number of uncertain predictionsans = 16
Input Arguments
Bagged classification ensemble model, specified as a ClassificationBaggedEnsemble model object trained with fitcensemble.
Name-Value Arguments
Specify optional pairs of arguments as
      Name1=Value1,...,NameN=ValueN, where Name is
      the argument name and Value is the corresponding value.
      Name-value arguments must appear after other arguments, but the order of the
      pairs does not matter.
    
      Before R2021a, use commas to separate each name and value, and enclose 
      Name in quotes.
    
Example: oobPredict(ens,Learners=[1 2 3 5],UseParallel=true)
                specifies to use the first, second, third, and fifth learners in the ensemble, and
                to perform computations in parallel.
Indices of the weak learners in the ensemble to use with
                                                  oobPredict, specified as a
                                                vector of positive integers in the range
                                                  [1:ens.NumTrained]. By default,
                                                the function uses all learners.
Example: Learners=[1 2 4]
Data Types: single | double
Flag to run in parallel, specified as a numeric or logical 1
        (true) or 0 (false). If you specify
        UseParallel=true, the oobPredict function executes
        for-loop iterations by using parfor. The loop runs in parallel when you have Parallel Computing Toolbox™.
Example: UseParallel=true
Data Types: logical
Output Arguments
Predicted class labels, returned as a categorical or character array, logical or numeric vector, or cell array of character vectors.
For each observation in X, the predicted class label
                        corresponds to the minimum expected classification cost among all classes.
                            For an observation with NaN scores, the
    function classifies the observation into the majority class, which makes up the largest
    proportion of the training labels.
- The label is the class with the highest score. In case of a tie, the label is earliest in - ens- .ClassNames.
- labelshas the same data type as the observed class labels (- Y) used to train- ens. (The software treats string arrays as cell arrays of character vectors.)
- The length of - labelsis equal to the number of rows of- ens.X.
Class scores, returned as a numeric matrix with one row per observation
                        and one column per class. For each observation and each class, the score
                        represents the confidence that the observation originates from that class. A
                        higher score indicates a higher confidence. Score values are in the range
                            0 to 1. For more information, see
                            Score (ensemble).
More About
Bagging, which stands for “bootstrap aggregation,”, is a
        type of ensemble learning. To bag a weak learner such as a decision tree on a data set,
            fitcensemble generates many bootstrap
        replicas of the data set and grows decision trees on these replicas. fitcensemble obtains each bootstrap replica by randomly selecting
            N observations out of N with replacement, where
            N is the data set size. To find the predicted response of a trained
        ensemble, predict take an average over predictions from
        individual trees.
Drawing N out of N observations
with replacement omits on average 37% (1/e) of
observations for each decision tree. These are "out-of-bag" observations.
For each observation, oobLoss estimates the out-of-bag
prediction by averaging over predictions from all trees in the ensemble
for which this observation is out of bag. It then compares the computed
prediction against the true response for this observation. It calculates
the out-of-bag error by comparing the out-of-bag predicted responses
against the true responses for all observations used for training.
This out-of-bag average is an unbiased estimator of the true ensemble
error.
For ensembles, a classification score represents the confidence of a classification into a class. The higher the score, the higher the confidence.
Different ensemble algorithms have different definitions for their scores. Furthermore, the range of scores depends on the ensemble type. For example:
- AdaBoostM1scores range from –∞ to ∞.
- Bagscores range from- 0to- 1.
Extended Capabilities
To run in parallel, set the UseParallel name-value argument to
                        true in the call to this function.
For more general information about parallel computing, see Run MATLAB Functions with Automatic Parallel Support (Parallel Computing Toolbox).
Version History
Introduced in R2012b
See Also
oobMargin | oobLoss | oobEdge | predict | ClassificationBaggedEnsemble | fitcensemble
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.
Amerika
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)