Main Content

resubPredict

Class:ClassificationTree

Predict resubstitution labels of classification tree

Syntax

label = resubPredict(tree)
[label,posterior] = resubPredict(tree)
[label,posterior,node] = resubPredict(tree)
[label,posterior,node,cnum] = resubPredict(tree)
[label,...] = resubPredict(tree,Name,Value)

Description

label= resubPredict(tree)returns the labelstreepredicts for the datatree.X.labelis the predictions oftreeon the data thatfitctreeused to createtree.

[label,posterior] = resubPredict(tree)returns the posterior class probabilities for the predictions.

[label,posterior,node] = resubPredict(tree)returns the node numbers oftreefor the resubstituted data.

[label,posterior,node,cnum] = resubPredict(tree)returns the predicted class numbers for the predictions.

[label,...] = resubPredict(tree,Name,Value)returns resubstitution predictions with additional options specified by one or moreName,Valuepair arguments.

Input Arguments

expand all

tree

A classification tree constructed byfitctree.

Name-Value Arguments

Specify optional comma-separated pairs ofName,Valuearguments.Nameis the argument name andValueis the corresponding value.Namemust appear inside quotes. You can specify several name and value pair arguments in any order asName1,Value1,...,NameN,ValueN.

Pruning level, specified as the comma-separated pair consisting of'Subtrees'and a vector of nonnegative integers in ascending order or'all'.

If you specify a vector, then all elements must be at least0and at mostmax(tree.PruneList).0indicates the full, unpruned tree andmax(tree.PruneList)indicates the completely pruned tree (i.e., just the root node).

If you specify'all', thenresubPredictoperates on all subtrees (i.e., the entire pruning sequence). This specification is equivalent to using0:max(tree.PruneList).

resubPredictprunestreeto each level indicated inSubtrees, and then estimates the corresponding output arguments. The size ofSubtreesdetermines the size of some output arguments.

To invokeSubtrees, the propertiesPruneListandPruneAlphaoftreemust be nonempty. In other words, growtreeby setting'Prune','on', or by pruningtreeusingprune.

Example:'Subtrees','all'

Data Types:single|double|char|string

Output Arguments

label

The responsetreepredicts for the training data.labelis the same data type as the training response datatree.Y.

If theSubtreesname-value argument containsm>1entries,labelhasmcolumns, each of which represents the predictions of the corresponding subtree. Otherwise,labelis a vector.

posterior

Matrix or array of posterior probabilities for classestreepredicts.

If theSubtreesname-value argument is a scalar or is missing,posterioris ann-by-kmatrix, wheren的行数在吗the training datatree.X, andkis the number of classes.

IfSubtreescontainsm>1entries,posterioris ann-by-k-by-marray, where the matrix for eachmgives posterior probabilities for the corresponding subtree.

node

The node numbers oftreewhere each data row resolves.

If theSubtreesname-value argument is a scalar or is missing,nodeis a numeric column vector withnrows, the same number of rows astree.X.

IfSubtreescontainsm>1entries,nodeis an-by-mmatrix. Each column represents the node predictions of the corresponding subtree.

cnum

The class numbers thattreepredicts for the resubstituted data.

If theSubtreesname-value argument is a scalar or is missing,cnumis a numeric column vector withnrows, the same number of rows astree.X.

IfSubtreescontainsm>1entries,cnumis an-by-mmatrix. Each column represents the class predictions of the corresponding subtree.

Examples

expand all

Find the total number of misclassifications of the Fisher iris data for a classification tree.

loadfisheriristree = fitctree(meas,species); Ypredict = resubPredict(tree);% The predictionsYsame = strcmp(Ypredict,species);% True when ==sum(~Ysame)% How many are different?
ans = 3

Load Fisher's iris data set. Partition the data into training (50%)

loadfisheriris

Grow a classification tree using the all petal measurements.

Mdl = fitctree(meas(:,3:4),species); n = size(meas,1);% Sample sizeK = numel(Mdl.ClassNames);% Number of classes

View the classification tree.

view(Mdl,“模式”,'graph');

Figure Classification tree viewer contains an axes object and other objects of type uimenu, uicontrol. The axes object contains 18 objects of type line, text.

The classification tree has four pruning levels. Level 0 is the full, unpruned tree (as displayed). Level 4 is just the root node (i.e., no splits).

Estimate the posterior probabilities for each class using the subtrees pruned to levels 1 and 3.

[~,Posterior] = resubPredict(Mdl,'SubTrees',[1 3]);

Posterioris ann-by-K-by- 2 array of posterior probabilities. Rows ofPosteriorcorrespond to observations, columns correspond to the classes with orderMdl.ClassNames, and pages correspond to pruning level.

Display the class posterior probabilities for iris 125 using each subtree.

Posterior(125,:,:)
ans = ans(:,:,1) = 0 0.0217 0.9783 ans(:,:,2) = 0 0.5000 0.5000

The decision stump (page 2 ofPosterior) has trouble predicting whether iris 125 is versicolor or virginica.

More About

expand all

Extended Capabilities