将 PCA 预处理参数传递给 train()
Pass PCA preprocessing arguments to train()
我正在尝试使用 PCA 作为预处理在插入符号中构建预测模型。预处理如下:
preProc <- preProcess(IL_train[,-1], method="pca", thresh = 0.8)
是否可以将 thresh
参数直接传递给插入符号的 train()
函数?我尝试了以下方法,但它不起作用:
modelFit_pp <- train(IL_train$diagnosis ~ . , preProcess="pca",
thresh= 0.8, method="glm", data=IL_train)
如果没有,我如何将单独的 preProc
结果传递给 train()
函数?
根据文档,您使用 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.
...
由于您的数据集不可重现,让我们看一个例子。我将使用来自 mlbench
的 Sonar
数据集并使用 pls
算法只是为了好玩。
library(caret)
library(mlbench)
data(Sonar)
ctrl <- trainControl(preProcOptions = list(thresh = 0.95))
mod <- train(Class ~ .,
data = Sonar,
method = "pls",
trControl = ctrl)
虽然文档不是最令人兴奋的读物,但一定要确保尝试通读它。包作者努力创建文档,其中有许多奇迹。
我正在尝试使用 PCA 作为预处理在插入符号中构建预测模型。预处理如下:
preProc <- preProcess(IL_train[,-1], method="pca", thresh = 0.8)
是否可以将 thresh
参数直接传递给插入符号的 train()
函数?我尝试了以下方法,但它不起作用:
modelFit_pp <- train(IL_train$diagnosis ~ . , preProcess="pca",
thresh= 0.8, method="glm", data=IL_train)
如果没有,我如何将单独的 preProc
结果传递给 train()
函数?
根据文档,您使用 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.
...
由于您的数据集不可重现,让我们看一个例子。我将使用来自 mlbench
的 Sonar
数据集并使用 pls
算法只是为了好玩。
library(caret)
library(mlbench)
data(Sonar)
ctrl <- trainControl(preProcOptions = list(thresh = 0.95))
mod <- train(Class ~ .,
data = Sonar,
method = "pls",
trControl = ctrl)
虽然文档不是最令人兴奋的读物,但一定要确保尝试通读它。包作者努力创建文档,其中有许多奇迹。