在 R 中使用 caret 的机器学习
Zach Mayer
Data Scientist at DataRobot and co-author of caret
# 生成含缺失的数据
mtcars[mtcars$disp < 140, "hp"] <- NA
Y <- mtcars$mpg
X <- mtcars[, 2:4]
# 使用中位数填补
model <- train(X, Y, method = "glm", preProcess = "medianImpute")
print(min(model$results$RMSE))
3.612713
# 使用 KNN 填补
set.seed(42)
model <- train(
X, Y, method = "glm", preProcess = "knnImpute"
)
print(min(model$results$RMSE))
3.558881
与中位数填补的 3.61 对比
在 R 中使用 caret 的机器学习