Documentation |
L = resubLoss(tree)
L = resubLoss(tree,Name,Value)
L = resubLoss(tree,'Subtrees',subtreevector)
[L,se] =
resubLoss(tree,'Subtrees',subtreevector)
[L,se,NLeaf]
= resubLoss(tree,'Subtrees',subtreevector)
[L,se,NLeaf,bestlevel]
= resubLoss(tree,'Subtrees',subtreevector)
[L,...] = resubLoss(tree,'Subtrees',subtreevector,Name,Value)
L = resubLoss(tree) returns the resubstitution loss, meaning the loss computed for the data that fitrtree used to create tree.
L = resubLoss(tree,Name,Value) returns the loss with additional options specified by one or more Name,Value pair arguments. You can specify several name-value pair arguments in any order as Name1,Value1,…,NameN,ValueN.
L = resubLoss(tree,'Subtrees',subtreevector) returns a vector of mean squared errors for the trees in the pruning sequence subtreevector.
[L,se] = resubLoss(tree,'Subtrees',subtreevector) returns the vector of standard errors of the classification errors.
[L,se,NLeaf] = resubLoss(tree,'Subtrees',subtreevector) returns the vector of numbers of leaf nodes in the trees of the pruning sequence.
[L,se,NLeaf,bestlevel] = resubLoss(tree,'Subtrees',subtreevector) returns the best pruning level as defined in the TreeSize name-value pair. By default, bestlevel is the pruning level that gives loss within one standard deviation of minimal loss.
[L,...] = resubLoss(tree,'Subtrees',subtreevector,Name,Value) returns loss statistics with additional options specified by one or more Name,Value pair arguments. You can specify several name-value pair arguments in any order as Name1,Value1,…,NameN,ValueN.
tree |
A regression tree constructed using fitrtree. |
Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.
'LossFun' |
Function handle, or the string 'mse' meaning mean squared error. You can write your own loss function in the syntax described in Loss Functions. Default: 'mse' |
Name,Value arguments associated with pruning subtrees:
The built-in loss function is 'mse', meaning mean squared error.
To write your own loss function, create a function file of the form
function loss = lossfun(Y,Yfit,W)
N is the number of rows of tree.X.
Y is an N-element vector representing the observed response.
Yfit is an N-element vector representing the predicted responses.
W is an N-element vector representing the observation weights.
The output loss should be a scalar.
Pass the function handle @lossfun as the value of the LossFun name-value pair.
Find the mean square error of a model of the carsmall data:
load carsmall X = [Displacement Horsepower Weight]; tree = fitrtree(X,MPG); resubLoss(tree) ans = 4.8952
fitrtree | loss | resubPredict