我很困惑.我以前用过火车没问题.但现在我反复得到"未使用的参数"错误.
#Generate random data
y <- rnorm(100, mean=.5)
x <- rnorm(100)
data <- cbind(x, y)
form <- y ~ x
fitControl <- trainControl(## 10-fold CV
method = "cv",
number = 8)
set.seed(825)
lmFit1 <- train(x, y, method = "lm", trControl = fitControl, na.action=na.omit)
lmFit1 <- train(form, data = data, method = "lm", trControl = fitControl, na.action=na.omit)
Run Code Online (Sandbox Code Playgroud)
由于我正在运行线性回归,我已经使用x和y以及表单指定了此模型.两者都会产生相同的错误.
Error in train(form, method = "lm", trControl = fitControl, na.action = na.omit) : unused arguments (method = "lm", trControl = fitControl, na.action = na.omit)
Error in train(x, y, method = "lm", trControl = fitControl, na.action = na.omit) : unused arguments (y, method = "lm", trControl = fitControl, na.action = na.omit)
Run Code Online (Sandbox Code Playgroud)
在我的实际数据中,我有更多的预测变量,并且一次只包含1或2个预测变量,但都会产生相同的误差.即使是随机数据也会产生错误.
有什么想法吗?非常感谢帮助!谢谢!
您可能更新了插入符包。如果您查看包中的更改日志,您可以看到以下内容:
6.0-34版本的变化
对于要训练的输入数据 x,我们现在尊重输入值的类别以适应其他数据类型(例如稀疏矩阵)。但也有一些复杂的情况;对于预处理,如果数据不是简单的矩阵或数据框,我们会发出警告,因为有一些其他类不存在的基础设施(例如complete.cases)。如果 returnData <- TRUE 并且无法将其转换为数据框,我们还会发出警告。这允许使用稀疏矩阵和文本语料库作为该函数的输入。
进一步在帮助中:
x 一个对象,其中样本位于行中,特征位于列中。这可以是简单矩阵、数据框或其他类型(例如稀疏矩阵)。请参阅下面的详细信息。
以及细节:
x 中的预测变量可以是几乎任何对象,只要底层模型拟合函数可以处理对象类。该函数设计用于处理简单的矩阵和数据帧输入,因此某些功能可能不起作用(例如预处理)。当使用字符串内核时,字符串向量应转换为单列矩阵。
我对第二个火车模型没有问题,对于第一个模型,只需添加 data.frame(x) 而不是 x。
library(caret)
#Generate random data
y <- rnorm(100, mean=.5)
x <- rnorm(100)
data <- cbind(x, y)
form <- y ~ x
fitControl <- trainControl(## 10-fold CV
method = "cv",
number = 8)
set.seed(825)
# changed x to data.frame(x)
lmFit1 <- train(data.frame(x), y, method = "lm", trControl = fitControl, na.action=na.omit)
set.seed(825)
lmFit2 <- train(form, data = data, method = "lm", trControl = fitControl, na.action=na.omit)
Run Code Online (Sandbox Code Playgroud)
我的会话信息()
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=Dutch_Netherlands.1252 LC_CTYPE=Dutch_Netherlands.1252 LC_MONETARY=Dutch_Netherlands.1252 LC_NUMERIC=C
[5] LC_TIME=Dutch_Netherlands.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] caret_6.0-52 ggplot2_1.0.1 lattice_0.20-33
loaded via a namespace (and not attached):
[1] Rcpp_0.12.0 magrittr_1.5 splines_3.2.2 MASS_7.3-43 munsell_0.4.2 colorspace_1.2-6 foreach_1.4.2
[8] minqa_1.2.4 car_2.1-0 stringr_1.0.0 plyr_1.8.3 tools_3.2.2 parallel_3.2.2 pbkrtest_0.4-2
[15] nnet_7.3-10 grid_3.2.2 gtable_0.1.2 nlme_3.1-121 mgcv_1.8-7 quantreg_5.19 MatrixModels_0.4-1
[22] iterators_1.0.7 gtools_3.5.0 lme4_1.1-9 digest_0.6.8 Matrix_1.2-2 nloptr_1.0.4 reshape2_1.4.1
[29] codetools_0.2-14 stringi_0.5-5 compiler_3.2.2 BradleyTerry2_1.0-6 scales_0.3.0 stats4_3.2.2 SparseM_1.7
[36] brglm_0.5-9 proto_0.3-10
Run Code Online (Sandbox Code Playgroud)