How to calculate r Squared (r 2) with the test examples?

Asked

Viewed 889 times

1

I broke my dice into one set for training and another for testing. I would like to know if I can calculate the value of r 2 for the set of test examples. I created two models: one model with SVR and the other with Linearmodel (function of Matlab). Now I would like to compare the RMSE (which I already have) and the value of the coefficient of determination (r 2) based on the test data.

Basically what I want to know is whether this is correct (for Random Forest but the idea also applied to other models):

model = TreeBagger(100, Xtrain, Ytrain,'Method','regression');
pred = model.predict(Xtest);

Ymean = mean(Ytest);
SSt = sum((Ytest-Ymean).^2);
SSr = sum((Ytest-pred).^2);

r2 = 1-(SSr/SSt);

The strange part is that with this RMSE = 9.29 (which is quite good for the problem in question) and an r 2 = -0.03. This is not contradictory?

If this procedure is correct, what is the interpretation of these results?

  • Please avoid long discussions in the comments; this conversation was moved to the chat

  • I cannot write in the chat since I don’t have 20 reputation points. This result is not the best ...

  • 1

    Good, ready, you already have 20 points now :)

  • @bfavaretto thanks, had not been able to transfer

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.