Documentation Center 
L = loss(tree,X,Y)
[L,se] =
loss(tree,X,Y)
[L,se,NLeaf]
= loss(tree,X,Y)
[L,se,NLeaf,bestlevel]
= loss(tree,X,Y)
L = loss(tree,X,Y,Name,Value)
L = loss(tree,X,Y) returns the mean squared error between the predictions of tree to the data in X, compared to the true responses Y.
[L,se] = loss(tree,X,Y) returns the standard error of the loss.
[L,se,NLeaf] = loss(tree,X,Y) returns the number of leaves (terminal nodes) in the tree.
[L,se,NLeaf,bestlevel] = loss(tree,X,Y) returns the optimal pruning level for tree.
L = loss(tree,X,Y,Name,Value) computes the error in prediction with additional options specified by one or more Name,Value pair arguments.
tree 
Regression tree created with fitrtree, or the compact method. 
X 
A matrix of predictor values. Each column of X represents one variable, and each row represents one observation. 
Y 
A numeric column vector with the same number of rows as X. Each entry in Y is the response to the data in the corresponding row of X. 
Specify optional commaseparated 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 for loss, or the string 'mse' representing meansquared error. If you pass a function handle fun, loss calls fun as: fun(Y,Yfit,W)
All the vectors have the same number of rows as Y. Default: 'mse' 
'subtrees' 
A vector with integer values from 0 (full unpruned tree) to the maximal pruning level max(tree.PruneList). You can set subtrees to 'all', meaning the entire pruning sequence. Default: 0 
'treesize' 
A string, either:

'weights' 
Numeric vector of observation weights with the same number of elements as Y. Default: ones(size(Y)) 
The mean squared error m of the predictions f(X_{n}) with weight vector w is
Find the loss of a regression tree predictor of the carsmall data to find MPG as a function of engine displacement, horsepower, and vehicle weight:
load carsmall X = [Displacement Horsepower Weight]; tree = fitrtree(X,MPG); L = loss(tree,X,MPG) L = 4.8952
Find the pruning level that gives the optimal level of loss for the carsmall data:
load carsmall X = [Displacement Horsepower Weight]; tree = fitrtree(X,MPG); [L,se,NLeaf,bestlevel] = loss(tree,X,MPG,'Subtrees','all'); bestlevel bestlevel = 4