Load the sample data.
load carsmall
Construct a regression tree using the sample data. The response variable is miles per gallon, MPG.
tree = fitrtree([Weight, Cylinders],MPG,...
'CategoricalPredictors',2,'MinParentSize',20,...
'PredictorNames',{'W','C'})
tree =
RegressionTree
PredictorNames: {'W' 'C'}
ResponseName: 'Y'
CategoricalPredictors: 2
ResponseTransform: 'none'
NumObservations: 94
Properties, Methods
Predict the mileage of 4,000-pound cars with 4, 6, and 8 cylinders.
MPG4Kpred = predict(tree,[4000 4; 4000 6; 4000 8])
MPG4Kpred = 3×1 19.2778 19.2778 14.3889