iris <- read.csv("https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data",header=F)
iris.setosa <- cbind(iris[1:50,1:4],V5=c(1))
iris.versicolor <- cbind(iris[51:100,1:4],V5=c(2))
iris.virginica <- cbind(iris[101:150,1:4],V5=c(3))
iris.local <- rbind(rbind(iris.setosa,iris.versicolor),iris.virginica)
iris.local$V5 <- as.factor(iris.local$V5)
formula.rf <- as.formula("V5~.")
require(randomForest)
## Loading required package: randomForest
## randomForest 4.6-12
## Type rfNews() to see new features/changes/bug fixes.
model.rf <- randomForest(formula.rf,data=iris.local,importance=TRUE,ntree=100)
print(model.rf)
## 
## Call:
##  randomForest(formula = formula.rf, data = iris.local, importance = TRUE,      ntree = 100) 
##                Type of random forest: classification
##                      Number of trees: 100
## No. of variables tried at each split: 2
## 
##         OOB estimate of  error rate: 4%
## Confusion matrix:
##    1  2  3 class.error
## 1 50  0  0        0.00
## 2  0 47  3        0.06
## 3  0  3 47        0.06
importance(model.rf)
##            1          2          3 MeanDecreaseAccuracy MeanDecreaseGini
## V1  2.375383  2.8085532  3.1608747             3.770516         7.409627
## V2  2.186001  0.3727879  0.9488992             1.565191         2.292421
## V3 10.667270 15.5850526 13.3183022            15.621059        46.487073
## V4  8.768707 14.9279832 13.3572145            14.583653        42.872412
print(model.rf$predicted)
##   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18 
##   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1 
##  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36 
##   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1 
##  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54 
##   1   1   1   1   1   1   1   1   1   1   1   1   1   1   2   2   2   2 
##  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72 
##   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   3   2 
##  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90 
##   2   2   2   2   2   3   2   2   2   2   2   3   2   2   2   2   2   2 
##  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 
##   2   2   2   2   2   2   2   2   2   2   3   3   3   3   3   3   2   3 
## 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 
##   3   3   3   3   3   3   3   3   3   3   3   2   3   3   3   3   3   3 
## 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 
##   3   3   3   3   3   3   3   3   2   3   3   3   3   3   3   3   3   3 
## 145 146 147 148 149 150 
##   3   3   3   3   3   3 
## Levels: 1 2 3