Reputation: 319
Given this data:
Siblings Children Gender Survival
1 Y Y F Y
2 N Y M N
3 Y Y M Y
4 N N F N
5 Y N F N
6 N Y F N
7 Y Y M N
8 Y Y M Y
9 Y N F Y
10 Y Y F N
11 Y N M N
When I use the function:
fit <- rpart(Survival ~ Gender + Children + Siblings,
data = data1, method = "class")
plot(fit)
There is an error message that says:
fit is not a tree, just a root.
How can I fit and plot a decision tree?
Upvotes: 1
Views: 585
Reputation: 63
When I entered your code, it also displayed the same message. I checked what it looks like inside:
> fit
n= 11
node), split, n, loss, yval, (yprob)
* denotes terminal node
1) root 11 4 N (0.6363636 0.3636364) *
It seems that this data is simply not enough for R to create something meaningful.
The fancyRpartPlot
function from the rattle
package works better with smaller data sets: (Taken from this answer: Decision trees in smaller datasets):
library(rattle)
fit <- rpart(Survival ~ Gender + Children + Siblings,
data = data, method = "class",
control = rpart.control(minbucket=2))
fancyRpartPlot(fit, sub=NULL)
And the result is as follows:
Upvotes: 1