R의 caret로 배우는 Machine Learning
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로 배우는 Machine Learning