Database Reference
In-Depth Information
input attributes: Sepal.Length, Petal.Length and Sepal.Width. The training
algorithm's parameters are set to the following values: minsplit=3 and
maxdepth=3 .
After training the tree, we plot it using a simple style (instead of
showing the histogram, it shows the class distribution). Finally, we classify
the instances in the test data and evaluate the predictive performance of
the tree by presenting the confusion matrix.
library (''party'')
# split the data into train and test
trainIndex
<
sample ( nrow (iris), 2 / 3
nrow (iris))
trainData
<
iris [ trainIndex ,]
testData
<
iris[
trainIndex ,]
# train the classification tree
irisClassifcationTree
<
ctree ( Species ˜ Sepal . Length+
Petal . Length + Sepal .Width ,
data =trainData, control =
ctree control (minsplit=3,
maxdepth=3))
#plotasimpletree
plot ( irisClassifcationTree ,type=''simple ' ')
# predict on test data
testPrediction
<
predict ( irisClassifcationTree ,
newdata = testData)
# show the confusion matrix
table (testPrediction , testData $ Species )
10.3.2
Forest
The party package provides an implementation of the random forest and
bagging ensemble algorithms utilizing ctree algorithm as a base inducer.
The following script illustrates the creation and evaluation of a random
forest with 10 trees ( ntree=10 ). The number of randomly preselected
attributes is set by mtry parameter.
Search WWH ::




Custom Search