Documentation Center |
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
You can construct a cross-validated tree model with crossval, and call kfoldLoss instead of cvLoss. The alternative can save time if you are going to examine the cross-validated tree more than once.
However, unlike cvLoss, kfoldLoss does not return SE, Nleaf, or BestLevel.