Borrar filtros
Borrar filtros

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

15 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

the cyclist
the cyclist el 9 de Jun. de 2014
Editada: the cyclist el 9 de Jun. de 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 comentarios
Janet Reimer
Janet Reimer el 9 de Jun. de 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 el 9 de Jun. de 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)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Time Series en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by