以下是我在Rstudio中运行的代码:
library(caret)
set.seed(1)
demo <-data.frame(x1 = runif(100),x2 <- rnorm(100),y <- rbinom(100,1,0.3))
modelout <- try(train(y~.,data = demo,
method = "AMORE"),silent = FALSE)
输出如下:
Loading required package: AMORE
Attaching package: ‘AMORE’
The following object is masked from ‘package:caret’:
train
Error in order(x$nhid) : argument 1 is not a vector
In addition: There were 50 or more warnings (use warnings() to see the first 50)
警告消息与“AMORE”包中的“train”功能有关。如果我输入
>train
运行上面的代码后,在命令窗口中的,我从AMORE包中得到了这个函数的主体。
function (net, P, T, Pval = NULL, Tval = NULL, error.criterium = "LMS",
report = TRUE, n.shows, show.step, Stao = NA, prob = NULL,
n.threads = 0L)
{...
}
<environment: namespace:AMORE>
我搜索了我的路径,显然AMORE出现在插入符号之前:
>search()
[1] ".GlobalEnv" "package:AMORE" "package:caret" "package:ggplot2" "package:lattice"
[6] "tools:rstudio" "package:stats" "package:graphics" "package:grDevices" "package:utils"
[11] "package:datasets" "package:methods" "Autoloads" "package:base"
以下是我的会话信息:
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] AMORE_0.2-14 caret_6.0-21 ggplot2_0.9.3.1 lattice_0.20-24
loaded via a namespace (and not attached):
[1] car_2.0-19 codetools_0.2-8 colorspace_1.2-4 compiler_3.0.2 dichromat_2.0-0
[6] digest_0.6.4 foreach_1.4.1 grid_3.0.2 gtable_0.1.2 iterators_1.0.6
[11] labeling_0.2 MASS_7.3-29 munsell_0.4.2 nnet_7.3-7 plyr_1.8
[16] proto_0.3-10 RColorBrewer_1.0-5 reshape2_1.2.2 scales_0.2.3 stringr_0.6.2
[21] tools_3.0.2
我应该如何解决这个问题,以便R在“插入符号”中使用“训练”功能而不是“AMORE”中的“训练”功能?感谢您的时间,并提前感谢您的帮助。
JT
答案 0 :(得分:0)
指定命名空间。
caret::train()
library(caret)
set.seed(1)
demo <-data.frame(x1 = runif(100),x2 <- rnorm(100),y <- rbinom(100,1,0.3))
modelout <- try(caret::train(y~.,data = demo,
method = "AMORE"),silent = FALSE)
答案 1 :(得分:0)
我通过创建该函数的副本来解决它。是的,这是命名空间问题。如果我重新定义了一个函数trainc&lt; - caret :: train,并在代码中使用trainc而不是train,问题就解决了。只是好奇为什么不能直接使用插入符号::火车!感谢SethB的帮助。