How can I determine the r-squared value for regression trees?

46 views (last 30 days)
I am using regression trees and I know that there is a way to determine an R^2 value for the tree, but I am not sure how to do it. I am using the function RegressionTree.fit with Matlab 2013a, but just downloaded 2014a on another computer. So I could use either version.

Accepted Answer

the cyclist
the cyclist on 9 Jun 2014
Edited: the cyclist on 9 Jun 2014
I don't think this is an output property of the model, but it is easy to calculate. Here is an example based on the one in the documentation for RegressionTree.fit:
load carsmall
tree = RegressionTree.fit([Weight, Cylinders],MPG,'MinParent',20,'PredictorNames',{'W','C'})
mpg_predicted = predict(tree,[Weight,Cylinders]);
RMSE = sqrt(nanmean((mpg_predicted-MPG).^2))
RMSE0 = nanstd(MPG-nanmean(MPG));
r_sq = 1 - (RMSE/RMSE0)
I would double-check all that, but you should be in the right direction.
  2 Comments
Janet Reimer
Janet Reimer on 9 Jun 2014
I do not have a value that I would use as the MPG in this example. I have a 15,000 x 3 matrix of predictors and a vector for the response. so tree = RegressionTree.fit(X,y). How do I deal with the extra variable in the example?
the cyclist
the cyclist on 9 Jun 2014
You might want to look at the example I mentioned. In that case, MPG is the response variable. So, I think in your case you are going to do
y_predicted = predict(tree,X);
RMSE = sqrt(nanmean((y_predicted-y).^2))
RMSE0 = nanstd(y-nanmean(y));
r_sq = 1 - (RMSE/RMSE0)

Sign in to comment.

More Answers (0)

Categories

Find more on Time Series in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!