Iris Prediction on the Web
devdataprod-016
Random Forest Training
library(shiny)
library(randomForest)
library(caret)
data(iris)
inTrain <- createDataPartition(iris$Species, list = F)
train <- iris[inTrain, ]
test <- iris[-inTrain, ]
fit <- randomForest(Species ~ ., data = iris)
print(fit)
##
## Call:
## randomForest(formula = Species ~ ., data = iris)
## Type of random forest: classification
## Number of trees: 500
## No. of variables tried at each split: 2
##
## OOB estimate of error rate: 4.67%
## Confusion matrix:
## setosa versicolor virginica class.error
## setosa 50 0 0 0.00
## versicolor 0 47 3 0.06
## virginica 0 4 46 0.08
Random Forest Prediction
predictions <- predict(fit, test)
head(predictions, 10)
## 1 2 4 5 6 7 10 11 12 13
## setosa setosa setosa setosa setosa setosa setosa setosa setosa setosa
## Levels: setosa versicolor virginica