是否有任何解决方法可以从Rstudio中获得插入符号包的train()函数?

时间:2014-01-01 20:01:05

标签: r compiler-construction rstudio r-caret

我正在阅读Max Kuhn和Kjell Johnson撰写的非常好的书“应用预测建模”的例子,遗憾的是我使用train()函数和其中一个{{1 GermanCredit包提供的数据集,用于支持向量机的交叉验证:

caret

它抛出了这个错误:

library(AppliedPredictiveModeling)
library(caret)
# preparing the data
data(GermanCredit)
GermanCredit <- GermanCredit[, -nearZeroVar(GermanCredit)]
GermanCredit$CheckingAccountStatus.lt.0 <- NULL
GermanCredit$SavingsAccountBonds.lt.100 <- NULL
GermanCredit$EmploymentDuration.lt.1 <- NULL
GermanCredit$EmploymentDuration.Unemployed <- NULL
GermanCredit$Personal.Male.Married.Widowed <- NULL
GermanCredit$Property.Unknown <- NULL
GermanCredit$Housing.ForFree <- NULL
set.seed(100)
inTrain <- createDataPartition(GermanCredit$Class, p = .8)[[1]]
GermanCreditTrain <- GermanCredit[ inTrain, ]
GermanCreditTest  <- GermanCredit[-inTrain, ]

# Grid selection for `sigma` and `cost` tuning parameters:    
library(kernlab)
set.seed(231)
sigDist <- sigest(Class ~ ., data = GermanCreditTrain, frac = 1)
svmTuneGrid <- data.frame(.sigma = sigDist[1], .C = 2^(-2:7))

# SVM classification and cross-validation
svmFit <- train(Class ~ .,
                data = GermanCreditTrain,
                method = "svmRadial",
                preProc = c("center", "scale"),
                tuneGrid = svmTuneGrid,
                trControl = trainControl(method = "repeatedcv", repeats = 5, 
                                         classProbs =  TRUE))  

有时会出现以下错误消息:

Error in comp(expr, env = envir, options = list(suppressUndefined = TRUE)) : 
  could not find function "makeCenv"

然后我了解到Loading required package: class Warning: namespace ‘compiler’ is not available and has been replaced by .GlobalEnv when processing object ‘GermanCredit’ Error in comp(expr, env = envir, options = list(suppressUndefined = TRUE)) : could not find function "makeCenv" In addition: Warning message: executing %dopar% sequentially: no parallel backend registered makeCenv()包中被建议作为并行计算或并行处理的替代方案,但是我不会选择这个包,因为它在Windows平台上不可用, 我猜。还有其他选择

更新 这些错误只出现在代码在doMC下运行时,默认的R控制台上的情况很好,所以问题是Rstudio的本地问题,我猜。在R控制台(大约8分钟)的时间有点长,不过,我想知道如何根据下面提到的硬件规格加快速度。

我的sessioninfo()输出在这里(Rstudio):

Rstudio IDE

默认R控制台的sessionInfo()输出:

R version 3.0.2 (2013-09-25)
Platform: i386-w64-mingw32/i386 (32-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] datasets  grid      splines   utils     stats     graphics  grDevices methods  
[9] base     

other attached packages:
 [1] proxy_0.4-10                    e1071_1.6-1                    
 [3] class_7.3-9                     kernlab_0.9-19                 
 [5] caret_5.17-7                    foreach_1.4.1                  
 [7] AppliedPredictiveModeling_1.1-4 CORElearn_0.9.42               
 [9] rpart_4.1-3                     xtable_1.7-1                   
[11] knitr_1.5                       texreg_1.30                    
[13] pastecs_1.3-15                  boot_1.3-9                     
[15] gridExtra_0.9.1                 reshape2_1.2.2                 
[17] plyr_1.8                        scales_0.2.3                   
[19] ggplot2_0.9.3.1                 vcdExtra_0.5-11                
[21] gnm_1.0-6                       vcd_1.3-1                      
[23] corrplot_0.73                   RColorBrewer_1.0-5             
[25] car_2.0-19                      Hmisc_3.13-0                   
[27] Formula_1.1-1                   cluster_1.14.4                 
[29] xlsx_0.5.5                      xlsxjars_0.5.0                 
[31] rJava_0.9-5                     lmPerm_1.1-2                   
[33] coin_1.0-23                     survival_2.37-4                
[35] GPArotation_2012.3-1            psych_1.3.12                   
[37] sos_1.3-8                       brew_1.0-6                     
[39] data.table_1.8.10               mice_2.18                      
[41] nnet_7.3-7                      MASS_7.3-29                    
[43] lattice_0.20-23                

loaded via a namespace (and not attached):
 [1] codetools_0.2-8   colorspace_1.2-4  dichromat_2.0-0   digest_0.6.4     
 [5] evaluate_0.5.1    formatR_0.10      gtable_0.1.2      iterators_1.0.6  
 [9] labeling_0.2      Matrix_1.1-0      modeltools_0.2-21 munsell_0.4.2    
[13] mvtnorm_0.9-9996  proto_0.3-10      qvcalc_0.8-8      relimp_1.0-3     
[17] stats4_3.0.2      stringr_0.6.2     tcltk_3.0.2       tools_3.0.2      

问题:

  1. 必须与R version 3.0.2 (2013-09-25) Platform: i386-w64-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] datasets grDevices grid splines graphics utils stats [8] methods base other attached packages: [1] e1071_1.6-1 class_7.3-9 kernlab_0.9-19 caret_5.17-7 [5] foreach_1.4.1 cluster_1.14.4 lattice_0.20-23 reshape2_1.2.2 [9] plyr_1.8 scales_0.2.3 ggplot2_0.9.3.1 lmPerm_1.1-2 [13] coin_1.0-23 survival_2.37-4 sos_1.3-8 brew_1.0-6 loaded via a namespace (and not attached): [1] codetools_0.2-8 colorspace_1.2-4 compiler_3.0.2 dichromat_2.0-0 [5] digest_0.6.3 gtable_0.1.2 iterators_1.0.6 labeling_0.2 [9] MASS_7.3-29 modeltools_0.2-21 munsell_0.4.2 mvtnorm_0.9-9996 [13] proto_0.3-10 RColorBrewer_1.0-5 stats4_3.0.2 stringr_0.6.2 [17] tools_3.0.2 进行交互,因为它在默认的R控制台中运行良好,基于默认R控制台和Rstudio的两个sessionInfo()输出,差异为Rstudio包。奇怪的是,这个pkg在CRAN中找不到,我在这里找到了一个注释: http://www.inside-r.org/r-doc/compiler/compile 当我在Rstudio中这样做时,说load(编译器)就足够了:这个错误消息是不可能的:

    错误:包“编译器”是在R 3.0.0之前构建的:请重新安装

  2. 更新
    它终于从复制和放大后的Rstudio开始工作了。将编译器包库从默认的R lib路径粘贴到Rstudio lib路径,但是时间太长(大约8分钟),我会发布一个单独的并行处理问题给出下面的硬件和windows,如果这会有帮助更快找到答案。

    1. 我的笔记本电脑是2.1GHz双核处理器,3GB,windows 32bit,任何想法如何用compiler功能进行并行处理?你能不能为此发出R代码,我将非常感激。

2 个答案:

答案 0 :(得分:1)

插入符号代码库完全独立于doMC或任何其他“do”包。我没有在这里测试的Windows系统,但我99%肯定这不是一个可重现的问题。该软件包每晚在几个地方(例如R-Forge)和3-4个不同的操作系统(包括Windows)进行测试。我从来没有见过这个问题,即使我已经在专门使用Windows的大量受众上教授课程。

我的猜测是你不小心在某个地方调用了doMC函数(即使它没有列在你的sessionInfo中)。

如果其他人可以尝试重现此错误,将会很有帮助。

谢谢,

最高

答案 1 :(得分:1)

升级R

    sudo su
    echo "deb http://www.stats.bris.ac.uk/R/bin/linux/ubuntu precise/" >> /etc/apt/sources.list
    apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
    apt-get update
    apt-get upgrade