Lab 4G
Directions: Follow along with the slides, completing
the questions in blue on your
computer, and answering the questions in red in your
journal.
Space, Click, Right Arrow or swipe left to move to
the next slide.
titanic
data.tree()
function to create a classification tree that predicts whether
a person survived
the Titanic based on their
sex
.
tree
is similar to that of the
lm()
function.tree1
.survived
or not based on
their sex
?tree1
, write and run code placing the model into the
treeplot
function.
treeplot
:
sex
does the model predict will
survive?tree
that
predicts whether a person survived
based on their
sex
, age
, class
, and where they
embarked
.
tree2
.treeplot
for
this model and answer the following questions:
tree2
?tree()
function will fit a tree
model that will make good predictions without needing lots of
branches.cp
, which equals 0.01
by
default.minsplit
,
which equals 20
by default.tree2
, write and run code creating a model named
tree3
but include cp = 0.005
and
minsplit = 10
as arguments.
tree3
different from
tree2
?data
function to load the
titanic_test
data.titanic_test
data survived or not using
tree1
.type = "class"
tells the
predict
function that we are predicting a categorical
variable and not a numerical variable.!=
will be useful
here.sum(____!=____)
will count the number of times
that the left-hand side does not equal the right-hand side.tree1
, tree2
, or
tree3
) had the lowest misclassification rate for the
titanic_test
data?tree2
. This time though, change the
complexity parameter to 0.0001
. Then answer the
following: