Download presentation
Presentation is loading. Please wait.
Published byJeremy Thompson Modified over 8 years ago
1
Decision Tree Lab
2
Load in iris data: http://archive.ics.uci.edu/ml/datasets/Iris http://archive.ics.uci.edu/ml/datasets/Iris Display iris data as a sanity check: iris Load package rpart. Install if necessary
3
We will use fit() to build tree First: understand arguments to fit() – fit(formula, data=, method, control=) – formula: outcome ~ predictor1 + predictor2+… – data: specifies the dataframe – method: “class” for classification tree – control: optional parameters for controlling tree growth
4
In the case of the iris dataset – formula: Species ~ Petal.Length + Petal.Width + Sepal.Length + Sepal.Width – data = iris – method=“class”
5
In the case of the iris dataset – control=rpart.control(minsplit=2, cp=0.001) i.e. at least 2 observation in a node must improve overall fit by a factor of 0.001 (cost complexity)
6
Altogether: fit = rpart(Species ~ Petal.Length + Petal.Width + Sepal.Length + Sepal.Width, method = "class", data=iris, control =rpart.control(minsplit=2, cp=0.001)) Examine decision tree: print(fit)
7
Plot decision tree: plot(fit, uniform=TRUE, main="Classification Tree for Iris Dataset") Label the tree: text(fit, use.n=TRUE, all=TRUE, cex=.7)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.