Skip to content
Prev 386805 / 398502 Next

How to get Mean Magnitude of Relative Error with caret library

Hi, I am using caret package and using nested resampling method (i.e. 5
fold for outer fold). I am getting the RMSE and MAE values, which are
default to the caret library.
My question is how can we implement the Mean Magnitude of Relative Error
(MRE and MMRE) with caret. My code is the following:

outer_folds <- createFolds(d$price, k = 5)
boot <- trainControl(method = "boot", number=100)

CV1 <- lapply(outer_folds, function(index){
  tr <- d[-index, ]
  ts <- d[index,]

  cart1 <- train(bug ~ ., data = tr,
                  method = "rf",
                 metric = "MAE",
                 preProc = c("center", "scale", "nzv"),
                 trControl = boot)

  postResample(predict(cart1, ts), ts$price)
})
sapply(CV1, function(x) x[3]) -> CV_MAE1
CV_MAE1