# Decision trees in smaller datasets

I have the following dataset from:

 train <- read.csv(url("http://s3.amazonaws.com/assets.datacamp.com/course/Kaggle/train.csv"))


When I want to make a decision tree using this data I do:

 my_tree_two <- rpart(Survived ~ Sex + Age, data=train, method="class")


This works fine. However I have created a (smaller) subset:

library(dplyr)
t <- select(train, Survived, Sex, Age)
t <- t[c(1:100), ]
t <- filter(t, !is.na(Age))


But now when I want to create a decision tree using

my_tree_two <- rpart(Survived ~ Sex + Age, data=t, method="class")


I only see this: n= 78

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

1) root 78 31 0 (0.6025641 0.3974359)
2) Sex=male 45  6 0 (0.8666667 0.1333333) *
3) Sex=female 33  8 1 (0.2424242 0.7575758) *


Could anybody tell me why, with a smaller sample size I only see "Sex" instead of Sex and age

• Based on this and your other tree-related questions today, I'd recommend reading about the basics of decision trees. The freely available An Introduction to Statistical Learning provides a basic overview of decision trees. There are also many other free resources out there. – Tchotchke Aug 17 '15 at 20:16

## 3 Answers

There are default settings that control the splits; you can see these by looking at the documentation for rpart.control.

If you decrease the minbucket size using rpart.control like this:

my_tree_two <- rpart(Survived ~ Sex + Age, data=t, method="class", control=rpart.control(minbucket=2))


Then you'll end up with more splits, including Age.

First, make sure the 100 rows you select for your smaller dataset are random. They have to be random to represent somehow your initial dataset. However, one thing that determines if there will be a split or not is the number of observations (in a given node). As an extreme example of what I mean, if you start with a dataset with 10 predictor variables and 1mil observations and get a tree output, you can't expect to get the same splits if you pick 100 rows and your 10 variables. You'll end up with nodes having < = 5 observations. In that case, if you really want to "force" some more splits, you can make your model a bit more "sensitive" by specifying various parameters. One of them is the example that @Tchotchke mentions above.

I dont see any problem in your case. If you have less information during the learning it is nit surprising at all that a given predictive model gives you a different output. Secondly the new tree learnt on the smaller dataset looks smaller so it is very logic, with less example the purity gains obtained with the "Age" splitnare not big enough to select that split. It would have been surprising if you got bigger tree with wmaller dataset but its not the case so every thing is fine.