When you build a tree using R, you will be (in most cases) fitting a statistical model of the data. Most tree models will have some heuristic to prune the branches to have a a sufficient number of leaves (observations) on each branch.
For example, using rpart() the default number of observations (minsplit) in every branch is 20. To change this default, you must specify a different argument to control.
Here is some example code to build a tree from your data. First read the data:
library(rpart)
dat <- read.table(text ="
Outlook Temp Humidity Windy Play
1 Sunny Hot High FALSE No
2 Sunny Hot High TRUE No
3 Overcast Hot High FALSE Yes
4 Rainy Mild High FALSE Yes
5 Rainy Cool Normal FALSE Yes
6 Rainy Cool Normal TRUE No
7 Overcast Cool Normal TRUE Yes
8 Sunny Mild High FALSE No
9 Sunny Cool Normal FALSE Yes
10 Rainy Mild Normal FALSE Yes
11 Sunny Mild Normal TRUE Yes
12 Overcast Mild High TRUE Yes
13 Overcast Hot Normal FALSE Yes
14 Rainy Mild High TRUE No",
stringsAsFactors = FALSE)
Now fit the model:
model <- rpart(
Play ~ Outlook + Temp + Humidity + Windy,
data = dat,
control = rpart.control(minsplit = 2))
par(xpd = NA, mar = rep(0.7, 4))
plot(model, compress = TRUE)
text(model, cex = 0.7, use.n = TRUE, fancy = FALSE, all = TRUE)
