2
votes

I am using R-studio (Version 0.98.994.) in a machine running OS X 10.10.2 (Yosemite) to apply a „random forest“ from the Caret Package. Here is my code:

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

And Here is the Error:

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

1 Answers

2
votes

You are missing the randomForest library. It is one of the suggested libraries in caret and where the rf method comes from. After you install it it should work fine like this:

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

Output:

> 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.