0
$\begingroup$

I am training a regression model using caret in R but I am having a hard time understanding how to validate the model. I am using postResample and it is outputting and RMSE and an R squared. I am honestly just confused as to what this function is doing and how it is getting these numbers. Is this an accurate way to validate a regression model or are there better ways? Below is code similar to what I am doing.

fitControl <- trainControl(## 10-fold CV
                           method = "repeatedcv",
                           number = 10,
                           ## repeated ten times
                           repeats = 3)

car_t_index <- createDataPartition(mtcars$mpg, p = .8, list = FALSE, times = 1)
car_train <- mtcars[car_t_index,]
car_test <- mtcars[-car_t_index,]


model <- train(mpg ~ ., data = car_train,method = "rf", trControl = fitControl)

pred <- predict(model,car_test)

model
pred
postResample(pred = pred, obs = car_test$mpg)

```
$\endgroup$

1 Answer 1

1
$\begingroup$

The question is pretty vague, both algorithms operate differently, the results of training for both algorithms for RMSE,Rsquared and MAE.

library(tidyverse)
library(caret)

fitControl <- trainControl(## 10-fold CV
  method = "repeatedcv",
  number = 10,
  ## repeated ten times
  repeats = 3)

car_t_index <- createDataPartition(mtcars$mpg, p = .8, list = FALSE, times = 1)
car_train <- mtcars[car_t_index,]
car_test <- mtcars[-car_t_index,]


model <- train(mpg ~ ., data = car_train,method = "rf", trControl = fitControl)
model2 <- train(mpg ~ ., data = car_train,method = "lm", trControl = fitControl)


resamp <- resamples(list(Random_Forest = model, Linear_model = model2))
summary(resamp)

I hope this helps

$\endgroup$
4
  • $\begingroup$ I think you do not need tidyverse. $\endgroup$
    – usεr11852
    Commented Jul 26, 2019 at 0:37
  • $\begingroup$ You are right, I am used to always loading it $\endgroup$
    – Yazid
    Commented Jul 26, 2019 at 10:26
  • $\begingroup$ So does that resamples function just compare two regression functions? Sorry I am new at this and am having a hard time figuring out the best way to validate these regression models. $\endgroup$ Commented Jul 26, 2019 at 15:56
  • $\begingroup$ Exactly! I suggest researching the topic and specifically on DataCamp, they provide very good beginner friendly courses, good luck! $\endgroup$
    – Yazid
    Commented Jul 26, 2019 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.