Documentation |
E = cvloss(tree)
[E,SE] =
cvloss(tree)
[E,SE,Nleaf]
= cvloss(tree)
[E,SE,Nleaf,BestLevel]
= cvloss(tree)
[E,...] = cvloss(tree,Name,Value)
E = cvloss(tree) returns the cross-validated regression error (loss) for tree, a regression tree.
[E,SE] = cvloss(tree) returns the standard error of E.
[E,SE,Nleaf] = cvloss(tree) returns the number of leaves (terminal nodes) in tree.
[E,SE,Nleaf,BestLevel] = cvloss(tree) returns the optimal pruning level for tree.
[E,...] = cvloss(tree,Name,Value) cross validates 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 produced by 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.
'Subtrees' |
Vector of pruning levels, with 0 representing the full, unpruned tree. tree must include a pruning sequence as created either by fitctree with 'prune' set to 'on', or by the prune method. The returned E, SE, and Nleaf are vectors of the same length as Subtrees; BestLevel is a scalar. If you set Subtrees to 'all', cvloss uses the entire pruning sequence. Default: 0 |
'TreeSize' |
One of the following strings:
Default: 'se' |
'kfold' |
Number of cross-validation samples, a positive integer. Default: 10 |
E |
The cross-validation mean squared error (loss). A vector or scalar depending on the setting of the Subtrees name-value pair. |
SE |
The standard error of E. A vector or scalar depending on the setting of the Subtrees name-value pair. |
Nleaf |
Number of leaf nodes in tree. Leaf nodes are terminal nodes, which give responses, not splits. A vector or scalar depending on the setting of the Subtrees name-value pair. |
BestLevel |
By default, a scalar representing the largest pruning level that achieves a value of E within SE of the minimum error. If you set TreeSize to 'min', BestLevel is the smallest value in Subtrees. |
Compute the cross-validation error for the default classification tree for the carsmall data:
load carsmall X = [Displacement Horsepower Weight]; tree = fitrtree(X,MPG); [E,SE,Nleaf,BestLevel] = cvloss(tree) E = 30.7558 SE = 6.0651 Nleaf = 19 BestLevel = 0
Find the best level by using the Subtrees name-value pair:
[~,~,~,BestLevel] = cvloss(tree,'Subtrees','all') BestLevel = 15