Machine Learning con caret in R
Zach Mayer
Data Scientist at DataRobot and co-author of caret
?preProcess per dettagli# Genera dati con valori mancanti
data(mtcars)
set.seed(42)
mtcars[sample(1:nrow(mtcars), 10), "hp"] <- NA
Y <- mtcars$mpg
X <- mtcars[,2:4] # <- Missing at random
# Usa la "ricetta" per modelli lineari
set.seed(42)
model <- train(
X, Y, method = "glm",
preProcess = c("center", "scale", "medianImpute")
)
print(min(model$results$RMSE))
3.612713
# PCA prima del modello
set.seed(42)
model <- train(
X, Y, method = "glm",
preProcess = c("center", "scale", "medianImpute", "pca")
)
min(model$results$RMSE)
3.402557
# Trasformazione spatial sign
set.seed(42)
model <- train(
X, Y, method = "glm",
preProcess = c("center", "scale", "medianImpute", "spatialSign")
)
min(model$results$RMSE)
4.284904
Machine Learning con caret in R