[R] Problem getting R's decision tree for Quinlan's golf example data

Alan Lapedes asl at santafe.edu
Sun Apr 16 23:14:36 CEST 2006


Newbie question, but I've checked archives etc. Am trying to reproduce
in R Quinlan's trivial example of the "golf" decision tree. The data file
of 14 examples follows (read in via read.table()):

Outlook Temperature Humidity Windy PlayDontPlay
1 sunny 85 85 false DontPlay
2 sunny 80 90 true DontPlay
3 overcast 83 78 false Play
4 rain 70 96 false Play
5 rain 68 80 false Play
6 rain 65 70 true DontPlay
7 overcast 64 65 true Play
8 sunny 72 95 false DontPlay
9 sunny 69 70 false Play
10 rain 75 80 false Play
11 sunny 75 70 true Play
12 overcast 72 90 true Play
13 overcast 81 75 false Play
14 rain 71 80 true DontPlay

R reports no format or other trivial problems: 
> summary(golf)
     Outlook   Temperature      Humidity      Windy     PlayDontPlay
 overcast:4   Min.   :64.0   Min.   :65.0   false:8   DontPlay:5    
 rain    :5   1st Qu.:69.2   1st Qu.:71.2   true :6   Play    :9    
 sunny   :5   Median :72.0   Median :80.0                           
              Mean   :73.6   Mean   :80.3                           
              3rd Qu.:78.8   3rd Qu.:88.8                           
              Max.   :85.0   Max.   :96.0             

I then try to build a decision tree:
> golf.rpart <- rpart(PlayDontPlay ~ Outlook + Temperature + Humidity + Windy, method="class", data=golf)

which doesn't yield a tree: 
> golf.rpart
n= 14 

node), split, n, loss, yval, (yprob)
      * denotes terminal node

1) root 14 5 Play (0.35714 0.64286) *

> plot(golf.rpart)
Error in plot.rpart(golf.rpart) : fit is not a tree, just a root

Thanks,
Alan




More information about the R-help mailing list