【问题标题】:Error in "random forest" from the Caret PackageCaret 包中的“随机森林”错误
【发布时间】:2015-05-10 14:58:44
【问题描述】:

我在运行 OS X 10.10.2 (Yosemite) 的机器上使用 R-studio(版本 0.98.994。)从 Caret 包中应用“随机森林”。这是我的代码:

library(caret)
data(iris)
inTrain <- createDataPartition(y=iris$Species, p=0.7, list=FALSE)
training <- iris[inTrain,]
testing <- iris[-inTrain,]

# Use o Random Forest do CARET
modFit <- train(Species ~ ., data=training, method="rf", prox=TRUE)
modFit

这是错误:

Error in checkInstall(models$library) : 
Calls: <Anonymous> ... train.formula -> train -> train.default -> checkInstall

【问题讨论】:

    标签: r random-forest r-caret


    【解决方案1】:

    您缺少randomForest 库。它是caret 中建议的库之一,也是rf 方法的来源。安装后它应该可以像这样正常工作:

    library(randomForest)
    library(caret)
    
    data(iris)
    inTrain <- createDataPartition(y=iris$Species, p=0.7, list=FALSE)
    training <- iris[inTrain,]
    testing <- iris[-inTrain,]
    
    # Use o Random Forest do CARET
    modFit <- train(Species ~ ., data=training, method="rf", prox=TRUE)
    modFit
    

    输出:

    > modFit
    Random Forest 
    
    105 samples
      4 predictor
      3 classes: 'setosa', 'versicolor', 'virginica' 
    
    No pre-processing
    Resampling: Bootstrapped (25 reps) 
    
    Summary of sample sizes: 105, 105, 105, 105, 105, 105, ... 
    
    Resampling results across tuning parameters:
    
      mtry  Accuracy  Kappa  Accuracy SD  Kappa SD
      2     0.949     0.923  0.0290       0.0436  
      3     0.953     0.929  0.0305       0.0460  
      4     0.948     0.921  0.0297       0.0447  
    
    Accuracy was used to select the optimal model using  the largest value.
    The final value used for the model was mtry = 3. 
    

    【讨论】:

    • 嗨,Lyzander,感谢您提供的信息。我点击了绿色箭头。酷!
    • :) 谢谢!快乐的提问和回答!
    猜你喜欢
    • 1970-01-01
    • 2018-03-11
    • 2013-09-05
    • 2017-08-13
    • 2016-12-02
    • 2018-03-30
    • 2015-02-26
    • 2016-10-26
    • 2013-12-03
    相关资源
    最近更新 更多