Class: CompactRegressionTree

Predict response of regression tree


Yfit = predict(tree,Xdata)
[Yfit,node] = predict(tree,Xdata)
[Yfit,node] = predict(tree,Xdata,Name,Value)


Yfit = predict(tree,Xdata) returns predicted responses to the data in Xdata, based on the tree regression tree.

[Yfit,node] = predict(tree,Xdata) returns the predicted node numbers of tree in response to Xdata.

[Yfit,node] = predict(tree,Xdata,Name,Value) predicts response with additional options specified by one or more Name,Value pair arguments.

Input Arguments


Regression tree created by fitrtree, or by the compact method.


Numeric array with the same number of columns as the array used for creating tree. Each row of Xdata corresponds to one data point, and each column corresponds to one predictor.

Name-Value Pair Arguments

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.


Numeric vector of pruning levels, with 0 representing the full, unpruned tree. To use the Subtrees name-value pair, tree must include a pruning sequence as created by the fitrtree or prune methods. If Subtrees has T elements, and X has N rows, then Yfit is an N-by-T matrix. The ith column of Yfit contains the fitted values produced by the Subtrees(I) subtree. Similarly, node is an N-by-T matrix. Subtrees must be sorted in ascending order. (To compute fitted values for a tree that is not part of the optimal pruning sequence, first use prune to prune the tree.)

Default: 0

Output Arguments


A numeric column vector with the same number of rows as Xdata. Each row of Yfit gives the predicted response to the corresponding row of Xdata, based on the tree regression model.


Numeric vector of node numbers for the predictions. Each entry corresponds to the predicted leaf node in tree for the corresponding row of Xdata.


Find the predicted mileage for a car with 200 cubic inch engine displacement, 150 horsepower, weighing 3000 lbs, based on the carsmall data:

load carsmall
X = [Displacement Horsepower Weight];
tree = fitrtree(X,MPG);
Mileage = predict(tree,[200 150 3000])

Mileage =

See Also

| |

Was this topic helpful?