Prediction Using Classification and Regression Trees
This example shows how to predict class labels or responses using trained classification and regression trees.
After creating a tree, you can easily predict responses for new data. SupposeXnew
is new data that has the same number of columns as the original dataX
. To predict the classification or regression based on the tree (Mdl
) and the new data, enter
Ynew = predict(Mdl,Xnew)
For each row of data inXnew
,predict
runs through the decisions inMdl
and gives the resulting prediction in the corresponding element ofYnew
. For more information on classification tree prediction, see thepredict
. For regression, seepredict
.
For example, find the predicted classification of a point at the mean of theionosphere
data.
loadionosphereCMdl = fitctree(X,Y); Ynew = predict(CMdl,mean(X))
Ynew =1x1 cell array{'g'}
Find the predicted英里/加仑
of a point at the mean of thecarsmall
data.
loadcarsmallX = [Horsepower Weight]; RMdl = fitrtree(X,MPG); Ynew = predict(RMdl,mean(X))
Ynew = 28.7931
See Also
fitctree
|fitrtree
|ClassificationTree
|RegressionTree
|predict (CompactRegressionTree)
|predict (CompactClassificationTree)