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
gender.
tree is similar to that of the
lm() function.tree1.survived or not based on
their gender?tree1, place the model into the treeplot
function.
treeplot:
gender does the model predict will
survive?tree that predicts whether a
person survived based on their gender,
age, class, and where they
embarked.
tree2.treeplot for this model and answer the
following question:
tree?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, create 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.In order to tally up the total number of misclassifications, we need to create a function that compares the actual outcome with the predicted outcome. The not equal to operator (!=) will be useful here.
Fill in the blanks to create a function to calculate the MCR.
Hint: 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.