I split my data into one set for training and another set for testing. I wonder if I can calculate the value of r ^ 2 for the set of test samples. I created two models: one model with the SVR and another with LinearModel (matlab function). Now I wanted to compare the RMSE (which I already have) and the coefficient of determination value (r ^ 2) based on the test data.
In the background, what I want to know is if this is correct (for Random Forest but the idea is 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 I get RMSE = 9.29 (which is quite good for the problem in question) and a r ^ 2 = -0.03. Is not this contradictory?
If this procedure is correct, what is the interpretation of these results?