mardi 5 novembre 2019

Calculating for RMSE (Root Mean Square Error) given train and test

I have a question where I am prompted to find the RMSE

I am given that:

y=2+2*x1+x2+rnorm(150)
and
ytrain=y[1:100]; ytest=y[101:150]
x=data.frame(x1, x2); x.train=x[1:100,]; x.test=x[101:150,]
m1=lm(ytrain~x1+x2, data=x.train)

I have tried:

m2=lm(ytest~x1+x2, data=x.test)

y_hat <- fitted.values(m2)
y_observed <- fitted.values(m1)

RMSE = function(y_observed, y_hat){
sqrt(mean((y_observed - y_hat)^2))
}

I get a value for RMSE when inputting this into R, however I do not think it is correct, as I get values above 1 when using it for different models. Any suggestions?

Aucun commentaire:

Enregistrer un commentaire