필터 지우기
필터 지우기

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

조회 수: 15 (최근 30일)
Janet Reimer
Janet Reimer 2014년 6월 9일
댓글: the cyclist 2014년 6월 9일
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.

채택된 답변

the cyclist
the cyclist 2014년 6월 9일
편집: the cyclist 2014년 6월 9일
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
Janet Reimer
Janet Reimer 2014년 6월 9일
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 2014년 6월 9일
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)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Time Series에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by