Caret 包中的 "random forest" 错误
Error in "random forest" from the Caret Package
我在机器 运行 OS X 10.10.2 (Yosemite) 中使用 R-studio(版本 0.98.994.)应用“随机森林”插入符包。这是我的代码:
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
您缺少 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.
我在机器 运行 OS X 10.10.2 (Yosemite) 中使用 R-studio(版本 0.98.994.)应用“随机森林”插入符包。这是我的代码:
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
您缺少 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.