为什么结果1与结果2不同?直觉我认为truc $结果$ RMSE是预测的均方根误差,但我想不是。
library(caret)
x <- data.frame(x = rnorm(15))
y <- x$x + rnorm(15)
myTimeControl <- trainControl(method = "timeslice",initialWindow = 10, horizon = 1, fixedWindow = FALSE, savePredictions=TRUE)
truc <- train(x,y,method = "lm",metric= "RMSE",trControl =myTimeControl,preProc = c("center", "scale"))
result1 <- sqrt(mean((truc$pred$pred-truc$pred$obs)^2))
result2 <- truc$results$RMSE
result1
result2
答案 0 :(得分:1)
如果你颠倒均值和sqrt,你会得到相同的结果......有些东西对于插入符号的公式很奇怪......实际上,你做了一个有趣的观察......
result1 <- mean(sqrt((truc$pred$pred-truc$pred$obs)^2))