Main Content

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. SupposeXnewis 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,predictruns through the decisions inMdland 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 theionospheredata.

loadionosphereCMdl = fitctree(X,Y); Ynew = predict(CMdl,mean(X))
Ynew =1x1 cell array{'g'}

Find the predicted英里/加仑of a point at the mean of thecarsmalldata.

loadcarsmallX = [Horsepower Weight]; RMdl = fitrtree(X,MPG); Ynew = predict(RMdl,mean(X))
Ynew = 28.7931

See Also

|||||

Related Topics