Pass PCA preprocessing arguments to train()

℡╲_俬逩灬. 提交于 2019-12-09 08:58:59

问题


I'm trying to build a predictive model in caret using PCA as pre-processing. The pre-processing would be as follows:

preProc <- preProcess(IL_train[,-1], method="pca", thresh = 0.8)

Is it possible to pass the thresh argument directly to caret's train() function? I've tried the following, but it doesn't work:

modelFit_pp <- train(IL_train$diagnosis ~ . , preProcess="pca",
                            thresh= 0.8, method="glm", data=IL_train)

If not, how can I pass the separate preProc results to the train() function?


回答1:


As per the documentation, you specify additional preprocessing arguments with trainControl

?trainControl

...
preProcOptions  

A list of options to pass to preProcess. The type of pre-processing 
(e.g. center, scaling etc) is passed in via the preProc option in train.
...

Since your dataset is not reproducible, let's look at an example. I will use the Sonar dataset from mlbench and use the pls algorithm just for fun.

library(caret)
library(mlbench)

data(Sonar)

ctrl <- trainControl(preProcOptions = list(thresh = 0.95))

mod <- train(Class ~ ., 
             data = Sonar, 
              method = "pls",
              trControl = ctrl)

Although documentation isn't the most exciting read, definitely make sure to try to go through it. Package authors work hard to create documentation and there are many wonders to be found within.



来源:https://stackoverflow.com/questions/29622242/pass-pca-preprocessing-arguments-to-train

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!