title: How do you calculate out-of-sample error in case of numeric response variable?
body: <p>I am trying to predict the "medv" (median owner-owned house prices) from Boston dataset. It is a numeric variable.</p>
  
  <p>I have made a linear model from a training dataset and want to calculate model accuracy by testing on a test dataset. Below is the reproducible code:</p>
  
  <pre><code>library("MASS")
  Boston&lt;-Boston
  
  set.seed(12396911) # set random seed
  index &lt;- sample(1:nrow(Boston), floor(0.8 * nrow(Boston)), replace = FALSE)
  training &lt;- Boston[index,]
  testing&lt;- Boston[-index,]
  
  fin_model&lt;-lm(medv ~ lstat + rm + ptratio + black + dis + nox + zn + chas + rad + tax + crim, data = training)
  prediction&lt;-predict(fin_model,testing)
  
  
  tab&lt;-data.frame(cbind(prediction,testing$medv))
  colnames(tab)&lt;-c("pred","true")
  mse&lt;-sum((tab$pred - tab$true)^2)/(length(tab)-1)
  mse
  </code></pre>
  
  <p>I have an idea on how to calculate accuracy when we are predicting a categorical response (it comparing the true value against predicted and hence it's either yes or no, and the proportion of matches is our accuracy). </p>
  
  <p>I was thinking if <code>correlation</code> makes sense as a measure of accuracy: If 1 it's 100% accurate and if it's 0, predictions are useless. But I am not sure.</p>
  
  <pre><code>cor(tab$pred,tab$true)
  # 0.8522107
  </code></pre>