Pass PCA preprocessing arguments to train()

后端 未结 1 1595
余生分开走
余生分开走 2021-02-07 07:04

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], met         


        
相关标签:
1条回答
  • 2021-02-07 07:27

    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.

    0 讨论(0)
提交回复
热议问题